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 13:30:40 UTC
[1/3] commons-compress git commit: make SonarQube less unhappy
Repository: commons-compress
Updated Branches:
refs/heads/master d5f61b439 -> c1470f52e
make SonarQube less unhappy
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/0367fb31
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/0367fb31
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/0367fb31
Branch: refs/heads/master
Commit: 0367fb31efae4535e15f01f6c27ea814a0739b81
Parents: d5f61b4
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Jan 21 14:25:38 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Jan 21 14:25:38 2018 +0100
----------------------------------------------------------------------
.../bzip2/BZip2CompressorInputStream.java | 6 +-
.../compressors/deflate64/HuffmanDecoder.java | 100 +++++++++++--------
.../compressors/lz77support/LZ77Compressor.java | 2 +-
.../compressors/zstandard/ZstdUtils.java | 2 +-
4 files changed, 61 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0367fb31/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 64a9007..9c7a80a 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
@@ -642,9 +642,9 @@ public class BZip2CompressorInputStream extends CompressorInputStream implements
nextSym = perm_zt[tmp];
}
- final int yy_0 = yy[0];
- checkBounds(yy_0, 256, "yy");
- final byte ch = seqToUnseq[yy_0];
+ final int yy0 = yy[0];
+ checkBounds(yy0, 256, "yy");
+ final byte ch = seqToUnseq[yy0];
unzftab[ch & 0xff] += s + 1;
while (s-- >= 0) {
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0367fb31/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
index 62d19d9..23a7236 100644
--- a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
+++ b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
@@ -131,51 +131,58 @@ class HuffmanDecoder implements Closeable {
public int decode(byte[] b, int off, int len) throws IOException {
while (!finalBlock || state.hasData()) {
- switch (state.state()) {
- case INITIAL:
+ if (state.state() == HuffmanState.INITIAL) {
finalBlock = readBits(1) == 1;
int mode = (int) readBits(2);
switch (mode) {
case 0:
- reader.alignWithByteBoundary();
- long bLen = readBits(16);
- long bNLen = readBits(16);
- if (((bLen ^ 0xFFFF) & 0xFFFF) != bNLen) {
- //noinspection DuplicateStringLiteralInspection
- throw new IllegalStateException("Illegal LEN / NLEN values");
- }
- state = new UncompressedState(bLen);
+ switchToUncompressedState();
break;
case 1:
state = new HuffmanCodes(FIXED_CODES, FIXED_LITERALS, FIXED_DISTANCE);
break;
case 2:
- int literals = (int) (readBits(5) + 257);
- int[] literalTable = new int[literals];
-
- int distances = (int) (readBits(5) + 1);
- int[] distanceTable = new int[distances];
-
- populateDynamicTables(reader, literalTable, distanceTable);
-
- state = new HuffmanCodes(DYNAMIC_CODES, literalTable, distanceTable);
+ int[][] tables = readDynamicTables();
+ state = new HuffmanCodes(DYNAMIC_CODES, tables[0], tables[1]);
break;
default:
throw new IllegalStateException("Unsupported compression: " + mode);
}
- break;
- default:
+ } else {
return state.read(b, off, len);
}
}
return -1;
}
+ private void switchToUncompressedState() throws IOException {
+ reader.alignWithByteBoundary();
+ long bLen = readBits(16);
+ long bNLen = readBits(16);
+ if (((bLen ^ 0xFFFF) & 0xFFFF) != bNLen) {
+ //noinspection DuplicateStringLiteralInspection
+ throw new IllegalStateException("Illegal LEN / NLEN values");
+ }
+ state = new UncompressedState(bLen);
+ }
+
+ private int[][] readDynamicTables() throws IOException {
+ int[][] result = new int[2][];
+ int literals = (int) (readBits(5) + 257);
+ result[0] = new int[literals];
+
+ int distances = (int) (readBits(5) + 1);
+ result[1] = new int[distances];
+
+ populateDynamicTables(reader, result[0], result[1]);
+ return result;
+ }
+
int available() throws IOException {
return state.available();
}
- private static abstract class DecoderState {
+ private abstract static class DecoderState {
abstract HuffmanState state();
abstract int read(byte[] b, int off, int len) throws IOException;
@@ -202,20 +209,22 @@ class HuffmanDecoder implements Closeable {
int read(byte[] b, int off, int len) throws IOException {
// as len is an int and (blockLength - read) is >= 0 the min must fit into an int as well
int max = (int) Math.min(blockLength - read, len);
- for (int i = 0; i < max; i++) {
+ int readSoFar = 0;
+ while (readSoFar < max) {
+ int readNow;
if (reader.bitsCached() > 0) {
byte next = (byte) readBits(Byte.SIZE);
- b[off + i] = memory.add(next);
- read++;
+ b[off + readSoFar] = memory.add(next);
+ readNow = 1;
} else {
- int readNow = in.read(b, off + i, max - i);
+ readNow = in.read(b, off + readSoFar, max - readSoFar);
if (readNow == -1) {
throw new EOFException("Truncated Deflate64 Stream");
}
- memory.add(b, off + i, readNow);
- read += readNow;
- i += readNow;
+ memory.add(b, off + readSoFar, readNow);
}
+ read += readNow;
+ readSoFar += readNow;
}
return max;
}
@@ -345,7 +354,7 @@ class HuffmanDecoder implements Closeable {
BinaryTreeNode node = tree;
while (node != null && node.literal == -1) {
long bit = readBits(reader, 1);
- node = bit == 0 ? node.left : node.right;
+ node = bit == 0 ? node.leftNode : node.rightNode;
}
return node != null ? node.literal : -1;
}
@@ -360,18 +369,20 @@ class HuffmanDecoder implements Closeable {
BinaryTreeNode codeLengthTree = buildTree(codeLengthValues);
- int[] auxBuffer = new int[literals.length + distances.length];
+ final int[] auxBuffer = new int[literals.length + distances.length];
- int value = -1, length = 0;
- for (int i = 0; i < auxBuffer.length; ) {
+ int value = -1;
+ int length = 0;
+ int off = 0;
+ while (off < auxBuffer.length) {
if (length > 0) {
- auxBuffer[i++] = value;
+ auxBuffer[off++] = value;
length--;
} else {
int symbol = nextSymbol(reader, codeLengthTree);
if (symbol < 16) {
value = symbol;
- auxBuffer[i++] = value;
+ auxBuffer[off++] = value;
} else if (symbol == 16) {
length = (int) (readBits(reader, 2) + 3);
} else if (symbol == 17) {
@@ -391,7 +402,8 @@ class HuffmanDecoder implements Closeable {
private static class BinaryTreeNode {
private final int bits;
int literal = -1;
- BinaryTreeNode left, right;
+ BinaryTreeNode leftNode;
+ BinaryTreeNode rightNode;
private BinaryTreeNode(int bits) {
this.bits = bits;
@@ -399,22 +411,22 @@ class HuffmanDecoder implements Closeable {
void leaf(int symbol) {
literal = symbol;
- left = null;
- right = null;
+ leftNode = null;
+ rightNode = null;
}
BinaryTreeNode left() {
- if (left == null && literal == -1) {
- left = new BinaryTreeNode(bits + 1);
+ if (leftNode == null && literal == -1) {
+ leftNode = new BinaryTreeNode(bits + 1);
}
- return left;
+ return leftNode;
}
BinaryTreeNode right() {
- if (right == null && literal == -1) {
- right = new BinaryTreeNode(bits + 1);
+ if (rightNode == null && literal == -1) {
+ rightNode = new BinaryTreeNode(bits + 1);
}
- return right;
+ return rightNode;
}
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0367fb31/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java
index 5086b60..4e494f3 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/LZ77Compressor.java
@@ -90,7 +90,7 @@ public class LZ77Compressor {
public enum BlockType {
LITERAL, BACK_REFERENCE, EOD
}
- abstract public BlockType getType();
+ public abstract BlockType getType();
}
/**
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0367fb31/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdUtils.java b/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdUtils.java
index cbbe3cd..8b2f8d3 100644
--- a/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdUtils.java
+++ b/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdUtils.java
@@ -74,7 +74,7 @@ public class ZstdUtils {
try {
Class.forName("com.github.luben.zstd.ZstdInputStream");
return true;
- } catch (NoClassDefFoundError | Exception error) {
+ } catch (NoClassDefFoundError | Exception error) { // NOSONAR
return false;
}
}
[3/3] commons-compress git commit: remove magic value
Posted by bo...@apache.org.
remove magic value
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/c1470f52
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/c1470f52
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/c1470f52
Branch: refs/heads/master
Commit: c1470f52ed67a82abcadb0333ea2620f11e475c5
Parents: 0e1e80c
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Jan 21 14:27:56 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Jan 21 14:27:56 2018 +0100
----------------------------------------------------------------------
.../org/apache/commons/compress/utils/BitInputStream.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c1470f52/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 e0645b3..ad1f229 100644
--- a/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/BitInputStream.java
@@ -111,7 +111,7 @@ public class BitInputStream implements Closeable {
* @since 1.16
*/
public long bitsAvailable() throws IOException {
- return bitsCachedSize + 8L * in.available();
+ return bitsCachedSize + ((long) Byte.SIZE) * in.available();
}
/**
@@ -119,7 +119,7 @@ public class BitInputStream implements Closeable {
* @since 1.16
*/
public void alignWithByteBoundary() {
- int toSkip = bitsCachedSize % 8;
+ int toSkip = bitsCachedSize % Byte.SIZE;
if (toSkip > 0) {
readCachedBits(toSkip);
}
@@ -132,7 +132,7 @@ public class BitInputStream implements Closeable {
// bitsCachedSize >= 57 and left-shifting it 8 bits would cause an overflow
int bitsToAddCount = count - bitsCachedSize;
- overflowBits = 8 - bitsToAddCount;
+ overflowBits = Byte.SIZE - bitsToAddCount;
final long nextByte = in.read();
if (nextByte < 0) {
return nextByte;
@@ -180,10 +180,10 @@ public class BitInputStream implements Closeable {
if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
bitsCached |= (nextByte << bitsCachedSize);
} else {
- bitsCached <<= 8;
+ bitsCached <<= Byte.SIZE;
bitsCached |= nextByte;
}
- bitsCachedSize += 8;
+ bitsCachedSize += Byte.SIZE;
}
return false;
}
[2/3] commons-compress git commit: whitespace
Posted by bo...@apache.org.
whitespace
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/0e1e80c2
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/0e1e80c2
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/0e1e80c2
Branch: refs/heads/master
Commit: 0e1e80c2ab0db3e66445b469cc7deeba8dc40864
Parents: 0367fb3
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Jan 21 14:26:21 2018 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Jan 21 14:26:21 2018 +0100
----------------------------------------------------------------------
.../compressors/deflate64/HuffmanDecoder.java | 34 ++++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/0e1e80c2/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
index 23a7236..dca3218 100644
--- a/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
+++ b/src/main/java/org/apache/commons/compress/compressors/deflate64/HuffmanDecoder.java
@@ -132,24 +132,24 @@ class HuffmanDecoder implements Closeable {
public int decode(byte[] b, int off, int len) throws IOException {
while (!finalBlock || state.hasData()) {
if (state.state() == HuffmanState.INITIAL) {
- finalBlock = readBits(1) == 1;
- int mode = (int) readBits(2);
- switch (mode) {
- case 0:
- switchToUncompressedState();
- break;
- case 1:
- state = new HuffmanCodes(FIXED_CODES, FIXED_LITERALS, FIXED_DISTANCE);
- break;
- case 2:
- int[][] tables = readDynamicTables();
- state = new HuffmanCodes(DYNAMIC_CODES, tables[0], tables[1]);
- break;
- default:
- throw new IllegalStateException("Unsupported compression: " + mode);
- }
+ finalBlock = readBits(1) == 1;
+ int mode = (int) readBits(2);
+ switch (mode) {
+ case 0:
+ switchToUncompressedState();
+ break;
+ case 1:
+ state = new HuffmanCodes(FIXED_CODES, FIXED_LITERALS, FIXED_DISTANCE);
+ break;
+ case 2:
+ int[][] tables = readDynamicTables();
+ state = new HuffmanCodes(DYNAMIC_CODES, tables[0], tables[1]);
+ break;
+ default:
+ throw new IllegalStateException("Unsupported compression: " + mode);
+ }
} else {
- return state.read(b, off, len);
+ return state.read(b, off, len);
}
}
return -1;