mirror of https://github.com/apache/poi.git
[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
This commit is contained in:
parent
d4373c2d09
commit
bcfd81f489
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue