Repository: commons-compress Updated Branches: refs/heads/master e79465bbe -> 7b5816d96
Move System.in functionality into BitInputStream. Optimize some more bit reading methods. Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/88dad2db Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/88dad2db Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/88dad2db Branch: refs/heads/master Commit: 88dad2dbdc18b724863d64003622f1a0f4315148 Parents: a0f55d9 Author: Thomas Meyer <tho...@m3y3r.de> Authored: Thu Jan 19 21:31:17 2017 +0100 Committer: Stefan Bodewig <bode...@apache.org> Committed: Sat Feb 4 18:56:59 2017 +0100 ---------------------------------------------------------------------- .../bzip2/BZip2CompressorInputStream.java | 25 ++++++++++---------- .../commons/compress/utils/BitInputStream.java | 4 +++- 2 files changed, 15 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/88dad2db/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java index 348334f..cf22e65 100644 --- a/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java @@ -266,6 +266,7 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements } private void initBlock() throws IOException { + BitInputStream bin = this.bin; char magic0; char magic1; char magic2; @@ -275,12 +276,12 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements while (true) { // Get the block magic bytes. - magic0 = bsGetUByte(); - magic1 = bsGetUByte(); - magic2 = bsGetUByte(); - magic3 = bsGetUByte(); - magic4 = bsGetUByte(); - magic5 = bsGetUByte(); + magic0 = bsGetUByte(bin); + magic1 = bsGetUByte(bin); + magic2 = bsGetUByte(bin); + magic3 = bsGetUByte(bin); + magic4 = bsGetUByte(bin); + magic5 = bsGetUByte(bin); // If isn't end of stream magic, break out of the loop. if (magic0 != 0x17 || magic1 != 0x72 || magic2 != 0x45 @@ -306,7 +307,7 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements this.currentState = EOF; throw new IOException("bad block header"); } - this.storedBlockCRC = bsGetInt(); + this.storedBlockCRC = bsGetInt(bin); this.blockRandomised = bsR(bin, 1) == 1; /** @@ -344,7 +345,7 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements } private boolean complete() throws IOException { - this.storedCombinedCRC = bsGetInt(); + this.storedCombinedCRC = bsGetInt(bin); this.currentState = EOF; this.data = null; @@ -362,9 +363,7 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements final BitInputStream inShadow = this.bin; if (inShadow != null) { try { -// if (inShadow != System.in) { -// inShadow.close(); -// } + inShadow.close(); } finally { this.data = null; this.bin = null; @@ -390,11 +389,11 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements return bsR(bin, 1) != 0; } - private char bsGetUByte() throws IOException { + private static char bsGetUByte(BitInputStream bin) throws IOException { return (char) bsR(bin, 8); } - private int bsGetInt() throws IOException { + private static int bsGetInt(BitInputStream bin) throws IOException { return (int) bsR(bin, 32); } http://git-wip-us.apache.org/repos/asf/commons-compress/blob/88dad2db/src/main/java/org/apache/commons/compress/utils/BitInputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/utils/BitInputStream.java b/src/main/java/org/apache/commons/compress/utils/BitInputStream.java index d933b0d..5531a04 100644 --- a/src/main/java/org/apache/commons/compress/utils/BitInputStream.java +++ b/src/main/java/org/apache/commons/compress/utils/BitInputStream.java @@ -56,7 +56,9 @@ public class BitInputStream implements Closeable { @Override public void close() throws IOException { - in.close(); + if (in != System.in) { + in.close(); + } } /**