diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java b/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java index e5b5eba6f1..1b98bb26ab 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java @@ -56,6 +56,7 @@ public class DeferredGeneration { //writeAvoidingTempFiles was added as an experimental change in POI 5.1.0 //wb.writeAvoidingTempFiles(fileOut); } finally { + //the dispose call is necessary to ensure temp files are removed wb.dispose(); } System.out.println("wrote DeferredGeneration.xlsx"); diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/Outlining.java b/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/Outlining.java index 6c29813edd..31b15dcb16 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/Outlining.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/Outlining.java @@ -47,6 +47,7 @@ public class Outlining { try (FileOutputStream fileOut = new FileOutputStream("outlining_collapsed.xlsx")) { wb2.write(fileOut); } finally { + //the dispose call is necessary to ensure temp files are removed wb2.dispose(); } } diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/SavePasswordProtectedXlsx.java b/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/SavePasswordProtectedXlsx.java index df5b7004cf..aabfd5955c 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/SavePasswordProtectedXlsx.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/SavePasswordProtectedXlsx.java @@ -80,6 +80,7 @@ public final class SavePasswordProtectedXlsx { } } finally { wb.close(); + //the dispose call is necessary to ensure temp files are removed wb.dispose(); } TempFileUtils.checkTempFiles(); diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SheetDataWriter.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SheetDataWriter.java index b25c5422b8..c339b12eea 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SheetDataWriter.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SheetDataWriter.java @@ -152,6 +152,9 @@ public class SheetDataWriter implements Closeable { */ public InputStream getWorksheetXMLInputStream() throws IOException { File fd = getTempFile(); + if (fd == null) { + throw new IOException("getWorksheetXMLInputStream only works when a temp file is used"); + } FileInputStream fis = new FileInputStream(fd); try { return decorateInputStream(fis);