diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java index 173e6963bd..1e467244f5 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java @@ -37,6 +37,7 @@ import org.apache.poi.util.Beta; @Beta public class StreamingSheetWriter extends SheetDataWriter { private static final Logger LOG = LogManager.getLogger(StreamingSheetWriter.class); + private boolean closed = false; public StreamingSheetWriter() throws IOException { throw new RuntimeException("StreamingSheetWriter requires OutputStream"); @@ -68,7 +69,9 @@ public class StreamingSheetWriter extends SheetDataWriter { @Override public void close() throws IOException { - _out.flush(); + if (!closed) { + _out.flush(); + } } @Override @@ -78,7 +81,10 @@ public class StreamingSheetWriter extends SheetDataWriter { @Override boolean dispose() throws IOException { - _out.close(); + if (!closed) { + _out.close(); + } + closed = true; return true; } }