Author: fanningpj
Date: Thu Oct 26 17:37:46 2023
New Revision: 1913356
URL: http://svn.apache.org/viewvc?rev=1913356&view=rev
Log:
[bug-67579] revert changes - POI will again close the InputStream
Removed:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/NoCloseInputStream.java
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1913356&r1=1913355&r2=1913356&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/ZipPackage.java
Thu Oct 26 17:37:46 2023
@@ -131,9 +131,6 @@ public final class ZipPackage extends OP
super(access);
try (ZipArchiveThresholdInputStream zis = ZipHelper.openZipStream(in))
{
this.zipArchive = new ZipInputStreamZipEntrySource(zis);
- } catch (final IOException | RuntimeException e) {
- IOUtils.closeQuietly(in);
- throw e;
}
}
Modified:
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java?rev=1913356&r1=1913355&r2=1913356&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
(original)
+++
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
Thu Oct 26 17:37:46 2023
@@ -176,7 +176,7 @@ public final class ZipHelper {
verifyZipHeader(checkedStream);
// Open as a proper zip stream
- return new ZipArchiveThresholdInputStream(new
ZipArchiveInputStream(new NoCloseInputStream(checkedStream)));
+ return new ZipArchiveThresholdInputStream(new
ZipArchiveInputStream(checkedStream));
}
/**
Modified:
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL:
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=1913356&r1=1913355&r2=1913356&view=diff
==============================================================================
---
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
(original)
+++
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
Thu Oct 26 17:37:46 2023
@@ -1449,17 +1449,26 @@ public final class TestXSSFWorkbook exte
}
@Test
- void testWorkbookCloseDoesNotCloseInputStream() throws Exception {
+ void testWorkbookCloseClosesInputStream() throws Exception {
try (WrappedStream stream = new WrappedStream(
HSSFTestDataSamples.openSampleFileStream("github-321.xlsx"))) {
try (XSSFWorkbook wb = new XSSFWorkbook(stream)) {
XSSFSheet xssfSheet = wb.getSheetAt(0);
assertNotNull(xssfSheet);
}
- assertFalse(stream.isClosed(), "stream should noy be closed by
XSSFWorkbook");
+ assertTrue(stream.isClosed(), "stream should be closed by
XSSFWorkbook");
}
}
+ static class NoCloseInputStream extends FilterInputStream {
+ NoCloseInputStream(InputStream stream) {
+ super(stream);
+ }
+
+ @Override
+ public void close() {}
+ }
+
@Test
void readFromZipStream() throws IOException {
File tempFile = TempFile.createTempFile("poitest", ".zip");
@@ -1485,7 +1494,9 @@ public final class TestXSSFWorkbook exte
try (ZipArchiveInputStream zis = new
ZipArchiveInputStream(Files.newInputStream(tempFile.toPath()))) {
ZipArchiveEntry entry;
while ((entry = zis.getNextZipEntry()) != null) {
- XSSFWorkbook wb = new XSSFWorkbook(zis);
+ // 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));
assertNotNull(wb);
count++;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]