Skip to content

Commit 042af17

Browse files
committed
Update javadocs
1 parent 54f7976 commit 042af17

10 files changed

Lines changed: 56 additions & 36 deletions

File tree

src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public int getCrcValue() {
147147
/**
148148
* Gets the operating system id if available for this entry.
149149
*
150-
* @return operating system id if available
150+
* @return operating system id or null if not available
151151
*/
152152
public Integer getOsId() {
153153
return osId;
@@ -183,7 +183,7 @@ public Integer getUnixGroupId() {
183183
/**
184184
* Gets the MS-DOS file attributes if available for this entry.
185185
*
186-
* @return MS-DOS file attributes if available
186+
* @return MS-DOS file attributes or null if not available
187187
*/
188188
public Integer getMsdosFileAttributes() {
189189
return msdosFileAttributes;

src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveInputStream.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ protected LhaArchiveEntry readHeaderLevel2(ByteBuffer buffer) throws IOException
408408
}
409409

410410
/**
411-
* Get the compression method from the header. It is always located at the same offset for all header levels.
411+
* Gets the compression method from the header. It is always located at the same offset for all header levels.
412412
*
413413
* @param buffer the buffer containing the header data
414414
* @return compression method, e.g. -lh5-
@@ -436,7 +436,7 @@ protected static String getCompressionMethod(final ByteBuffer buffer) throws Arc
436436
}
437437

438438
/**
439-
* Get the pathname from the current position in the provided buffer. Any 0xFF bytes
439+
* Gets the pathname from the current position in the provided buffer. Any 0xFF bytes
440440
* and '\' chars will be converted into the configured file path separator char.
441441
* Any leading file path separator char will be removed to avoid extracting to
442442
* absolute locations.
@@ -571,7 +571,7 @@ protected void parseExtendedHeader(final ByteBuffer extendedHeaderBuffer, final
571571
}
572572

573573
/**
574-
* Check if the compression method is a directory entry.
574+
* Tests whether the compression method is a directory entry.
575575
*
576576
* @param compressionMethod the compression method
577577
* @return true if the compression method is a directory entry, false otherwise

src/main/java/org/apache/commons/compress/archivers/lha/package-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
/**
21-
* Provides stream classes for reading archives using the LHA format, also known as the LZH format or LHarc format.
21+
* Provides stream classes for reading archives using the <a href="https://en.wikipedia.org/wiki/LHA_(file_format)">LHA</a> format,
22+
* also known as the LZH format or LHarc format.
2223
*/
2324
package org.apache.commons.compress.archivers.lha;

src/main/java/org/apache/commons/compress/compressors/lha/AbstractLhStaticHuffmanCompressorInputStream.java

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,41 @@
3333
/**
3434
* This is an implementation of a static Huffman compressor input stream for LHA files that
3535
* supports lh4, lh5, lh6 and lh7 compression methods.
36-
*
37-
* This implementation is based on the documentation that can be found at
38-
* https://github.com/jca02266/lha/blob/master/Hacking_of_LHa
3936
*/
4037
abstract class AbstractLhStaticHuffmanCompressorInputStream extends CompressorInputStream implements InputStreamStatistics {
41-
// Constants for command tree decoding
42-
private static final int COMMAND_DECODING_LENGTH_BITS = 5; // Number of bits used to encode the command decoding tree length
43-
private static final int MAX_NUMBER_OF_COMMAND_DECODING_CODE_LENGTHS = 19; // Maximum number of codes in the command decoding tree
44-
45-
// Constants for command tree
46-
private static final int COMMAND_TREE_LENGTH_BITS = 9; // Number of bits used to encode the command tree length
47-
48-
// Constants for code length
49-
private static final int CODE_LENGTH_BITS = 3; // Number of bits used to encode the code length
38+
/**
39+
* Number of bits used to encode the command decoding tree length.
40+
*/
41+
private static final int COMMAND_DECODING_LENGTH_BITS = 5;
42+
/**
43+
* Maximum number of codes in the command decoding tree.
44+
*/
45+
private static final int MAX_NUMBER_OF_COMMAND_DECODING_CODE_LENGTHS = 19;
46+
/**
47+
* Number of bits used to encode the command tree length.
48+
*/
49+
private static final int COMMAND_TREE_LENGTH_BITS = 9;
50+
/**
51+
* Number of literal codes (0-255).
52+
*/
53+
private static final int NUMBER_OF_LITERAL_CODES = 0x100;
54+
/**
55+
* Number of bits used to encode the code length.
56+
*/
57+
private static final int CODE_LENGTH_BITS = 3;
5058
private static final int MAX_CODE_LENGTH = 16;
5159

5260
private BitInputStream bin;
5361
private CircularBuffer buffer;
5462
private int blockSize;
55-
private BinaryTree commandTree; // Command is either a literal or a copy command
56-
private BinaryTree distanceTree; // Distance is the offset to copy from the sliding dictionary
63+
/**
64+
* Command is either a literal or a copy command.
65+
*/
66+
private BinaryTree commandTree;
67+
/**
68+
* Distance is the offset to copy from the sliding dictionary.
69+
*/
70+
private BinaryTree distanceTree;
5771

5872
/**
5973
* Constructs a new CompressorInputStream which decompresses bytes read from the specified stream.
@@ -82,7 +96,7 @@ public void close() throws IOException {
8296
}
8397

8498
/**
85-
* Get the threshold for copying data from the sliding dictionary. This is the minimum
99+
* Gets the threshold for copying data from the sliding dictionary. This is the minimum
86100
* possible number of bytes that will be part of a copy command.
87101
*
88102
* @return the copy threshold
@@ -92,14 +106,14 @@ protected int getCopyThreshold() {
92106
}
93107

94108
/**
95-
* Get the number of bits used for the dictionary size.
109+
* Gets the number of bits used for the dictionary size.
96110
*
97111
* @return the number of bits used for the dictionary size
98112
*/
99113
protected abstract int getDictionaryBits();
100114

101115
/**
102-
* Get the size of the dictionary.
116+
* Gets the size of the dictionary.
103117
*
104118
* @return the size of the dictionary
105119
*/
@@ -108,18 +122,23 @@ protected int getDictionarySize() {
108122
}
109123

110124
/**
111-
* Get the number of bits used for the distance.
125+
* Gets the number of bits used for the distance.
112126
*
113127
* @return the number of bits used for the distance
114128
*/
115129
protected abstract int getDistanceBits();
116130

117-
protected int getDistanceCodeSize() {
131+
/**
132+
* Gets the maximum number of distance codes in the distance tree.
133+
*
134+
* @return the maximum number of distance codes
135+
*/
136+
protected int getMaxNumberOfDistanceCodes() {
118137
return getDictionaryBits() + 1;
119138
}
120139

121140
/**
122-
* Get the maximum match length for the copy command.
141+
* Gets the maximum match length for the copy command.
123142
*
124143
* @return the maximum match length
125144
*/
@@ -128,13 +147,13 @@ protected int getMaxMatchLength() {
128147
}
129148

130149
/**
131-
* Get the maximum number of commands in the command tree.
150+
* Gets the maximum number of commands in the command tree.
132151
* This is 256 literals (0-255) and 254 copy lengths combinations (3-256).
133152
*
134153
* @return the maximum number of commands
135154
*/
136155
protected int getMaxNumberOfCommands() {
137-
return 256 + getMaxMatchLength() - getCopyThreshold() + 1;
156+
return NUMBER_OF_LITERAL_CODES + getMaxMatchLength() - getCopyThreshold() + 1;
138157
}
139158

140159
@Override
@@ -306,8 +325,8 @@ private BinaryTree readDistanceTree() throws IOException {
306325
// Number of code lengths to read
307326
final int numCodeLengths = readBits(getDistanceBits());
308327

309-
if (numCodeLengths > getDistanceCodeSize()) {
310-
throw new CompressorException("Code length table has invalid size (%d > %d)", numCodeLengths, getDistanceCodeSize());
328+
if (numCodeLengths > getMaxNumberOfDistanceCodes()) {
329+
throw new CompressorException("Code length table has invalid size (%d > %d)", numCodeLengths, getMaxNumberOfDistanceCodes());
311330
} else if (numCodeLengths == 0) {
312331
// If numCodeLengths is zero, we read a single code length of getDistanceBits() bits and use as root of the tree
313332
return new BinaryTree(readBits(getDistanceBits()));

src/main/java/org/apache/commons/compress/compressors/lha/Lh4CompressorInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected int getDistanceBits() {
4343
}
4444

4545
@Override
46-
protected int getDistanceCodeSize() {
46+
protected int getMaxNumberOfDistanceCodes() {
4747
return getDictionaryBits() + 2;
4848
}
4949
}

src/main/java/org/apache/commons/compress/compressors/lha/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
*/
1919

2020
/**
21-
* Provides stream classes for decompressing streams found in LHA archives.
21+
* Provides stream classes for decompressing streams found in <a href="https://en.wikipedia.org/wiki/LHA_(file_format)">LHA</a> archives.
2222
*/
2323
package org.apache.commons.compress.compressors.lha;

src/test/java/org/apache/commons/compress/compressors/lha/Lh4CompressorInputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void testConfiguration() throws IOException {
4040
assertEquals(12, in.getDictionaryBits());
4141
assertEquals(4096, in.getDictionarySize());
4242
assertEquals(4, in.getDistanceBits());
43-
assertEquals(14, in.getDistanceCodeSize());
43+
assertEquals(14, in.getMaxNumberOfDistanceCodes());
4444
assertEquals(256, in.getMaxMatchLength());
4545
assertEquals(510, in.getMaxNumberOfCommands());
4646
}

src/test/java/org/apache/commons/compress/compressors/lha/Lh5CompressorInputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void testConfiguration() throws IOException {
4040
assertEquals(8192, in.getDictionarySize());
4141
assertEquals(13, in.getDictionaryBits());
4242
assertEquals(4, in.getDistanceBits());
43-
assertEquals(14, in.getDistanceCodeSize());
43+
assertEquals(14, in.getMaxNumberOfDistanceCodes());
4444
assertEquals(256, in.getMaxMatchLength());
4545
assertEquals(510, in.getMaxNumberOfCommands());
4646
}

src/test/java/org/apache/commons/compress/compressors/lha/Lh6CompressorInputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void testConfiguration() throws IOException {
4040
assertEquals(15, in.getDictionaryBits());
4141
assertEquals(32768, in.getDictionarySize());
4242
assertEquals(5, in.getDistanceBits());
43-
assertEquals(16, in.getDistanceCodeSize());
43+
assertEquals(16, in.getMaxNumberOfDistanceCodes());
4444
assertEquals(256, in.getMaxMatchLength());
4545
assertEquals(510, in.getMaxNumberOfCommands());
4646
}

src/test/java/org/apache/commons/compress/compressors/lha/Lh7CompressorInputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void testConfiguration() throws IOException {
4040
assertEquals(16, in.getDictionaryBits());
4141
assertEquals(65536, in.getDictionarySize());
4242
assertEquals(5, in.getDistanceBits());
43-
assertEquals(17, in.getDistanceCodeSize());
43+
assertEquals(17, in.getMaxNumberOfDistanceCodes());
4444
assertEquals(256, in.getMaxMatchLength());
4545
assertEquals(510, in.getMaxNumberOfCommands());
4646
}

0 commit comments

Comments
 (0)