diff --git a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java index ae2e9ac70..ac2f510b3 100644 --- a/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java +++ b/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java @@ -381,6 +381,16 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { if (closed) { return; } + finish(); + super.close(); + bsStream.close(); + closed = true; + } + + protected void finish() throws IOException { + if (closed) { + return; + } if (runLength > 0) { writeRun(); @@ -388,9 +398,6 @@ public class CBZip2OutputStream extends OutputStream implements BZip2Constants { currentChar = -1; endBlock(); endCompression(); - closed = true; - super.close(); - bsStream.close(); } public void flush() throws IOException {