diff --git a/src/main/java/io/airlift/compress/zstd/ZstdOutputStream.java b/src/main/java/io/airlift/compress/zstd/ZstdOutputStream.java index 90a2236c..7a9a600f 100644 --- a/src/main/java/io/airlift/compress/zstd/ZstdOutputStream.java +++ b/src/main/java/io/airlift/compress/zstd/ZstdOutputStream.java @@ -133,18 +133,22 @@ private void compressIfNecessary() void finishWithoutClosingSource() throws IOException { - writeChunk(true); - closed = true; + if (!closed) { + writeChunk(true); + closed = true; + } } @Override public void close() throws IOException { - writeChunk(true); + if (!closed) { + writeChunk(true); - closed = true; - outputStream.close(); + closed = true; + outputStream.close(); + } } private void writeChunk(boolean lastChunk)