This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 0a2d5642a83f172c12bf53e2bb1a9a40e43fb81b Author: Gary Gregory <[email protected]> AuthorDate: Thu Aug 15 08:58:25 2024 -0400 Refactor stream close checking - Use the same exception message --- .../compressors/bzip2/BZip2CompressorOutputStream.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java index 7efaffd90..059be5786 100644 --- a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java @@ -480,6 +480,12 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream<OutputSt this.bsLive = bsLiveShadow + n; } + private void checkClosed() throws IOException { + if (closed) { + throw new IOException("Stream closed"); + } + } + @Override public void close() throws IOException { if (!closed) { @@ -1168,10 +1174,7 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream<OutputSt if (offs + len > buf.length) { throw new IndexOutOfBoundsException("offs(" + offs + ") + len(" + len + ") > buf.length(" + buf.length + ")."); } - if (closed) { - throw new IOException("Stream closed"); - } - + checkClosed(); for (final int hi = offs + len; offs < hi;) { write0(buf[offs++]); } @@ -1179,9 +1182,7 @@ public class BZip2CompressorOutputStream extends CompressorOutputStream<OutputSt @Override public void write(final int b) throws IOException { - if (closed) { - throw new IOException("Closed"); - } + checkClosed(); write0(b); }
