diff options
author | PJ Fanning <fanningpj@apache.org> | 2023-10-26 15:19:42 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2023-10-26 15:19:42 +0000 |
commit | bcfd81f489670ace3304ee68934f24143c9f517d (patch) | |
tree | ec29aa2eec78eb62be39e9912221aeba00b2fbac /poi | |
parent | d4373c2d098030e885aa33d799056b95aa42d7f1 (diff) | |
download | poi-bcfd81f489670ace3304ee68934f24143c9f517d.tar.gz poi-bcfd81f489670ace3304ee68934f24143c9f517d.zip |
[bug-67579] test that we close input stream
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1913352 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r-- | poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index 94f3c4fa78..9cba23ff82 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -32,6 +32,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -1231,4 +1232,34 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { } } } + + @Test + void testWorkbookCloseClosesInputStream() throws Exception { + try (WrappedStream stream = new WrappedStream( + HSSFTestDataSamples.openSampleFileStream("49423.xls"))) { + try (HSSFWorkbook wb = new HSSFWorkbook(stream)) { + HSSFSheet hssfSheet = wb.getSheetAt(0); + assertNotNull(hssfSheet); + } + assertTrue(stream.isClosed(), "stream should be closed by HSSFWorkbook"); + } + } + + private static class WrappedStream extends FilterInputStream { + private boolean closed; + + WrappedStream(InputStream stream) { + super(stream); + } + + @Override + public void close() throws IOException { + super.close(); + closed = true; + } + + boolean isClosed() { + return closed; + } + } } |