You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2018/01/21 12:34:28 UTC
[2/2] commons-compress git commit: reading from the cache doesn't
need to throw an exception
reading from the cache doesn't need to throw an exception
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/d5f61b43
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/d5f61b43
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/d5f61b43
Branch: refs/heads/master
Commit: d5f61b4398e6572d974ee13d01f47f82744fb495
Parents: 271e0a7
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Jan 21 13:33:39 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Jan 21 13:33:39 2018 +0100
----------------------------------------------------------------------
.../commons/compress/utils/BitInputStream.java | 27 +++++++++++---------
1 file changed, 15 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d5f61b43/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 770101d..e0645b3 100644
--- a/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
@@ -89,15 +89,7 @@ public class BitInputStream implements Closeable {
if (bitsCachedSize < count) {
return processBitsGreater57(count);
}
- final long bitsOut;
- if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
- bitsOut = (bitsCached & MASKS[count]);
- bitsCached >>>= count;
- } else {
- bitsOut = (bitsCached >> (bitsCachedSize - count)) & MASKS[count];
- }
- bitsCachedSize -= count;
- return bitsOut;
+ return readCachedBits(count);
}
/**
@@ -124,13 +116,12 @@ public class BitInputStream implements Closeable {
/**
* Drops bits until the next bits will be read from a byte boundary.
- * @throws IOException if reading the remaining bits to the next byte boundary fails
* @since 1.16
*/
- public void alignWithByteBoundary() throws IOException {
+ public void alignWithByteBoundary() {
int toSkip = bitsCachedSize % 8;
if (toSkip > 0) {
- readBits(toSkip);
+ readCachedBits(toSkip);
}
}
@@ -162,6 +153,18 @@ public class BitInputStream implements Closeable {
return bitsOut;
}
+ private long readCachedBits(int count) {
+ final long bitsOut;
+ if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
+ bitsOut = (bitsCached & MASKS[count]);
+ bitsCached >>>= count;
+ } else {
+ bitsOut = (bitsCached >> (bitsCachedSize - count)) & MASKS[count];
+ }
+ bitsCachedSize -= count;
+ return bitsOut;
+ }
+
/**
* Fills the cache up to 56 bits
* @param count