aboutsummaryrefslogtreecommitdiffstats
path: root/poi-ooxml/src/test
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2023-10-26 18:09:38 +0000
committerPJ Fanning <fanningpj@apache.org>2023-10-26 18:09:38 +0000
commite94b284c5945f54991d22f59b3612ecfd17b8427 (patch)
tree32557686577e046f292464b731e325a823c3a8e1 /poi-ooxml/src/test
parentff5fc9d582844c7737582de8e20671e7c16faaf0 (diff)
downloadpoi-e94b284c5945f54991d22f59b3612ecfd17b8427.tar.gz
poi-e94b284c5945f54991d22f59b3612ecfd17b8427.zip
[bug-67579] add new XSSFWorkbook constructor
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1913359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src/test')
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java21
1 files changed, 12 insertions, 9 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
index f5eb9f18aa..7d6d7b668b 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
@@ -1460,13 +1460,17 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
}
}
- static class NoCloseInputStream extends FilterInputStream {
- NoCloseInputStream(InputStream stream) {
- super(stream);
+ @Test
+ void testWorkbookCloseCanBeStoppedFromClosingInputStream() throws Exception {
+ try (WrappedStream stream = new WrappedStream(
+ HSSFTestDataSamples.openSampleFileStream("github-321.xlsx"))) {
+ // uses new constructor, available since POI 5.2.5
+ try (XSSFWorkbook wb = new XSSFWorkbook(stream, false)) {
+ XSSFSheet xssfSheet = wb.getSheetAt(0);
+ assertNotNull(xssfSheet);
+ }
+ assertFalse(stream.isClosed(), "stream should not be closed by XSSFWorkbook");
}
-
- @Override
- public void close() {}
}
@Test
@@ -1494,9 +1498,8 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
try (ZipArchiveInputStream zis = new ZipArchiveInputStream(Files.newInputStream(tempFile.toPath()))) {
ZipArchiveEntry entry;
while ((entry = zis.getNextZipEntry()) != null) {
- // NoCloseInputStream is needed to stop XSSFWorkbook closing the underlying InputStream
- // this might not sound great but POI has worked like this for years and we can't just change it
- XSSFWorkbook wb = new XSSFWorkbook(new NoCloseInputStream(zis));
+ // Since POI 5.2.5, you can stop XSSFWorkbook closing the InputStream by using this new constructor
+ XSSFWorkbook wb = new XSSFWorkbook(zis, false);
assertNotNull(wb);
count++;
}