You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/07/31 15:20:56 UTC
(commons-compress) 12/19: Use final
This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit f3f563da1eda1c769bd32837a3d1e97c8a85456f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 31 10:32:01 2026 -0400
Use final
---
...stractLhStaticHuffmanCompressorInputStream.java | 116 +++++++++++----------
.../compress/compressors/lha/CircularBuffer.java | 3 +-
2 files changed, 61 insertions(+), 58 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/compressors/lha/AbstractLhStaticHuffmanCompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/lha/AbstractLhStaticHuffmanCompressorInputStream.java
index 3940f9011..e5756fc9b 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lha/AbstractLhStaticHuffmanCompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lha/AbstractLhStaticHuffmanCompressorInputStream.java
@@ -103,7 +103,8 @@ private void fillBuffer() throws IOException {
if (this.blockSize == -1) {
// End of stream
return;
- } else if (this.blockSize == 0) {
+ }
+ if (this.blockSize == 0) {
// Start to read the next block
// Read the block size (number of commands to read)
@@ -125,7 +126,8 @@ private void fillBuffer() throws IOException {
final int command = commandTree.read(bin);
if (command == -1) {
throw new CompressorException("Unexpected end of stream");
- } else if (command < NUMBER_OF_LITERAL_CODES) {
+ }
+ if (command < NUMBER_OF_LITERAL_CODES) {
// Literal command, just write the byte to the buffer
buffer.put(command);
} else {
@@ -280,23 +282,22 @@ BinaryTree readCommandDecodingTree() throws IOException {
if (numCodeLengths > MAX_NUMBER_OF_COMMAND_DECODING_CODE_LENGTHS) {
throw new CompressorException("Code length table has invalid size (%d > %d)", numCodeLengths, MAX_NUMBER_OF_COMMAND_DECODING_CODE_LENGTHS);
- } else if (numCodeLengths == 0) {
+ }
+ if (numCodeLengths == 0) {
// If numCodeLengths is zero, we read a single code length of COMMAND_DECODING_LENGTH_BITS bits and use as root of the tree
return new BinaryTree(readBits(COMMAND_DECODING_LENGTH_BITS));
- } else {
- // Read all code lengths
- final int[] codeLengths = new int[numCodeLengths];
- for (int index = 0; index < numCodeLengths; index++) {
- codeLengths[index] = readCodeLength();
-
- if (index == 2) {
- // After reading the first three code lengths, we read a 2-bit skip range
- index += readBits(2);
- }
+ }
+ // Read all code lengths
+ final int[] codeLengths = new int[numCodeLengths];
+ for (int index = 0; index < numCodeLengths; index++) {
+ codeLengths[index] = readCodeLength();
+
+ if (index == 2) {
+ // After reading the first three code lengths, we read a 2-bit skip range
+ index += readBits(2);
}
-
- return new BinaryTree(codeLengths);
}
+ return new BinaryTree(codeLengths);
}
/**
@@ -311,35 +312,38 @@ BinaryTree readCommandTree(final BinaryTree commandDecodingTree) throws IOExcept
if (numCodeLengths > getMaxNumberOfCommands()) {
throw new CompressorException("Code length table has invalid size (%d > %d)", numCodeLengths, getMaxNumberOfCommands());
- } else if (numCodeLengths == 0) {
+ }
+ if (numCodeLengths == 0) {
// If numCodeLengths is zero, we read a single code length of COMMAND_TREE_LENGTH_BITS bits and use as root of the tree
return new BinaryTree(readBits(COMMAND_TREE_LENGTH_BITS));
- } else {
- // Read all code lengths
- final int[] codeLengths = new int[numCodeLengths];
-
- for (int index = 0; index < numCodeLengths;) {
- final int codeOrSkipRange = commandDecodingTree.read(bin);
-
- if (codeOrSkipRange == -1) {
- throw new CompressorException("Unexpected end of stream");
- } else if (codeOrSkipRange == 0) {
- // Skip one code length
- index++;
- } else if (codeOrSkipRange == 1) {
- // Skip a range of code lengths, read 4 bits to determine how many to skip
- index += readBits(4) + 3;
- } else if (codeOrSkipRange == 2) {
- // Skip a range of code lengths, read 9 bits to determine how many to skip
- index += readBits(9) + 20;
- } else {
- // Subtract 2 from the codeOrSkipRange to get the code length
- codeLengths[index++] = codeOrSkipRange - 2;
- }
- }
+ }
+ // Read all code lengths
+ final int[] codeLengths = new int[numCodeLengths];
+ for (int index = 0; index < numCodeLengths;) {
+ final int codeOrSkipRange = commandDecodingTree.read(bin);
- return new BinaryTree(codeLengths);
+ switch (codeOrSkipRange) {
+ case -1:
+ throw new CompressorException("Unexpected end of stream");
+ case 0:
+ // Skip one code length
+ index++;
+ break;
+ case 1:
+ // Skip a range of code lengths, read 4 bits to determine how many to skip
+ index += readBits(4) + 3;
+ break;
+ case 2:
+ // Skip a range of code lengths, read 9 bits to determine how many to skip
+ index += readBits(9) + 20;
+ break;
+ default:
+ // Subtract 2 from the codeOrSkipRange to get the code length
+ codeLengths[index++] = codeOrSkipRange - 2;
+ break;
+ }
}
+ return new BinaryTree(codeLengths);
}
/**
@@ -354,17 +358,16 @@ private int readDistance() throws IOException {
final int bits = distanceTree.read(bin);
if (bits == -1) {
throw new CompressorException("Unexpected end of stream");
- } else if (bits == 0 || bits == 1) {
+ }
+ if (bits == 0 || bits == 1) {
// This is effectively run length encoding
return bits;
- } else {
- // Bits minus one is the number of bits to read for the distance
- final int value = readBits(bits - 1);
-
- // Add the implicit bit (1 << (bits - 1)) to the value read from the stream giving the distance.
- // E.g. if bits is 6, we read 5 bits giving value 8 and then we add 32 giving a distance of 40.
- return value | (1 << (bits - 1));
}
+ // Bits minus one is the number of bits to read for the distance
+ final int value = readBits(bits - 1);
+ // Add the implicit bit (1 << (bits - 1)) to the value read from the stream giving the distance.
+ // E.g. if bits is 6, we read 5 bits giving value 8 and then we add 32 giving a distance of 40.
+ return value | 1 << bits - 1;
}
/**
@@ -379,17 +382,16 @@ private BinaryTree readDistanceTree() throws IOException {
if (numCodeLengths > getMaxNumberOfDistanceCodes()) {
throw new CompressorException("Code length table has invalid size (%d > %d)", numCodeLengths, getMaxNumberOfDistanceCodes());
- } else if (numCodeLengths == 0) {
+ }
+ if (numCodeLengths == 0) {
// If numCodeLengths is zero, we read a single code length of getDistanceBits() bits and use as root of the tree
return new BinaryTree(readBits(getDistanceBits()));
- } else {
- // Read all code lengths
- final int[] codeLengths = new int[numCodeLengths];
- for (int index = 0; index < numCodeLengths; index++) {
- codeLengths[index] = readCodeLength();
- }
-
- return new BinaryTree(codeLengths);
}
+ // Read all code lengths
+ final int[] codeLengths = new int[numCodeLengths];
+ for (int index = 0; index < numCodeLengths; index++) {
+ codeLengths[index] = readCodeLength();
+ }
+ return new BinaryTree(codeLengths);
}
}
diff --git a/src/main/java/org/apache/commons/compress/compressors/lha/CircularBuffer.java b/src/main/java/org/apache/commons/compress/compressors/lha/CircularBuffer.java
index 9f2c6b249..0b8a56323 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lha/CircularBuffer.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lha/CircularBuffer.java
@@ -69,7 +69,8 @@ public boolean available() {
public void copy(final int distance, final int length) {
if (distance < 1) {
throw new IllegalArgumentException("Distance must be at least 1");
- } else if (distance > size) {
+ }
+ if (distance > size) {
throw new IllegalArgumentException("Distance exceeds buffer size");
}
final int pos1 = writeIndex - distance;