diff --git a/spring-batch-excel/pom.xml b/spring-batch-excel/pom.xml index 7702d94..e018aa5 100644 --- a/spring-batch-excel/pom.xml +++ b/spring-batch-excel/pom.xml @@ -44,14 +44,14 @@ 1.8 - 4.3.3 + 4.3.4 4.1.2 3.18.1 - 5.7.1 + 5.8.2 2.13.3 - 3.6.0 + 3.11.0 @@ -183,6 +183,14 @@ + + maven-surefire-plugin + 2.22.2 + + + maven-failsafe-plugin + 2.22.2 + diff --git a/spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/Sheet.java b/spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/Sheet.java index 70080a2..7576017 100644 --- a/spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/Sheet.java +++ b/spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/Sheet.java @@ -39,7 +39,8 @@ public interface Sheet extends Iterable, AutoCloseable { String getName(); /** - * Get the row as a {@code String[]}. Returns {@code null} if the row doesn't exist. + * Get the row as a {@code String[]}. Returns {@code null} if the row doesn't exist. Can throw an + * {@code UnsupportedOperationException} when the underlying implementation doesn't support indexed access to rows. * @param rowNumber the row number to read. * @return a {@code String[]} or {@code null} */ diff --git a/spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/streaming/StreamingSheet.java b/spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/streaming/StreamingSheet.java index 0be89f9..a4d87b5 100644 --- a/spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/streaming/StreamingSheet.java +++ b/spring-batch-excel/src/main/java/org/springframework/batch/extensions/excel/streaming/StreamingSheet.java @@ -16,8 +16,6 @@ package org.springframework.batch.extensions.excel.streaming; -import java.io.Closeable; -import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.HashMap; @@ -42,7 +40,13 @@ import org.springframework.batch.extensions.excel.Sheet; import org.springframework.util.StringUtils; import org.springframework.util.xml.StaxUtils; -class StreamingSheet implements Sheet, Iterable, Closeable { +/** + * {@code Sheet} implementation for Apache POI using the streaming event mode to read the rows. + * + * @author Marten Deinum + * @since 0.1.0 + */ +class StreamingSheet implements Sheet { private final Log logger = LogFactory.getLog(StreamingSheet.class); @@ -143,7 +147,7 @@ class StreamingSheet implements Sheet, Iterable, Closeable { } @Override - public void close() throws IOException { + public void close() throws Exception { try { this.reader.close(); } diff --git a/spring-batch-excel/src/test/java/org/springframework/batch/extensions/excel/poi/PoiItemReaderXlsxWithBlankLinesTests.java b/spring-batch-excel/src/test/java/org/springframework/batch/extensions/excel/poi/PoiItemReaderXlsxWithBlankLinesTests.java new file mode 100644 index 0000000..0127537 --- /dev/null +++ b/spring-batch-excel/src/test/java/org/springframework/batch/extensions/excel/poi/PoiItemReaderXlsxWithBlankLinesTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.batch.extensions.excel.poi; + +import org.springframework.batch.extensions.excel.AbstractExcelItemReader; +import org.springframework.batch.extensions.excel.AbstractExcelItemReaderTests; +import org.springframework.core.io.ClassPathResource; + +/** + * @author Marten Deinum + * @since 0.1.0 + */ +public class PoiItemReaderXlsxWithBlankLinesTests extends AbstractExcelItemReaderTests { + + @Override + protected void configureItemReader(AbstractExcelItemReader itemReader) { + itemReader.setResource(new ClassPathResource("player_with_blank_lines.xlsx")); + } + + @Override + protected AbstractExcelItemReader createExcelItemReader() { + return new PoiItemReader<>(); + } + +} diff --git a/spring-batch-excel/src/test/java/org/springframework/batch/extensions/excel/streaming/StreamingXlsxItemReaderWithBlankLinesTest.java b/spring-batch-excel/src/test/java/org/springframework/batch/extensions/excel/streaming/StreamingXlsxItemReaderWithBlankLinesTest.java new file mode 100644 index 0000000..650779e --- /dev/null +++ b/spring-batch-excel/src/test/java/org/springframework/batch/extensions/excel/streaming/StreamingXlsxItemReaderWithBlankLinesTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2006-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.batch.extensions.excel.streaming; + +import org.springframework.batch.extensions.excel.AbstractExcelItemReader; +import org.springframework.batch.extensions.excel.AbstractExcelItemReaderTests; +import org.springframework.core.io.ClassPathResource; + +/** + * @author Marten Deinum + * @since 0.1.0 + */ +class StreamingXlsxItemReaderWithBlankLinesTest extends AbstractExcelItemReaderTests { + + @Override + protected void configureItemReader(AbstractExcelItemReader itemReader) { + itemReader.setResource(new ClassPathResource("player_with_blank_lines.xlsx")); + } + + @Override + protected AbstractExcelItemReader createExcelItemReader() { + return new StreamingXlsxItemReader<>(); + } + +} diff --git a/spring-batch-excel/src/test/resources/player_with_blank_lines.xls b/spring-batch-excel/src/test/resources/player_with_blank_lines.xls index 7c34ece..fa622c5 100644 Binary files a/spring-batch-excel/src/test/resources/player_with_blank_lines.xls and b/spring-batch-excel/src/test/resources/player_with_blank_lines.xls differ diff --git a/spring-batch-excel/src/test/resources/player_with_blank_lines.xlsx b/spring-batch-excel/src/test/resources/player_with_blank_lines.xlsx new file mode 100644 index 0000000..f86ce65 Binary files /dev/null and b/spring-batch-excel/src/test/resources/player_with_blank_lines.xlsx differ