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
The following commit(s) were added to refs/heads/master by this push:
new c1f46fb82 Reduce public API footprint for new LHA code.
c1f46fb82 is described below
commit c1f46fb82a4a0ff7b311ad2c145393a638eced2d
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Jul 31 12:18:20 2026 -0400
Reduce public API footprint for new LHA code.
Reduce vertical whitespace.
---
.../{compressors => archivers}/lha/BinaryTree.java | 6 +-
.../lha/CircularBuffer.java | 2 +-
.../lha/LhStaticHuffmanCompressorInputStream.java | 50 +++--
.../compress/archivers/lha/LhaArchiveEntry.java | 3 +-
.../archivers/lha/LhaArchiveInputStream.java | 2 +-
.../compress/archivers/lha/package-info.java | 5 +-
.../lha/BinaryTreeTest.java | 127 +++++-------
.../lha/CircularBufferTest.java | 46 +----
.../lha/Lh4CompressorInputStreamTest.java | 10 +-
.../lha/Lh5CompressorInputStreamTest.java | 4 +-
.../lha/Lh6CompressorInputStreamTest.java | 12 +-
.../lha/Lh7CompressorInputStreamTest.java | 7 +-
.../LhStaticHuffmanCompressorInputStreamTest.java | 2 +-
.../archivers/lha/LhaArchiveInputStreamTest.java | 216 +++------------------
14 files changed, 125 insertions(+), 367 deletions(-)
diff --git
a/src/main/java/org/apache/commons/compress/compressors/lha/BinaryTree.java
b/src/main/java/org/apache/commons/compress/archivers/lha/BinaryTree.java
similarity index 98%
rename from
src/main/java/org/apache/commons/compress/compressors/lha/BinaryTree.java
rename to
src/main/java/org/apache/commons/compress/archivers/lha/BinaryTree.java
index 63e8e83d8..a1f551627 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lha/BinaryTree.java
+++ b/src/main/java/org/apache/commons/compress/archivers/lha/BinaryTree.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
import java.io.IOException;
import java.util.Arrays;
@@ -113,8 +113,8 @@ private int[] initTree(final int depth) throws
CompressorException {
}
/**
- * Reads a value from the specified bit stream.
- *.
+ * Reads a value from the specified bit stream. .
+ *
* @param stream The data source.
* @return the value decoded, or -1 if the end of the stream is reached.
* @throws IOException on error.
diff --git
a/src/main/java/org/apache/commons/compress/compressors/lha/CircularBuffer.java
b/src/main/java/org/apache/commons/compress/archivers/lha/CircularBuffer.java
similarity index 98%
rename from
src/main/java/org/apache/commons/compress/compressors/lha/CircularBuffer.java
rename to
src/main/java/org/apache/commons/compress/archivers/lha/CircularBuffer.java
index 1f15442b1..eb16fba06 100644
---
a/src/main/java/org/apache/commons/compress/compressors/lha/CircularBuffer.java
+++
b/src/main/java/org/apache/commons/compress/archivers/lha/CircularBuffer.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
/**
* Circular byte buffer. Copied from
org.apache.commons.compress.archivers.zip.CircularBuffer and modified for LHA.
diff --git
a/src/main/java/org/apache/commons/compress/compressors/lha/LhStaticHuffmanCompressorInputStream.java
b/src/main/java/org/apache/commons/compress/archivers/lha/LhStaticHuffmanCompressorInputStream.java
similarity index 98%
rename from
src/main/java/org/apache/commons/compress/compressors/lha/LhStaticHuffmanCompressorInputStream.java
rename to
src/main/java/org/apache/commons/compress/archivers/lha/LhStaticHuffmanCompressorInputStream.java
index 00aeb375b..ae43fef30 100644
---
a/src/main/java/org/apache/commons/compress/compressors/lha/LhStaticHuffmanCompressorInputStream.java
+++
b/src/main/java/org/apache/commons/compress/archivers/lha/LhStaticHuffmanCompressorInputStream.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
import java.io.IOException;
import java.io.InputStream;
@@ -31,10 +31,8 @@
/**
* Implements a static Huffman compressor input stream for LHA files that
supports lh4, lh5, lh6 and lh7 compression methods.
- *
- * @since 1.29.0
*/
-public class LhStaticHuffmanCompressorInputStream extends
CompressorInputStream implements InputStreamStatistics {
+class LhStaticHuffmanCompressorInputStream extends CompressorInputStream
implements InputStreamStatistics {
/**
* Number of bits used to encode the command decoding tree length.
@@ -71,28 +69,6 @@ public class LhStaticHuffmanCompressorInputStream extends
CompressorInputStream
private static final int DICT_BITS_LH7 = 16;
- private BitInputStream bin;
-
- private CircularBuffer buffer;
-
- private int blockSize;
-
- /**
- * Command is either a literal or a copy command.
- */
- private BinaryTree commandTree;
-
- /**
- * Distance is the offset to copy from the sliding dictionary.
- */
- private BinaryTree distanceTree;
-
- private final int dictionaryBits;
-
- private final int distanceBits;
-
- private final int maxNumberOfDistanceCodes;
-
/**
* Creates a new LhStaticHuffmanCompressorInputStream for the specified
InputStream and LH4.
*
@@ -137,6 +113,28 @@ public static LhStaticHuffmanCompressorInputStream
lh7CompressorInputStream(fina
return new LhStaticHuffmanCompressorInputStream(in, DICT_BITS_LH7, 5,
DICT_BITS_LH7 + 1);
}
+ private BitInputStream bin;
+
+ private CircularBuffer buffer;
+
+ private int blockSize;
+
+ /**
+ * Command is either a literal or a copy command.
+ */
+ private BinaryTree commandTree;
+
+ /**
+ * Distance is the offset to copy from the sliding dictionary.
+ */
+ private BinaryTree distanceTree;
+
+ private final int dictionaryBits;
+
+ private final int distanceBits;
+
+ private final int maxNumberOfDistanceCodes;
+
/**
* Constructs a new CompressorInputStream which decompresses bytes read
from the specified stream.
*
diff --git
a/src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveEntry.java
b/src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveEntry.java
index 427123fcc..8cff36cdf 100644
---
a/src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveEntry.java
+++
b/src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveEntry.java
@@ -171,8 +171,7 @@ static Builder builder() {
private final Integer headerCrc;
LhaArchiveEntry(final Builder builder) {
- this.name = new
StringBuilder().append(Objects.toString(builder.directoryName, ""))
- .append(Objects.toString(builder.fileName, "")).toString();
+ this.name = new
StringBuilder().append(Objects.toString(builder.directoryName,
"")).append(Objects.toString(builder.fileName, "")).toString();
this.directory = builder.directory;
this.size = builder.size;
this.lastModifiedDate = builder.lastModifiedDate;
diff --git
a/src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveInputStream.java
b/src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveInputStream.java
index de7f4da24..4ad86ffa6 100644
---
a/src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveInputStream.java
+++
b/src/main/java/org/apache/commons/compress/archivers/lha/LhaArchiveInputStream.java
@@ -38,7 +38,6 @@
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipUtil;
-import
org.apache.commons.compress.compressors.lha.LhStaticHuffmanCompressorInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.BoundedInputStream;
import org.apache.commons.io.input.ChecksumInputStream;
@@ -58,6 +57,7 @@ public class LhaArchiveInputStream extends
ArchiveInputStream<LhaArchiveEntry> {
* </p>
*
* <pre>{@code
+ *
* LhaArchiveInputStream in =
LhaArchiveInputStream.builder().setPath(inputPath).setCharset(StandardCharsets.UTF_8).get();
* }</pre>
*/
diff --git
a/src/main/java/org/apache/commons/compress/archivers/lha/package-info.java
b/src/main/java/org/apache/commons/compress/archivers/lha/package-info.java
index bd073a9df..abeff103e 100644
--- a/src/main/java/org/apache/commons/compress/archivers/lha/package-info.java
+++ b/src/main/java/org/apache/commons/compress/archivers/lha/package-info.java
@@ -18,9 +18,10 @@
*/
/**
- * Provides stream classes for reading archives using the <a
href="https://en.wikipedia.org/wiki/LHA_(file_format)">LHA</a> format,
- * also known as the LZH format or LHarc format.
+ * Provides stream classes for reading archives using the <a
href="https://en.wikipedia.org/wiki/LHA_(file_format)">LHA</a> format, also
known as the LZH format
+ * or LHarc format.
*
* @since 1.29.0
*/
+
package org.apache.commons.compress.archivers.lha;
diff --git
a/src/test/java/org/apache/commons/compress/compressors/lha/BinaryTreeTest.java
b/src/test/java/org/apache/commons/compress/archivers/lha/BinaryTreeTest.java
similarity index 75%
rename from
src/test/java/org/apache/commons/compress/compressors/lha/BinaryTreeTest.java
rename to
src/test/java/org/apache/commons/compress/archivers/lha/BinaryTreeTest.java
index 8c48936fa..caaca1ce5 100644
---
a/src/test/java/org/apache/commons/compress/compressors/lha/BinaryTreeTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/lha/BinaryTreeTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
@@ -31,12 +31,12 @@
import org.junit.jupiter.api.Test;
class BinaryTreeTest {
+
private BitInputStream createBitInputStream(final int... data) throws
IOException {
final byte[] bytes = new byte[data.length];
for (int i = 0; i < data.length; i++) {
bytes[i] = (byte) data[i];
}
-
return new BitInputStream(new ByteArrayInputStream(bytes),
ByteOrder.BIG_ENDIAN);
}
@@ -53,16 +53,13 @@ void testCheckMaxDepth() throws Exception {
@Test
void testInvalidBitstream() throws Exception {
final int[] length = { 4, 2, 3, 0, 5, 0, 1 };
- // Value: 0 1 2 3 4 5 6
-
+ // Value: 0 1 2 3 4 5 6
final BinaryTree tree = new BinaryTree(length);
-
assertEquals(6, tree.read(createBitInputStream(0x00))); // 0xxx xxxx
assertEquals(1, tree.read(createBitInputStream(0x80))); // 10xx xxxx
assertEquals(2, tree.read(createBitInputStream(0xc0))); // 110x xxxx
assertEquals(0, tree.read(createBitInputStream(0xe0))); // 1110 xxxx
assertEquals(4, tree.read(createBitInputStream(0xf0))); // 1111 0xxx
-
try {
assertEquals(5, tree.read(createBitInputStream(0xf8))); // 1111
1xxx
fail("Expected CompressorException for invalid bitstream");
@@ -84,14 +81,11 @@ void testNoLeafNodes() throws Exception {
@Test
void testReadEof() throws Exception {
final int[] length = { 4, 2, 3, 0, 5, 5, 1 };
- // Value: 0 1 2 3 4 5 6
-
+ // Value: 0 1 2 3 4 5 6
final BinaryTree tree = new BinaryTree(length);
-
final BitInputStream in = createBitInputStream(0xfe); // 1111 1110
-
- assertEquals(5, tree.read(in)); // 1111 1xxx
- assertEquals(2, tree.read(in)); // 110x xxxx
+ assertEquals(5, tree.read(in)); // 1111 1xxx
+ assertEquals(2, tree.read(in)); // 110x xxxx
assertEquals(-1, tree.read(in)); // EOF
}
@@ -109,56 +103,47 @@ void testTooManyLeafNodes() throws Exception {
void testTree1() throws Exception {
// Special case where the single array value is the root node value
final BinaryTree tree = new BinaryTree(4);
-
assertEquals(4, tree.read(createBitInputStream())); // Nothing to
read, just return the root value
}
@Test
void testTree10() throws Exception {
// Maximum length of 510 entries for command tree and maximum
supported depth of 16
- final int[] length = { 4, 7, 7, 8, 7, 9, 8, 9, 7, 10, 8, 10, 7, 10, 8,
10, 7, 9, 8, 9, 8, 10, 8, 12, 8, 10, 9, 11, 9, 9, 8, 10, 6, 9,
- 7, 9, 8, 10, 8, 11, 7, 9, 8, 9, 8, 9, 8, 9, 7, 9, 8, 8, 8, 10,
9, 11, 8, 9, 8, 10, 8, 9, 8, 9, 7, 7, 7, 8, 8, 8, 8, 9, 7, 8, 7, 9, 8, 9,
- 8, 8, 8, 10, 7, 7, 8, 8, 8, 9, 8, 9, 8, 9, 9, 10, 9, 10, 7, 8,
9, 9, 8, 7, 7, 7, 8, 8, 9, 8, 8, 9, 8, 8, 8, 11, 8, 9, 8, 8, 9, 10, 9, 9,
- 8, 10, 8, 10, 9, 9, 7, 9, 9, 10, 9, 10, 9, 9, 9, 10, 9, 11,
10, 11, 9, 10, 8, 10, 9, 11, 9, 10, 10, 12, 9, 11, 9, 12, 10, 14, 10, 14, 10,
- 11, 10, 11, 9, 11, 10, 12, 9, 11, 10, 11, 9, 10, 10, 11, 9,
11, 10, 12, 10, 13, 11, 13, 10, 11, 10, 13, 10, 15, 10, 14, 8, 10, 9, 10, 9,
- 10, 10, 11, 9, 11, 10, 12, 10, 13, 10, 13, 9, 11, 9, 11, 9,
12, 9, 11, 9, 10, 9, 12, 9, 11, 9, 9, 9, 10, 8, 10, 9, 11, 9, 10, 9, 10, 9,
- 10, 9, 10, 9, 11, 8, 10, 9, 10, 9, 10, 9, 11, 9, 10, 8, 10, 8,
10, 9, 7, 3, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 10, 10, 11, 11, 11,
- 10, 11, 12, 11, 12, 12, 12, 12, 13, 13, 13, 14, 12, 14, 13,
16, 14, 16, 13, 15, 14, 13, 15, 14, 15, 14, 15, 14, 14, 0, 14, 15, 14, 0,
- 14, 0, 0, 0, 0, 0, 0, 0, 15, 0, 15, 0, 0, 15, 15, 0, 0, 0, 0,
0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 13, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 15, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0,
0, 0, 15, 10 };
-
+ final int[] length = { 4, 7, 7, 8, 7, 9, 8, 9, 7, 10, 8, 10, 7, 10, 8,
10, 7, 9, 8, 9, 8, 10, 8, 12, 8, 10, 9, 11, 9, 9, 8, 10, 6, 9, 7, 9, 8, 10, 8,
+ 11, 7, 9, 8, 9, 8, 9, 8, 9, 7, 9, 8, 8, 8, 10, 9, 11, 8, 9, 8,
10, 8, 9, 8, 9, 7, 7, 7, 8, 8, 8, 8, 9, 7, 8, 7, 9, 8, 9, 8, 8, 8, 10, 7, 7, 8,
+ 8, 8, 9, 8, 9, 8, 9, 9, 10, 9, 10, 7, 8, 9, 9, 8, 7, 7, 7, 8,
8, 9, 8, 8, 9, 8, 8, 8, 11, 8, 9, 8, 8, 9, 10, 9, 9, 8, 10, 8, 10, 9, 9, 7, 9,
9,
+ 10, 9, 10, 9, 9, 9, 10, 9, 11, 10, 11, 9, 10, 8, 10, 9, 11, 9,
10, 10, 12, 9, 11, 9, 12, 10, 14, 10, 14, 10, 11, 10, 11, 9, 11, 10, 12, 9, 11,
+ 10, 11, 9, 10, 10, 11, 9, 11, 10, 12, 10, 13, 11, 13, 10, 11,
10, 13, 10, 15, 10, 14, 8, 10, 9, 10, 9, 10, 10, 11, 9, 11, 10, 12, 10, 13, 10,
+ 13, 9, 11, 9, 11, 9, 12, 9, 11, 9, 10, 9, 12, 9, 11, 9, 9, 9,
10, 8, 10, 9, 11, 9, 10, 9, 10, 9, 10, 9, 10, 9, 11, 8, 10, 9, 10, 9, 10, 9, 11,
+ 9, 10, 8, 10, 8, 10, 9, 7, 3, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9,
9, 9, 10, 10, 11, 11, 11, 10, 11, 12, 11, 12, 12, 12, 12, 13, 13, 13, 14, 12,
14,
+ 13, 16, 14, 16, 13, 15, 14, 13, 15, 14, 15, 14, 15, 14, 14, 0,
14, 15, 14, 0, 14, 0, 0, 0, 0, 0, 0, 0, 15, 0, 15, 0, 0, 15, 15, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 15, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 13, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
+ 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0,
0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 15, 10 };
final BinaryTree tree = new BinaryTree(length);
-
- assertEquals(256, tree.read(createBitInputStream(0x00, 0x00))); //
000x xxxx xxxx xxxx
- assertEquals(0, tree.read(createBitInputStream(0x20, 0x00))); //
0010 xxxx xxxx xxxx
- assertEquals(257, tree.read(createBitInputStream(0x30, 0x00))); //
0011 xxxx xxxx xxxx
- assertEquals(258, tree.read(createBitInputStream(0x40, 0x00))); //
0100 0xxx xxxx xxxx
- assertEquals(259, tree.read(createBitInputStream(0x48, 0x00))); //
0100 1xxx xxxx xxxx
- assertEquals(32, tree.read(createBitInputStream(0x50, 0x00))); //
0101 00xx xxxx xxxx
- assertEquals(260, tree.read(createBitInputStream(0x54, 0x00))); //
0101 01xx xxxx xxxx
-
- assertEquals(226, tree.read(createBitInputStream(0xbd, 0x00))); //
1011 1101 xxxx xxxx
- assertEquals(240, tree.read(createBitInputStream(0xbe, 0x00))); //
1011 1110 xxxx xxxx
-
- assertEquals(163, tree.read(createBitInputStream(0xfb, 0xa0))); //
1111 1011 101x xxxx
- assertEquals(165, tree.read(createBitInputStream(0xfb, 0xc0))); //
1111 1011 110x xxxx
-
- assertEquals(499, tree.read(createBitInputStream(0xff, 0xfa))); //
1111 1111 1111 101x
- assertEquals(508, tree.read(createBitInputStream(0xff, 0xfc))); //
1111 1111 1111 110x
- assertEquals(290, tree.read(createBitInputStream(0xff, 0xfe))); //
1111 1111 1111 1110
- assertEquals(292, tree.read(createBitInputStream(0xff, 0xff))); //
1111 1111 1111 1111
+ assertEquals(256, tree.read(createBitInputStream(0x00, 0x00))); //
000x xxxx xxxx xxxx
+ assertEquals(0, tree.read(createBitInputStream(0x20, 0x00))); // 0010
xxxx xxxx xxxx
+ assertEquals(257, tree.read(createBitInputStream(0x30, 0x00))); //
0011 xxxx xxxx xxxx
+ assertEquals(258, tree.read(createBitInputStream(0x40, 0x00))); //
0100 0xxx xxxx xxxx
+ assertEquals(259, tree.read(createBitInputStream(0x48, 0x00))); //
0100 1xxx xxxx xxxx
+ assertEquals(32, tree.read(createBitInputStream(0x50, 0x00))); // 0101
00xx xxxx xxxx
+ assertEquals(260, tree.read(createBitInputStream(0x54, 0x00))); //
0101 01xx xxxx xxxx
+ assertEquals(226, tree.read(createBitInputStream(0xbd, 0x00))); //
1011 1101 xxxx xxxx
+ assertEquals(240, tree.read(createBitInputStream(0xbe, 0x00))); //
1011 1110 xxxx xxxx
+ assertEquals(163, tree.read(createBitInputStream(0xfb, 0xa0))); //
1111 1011 101x xxxx
+ assertEquals(165, tree.read(createBitInputStream(0xfb, 0xc0))); //
1111 1011 110x xxxx
+ assertEquals(499, tree.read(createBitInputStream(0xff, 0xfa))); //
1111 1111 1111 101x
+ assertEquals(508, tree.read(createBitInputStream(0xff, 0xfc))); //
1111 1111 1111 110x
+ assertEquals(290, tree.read(createBitInputStream(0xff, 0xfe))); //
1111 1111 1111 1110
+ assertEquals(292, tree.read(createBitInputStream(0xff, 0xff))); //
1111 1111 1111 1111
}
@Test
void testTree2() throws Exception {
final int[] length = { 1, 1 };
- // Value: 0 1
-
+ // Value: 0 1
final BinaryTree tree = new BinaryTree(length);
-
assertEquals(0, tree.read(createBitInputStream(0x00))); // 0xxx xxxx
assertEquals(1, tree.read(createBitInputStream(0x80))); // 1xxx xxxx
}
@@ -166,10 +151,8 @@ void testTree2() throws Exception {
@Test
void testTree3() throws Exception {
final int[] length = { 1, 0, 1 };
- // Value: 0 1 2
-
+ // Value: 0 1 2
final BinaryTree tree = new BinaryTree(length);
-
assertEquals(0, tree.read(createBitInputStream(0x00))); // 0xxx xxxx
assertEquals(2, tree.read(createBitInputStream(0x80))); // 1xxx xxxx
}
@@ -177,10 +160,8 @@ void testTree3() throws Exception {
@Test
void testTree4() throws Exception {
final int[] length = { 2, 0, 1, 2 };
- // Value: 0 1 2 3
-
+ // Value: 0 1 2 3
final BinaryTree tree = new BinaryTree(length);
-
assertEquals(2, tree.read(createBitInputStream(0x00))); // 0xxx xxxx
assertEquals(0, tree.read(createBitInputStream(0x80))); // 10xx xxxx
assertEquals(3, tree.read(createBitInputStream(0xc0))); // 11xx xxxx
@@ -189,10 +170,8 @@ void testTree4() throws Exception {
@Test
void testTree5() throws Exception {
final int[] length = { 2, 0, 0, 2, 1 };
- // Value: 0 1 2 3 4
-
+ // Value: 0 1 2 3 4
final BinaryTree tree = new BinaryTree(length);
-
assertEquals(4, tree.read(createBitInputStream(0x00))); // 0xxx xxxx
assertEquals(0, tree.read(createBitInputStream(0x80))); // 10xx xxxx
assertEquals(3, tree.read(createBitInputStream(0xc0))); // 11xx xxxx
@@ -201,10 +180,8 @@ void testTree5() throws Exception {
@Test
void testTree6() throws Exception {
final int[] length = { 1, 0, 2, 3, 3 };
- // Value: 0 1 2 3 4
-
+ // Value: 0 1 2 3 4
final BinaryTree tree = new BinaryTree(length);
-
assertEquals(0, tree.read(createBitInputStream(0x00))); // 0xxx xxxx
assertEquals(2, tree.read(createBitInputStream(0x80))); // 10xx xxxx
assertEquals(3, tree.read(createBitInputStream(0xc0))); // 110x xxxx
@@ -214,10 +191,8 @@ void testTree6() throws Exception {
@Test
void testTree7() throws Exception {
final int[] length = { 0, 0, 0, 0, 1, 1 };
- // Value: 0 1 2 3 4 5
-
+ // Value: 0 1 2 3 4 5
final BinaryTree tree = new BinaryTree(length);
-
assertEquals(4, tree.read(createBitInputStream(0x00))); // 0xxx xxxx
assertEquals(5, tree.read(createBitInputStream(0x80))); // 1xxx xxxx
}
@@ -225,10 +200,8 @@ void testTree7() throws Exception {
@Test
void testTree8() throws Exception {
final int[] length = { 4, 2, 3, 0, 5, 5, 1 };
- // Value: 0 1 2 3 4 5 6
-
+ // Value: 0 1 2 3 4 5 6
final BinaryTree tree = new BinaryTree(length);
-
assertEquals(6, tree.read(createBitInputStream(0x00))); // 0xxx xxxx
assertEquals(1, tree.read(createBitInputStream(0x80))); // 10xx xxxx
assertEquals(2, tree.read(createBitInputStream(0xc0))); // 110x xxxx
@@ -240,26 +213,24 @@ void testTree8() throws Exception {
@Test
void testTree9() throws Exception {
final int[] length = { 5, 6, 6, 0, 0, 8, 7, 7, 7, 4, 3, 2, 2, 4, 5, 5,
5, 4, 8 };
- // Value: 0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15 16 17 18
-
+ // Value: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
final BinaryTree tree = new BinaryTree(length);
-
assertEquals(11, tree.read(createBitInputStream(0x00))); // 00xx xxxx
assertEquals(12, tree.read(createBitInputStream(0x40))); // 01xx xxxx
assertEquals(10, tree.read(createBitInputStream(0x80))); // 100x xxxx
- assertEquals(9, tree.read(createBitInputStream(0xa0))); // 1010 xxxx
+ assertEquals(9, tree.read(createBitInputStream(0xa0))); // 1010 xxxx
assertEquals(13, tree.read(createBitInputStream(0xb0))); // 1011 xxxx
assertEquals(17, tree.read(createBitInputStream(0xc0))); // 1100 xxxx
- assertEquals(0, tree.read(createBitInputStream(0xd0))); // 1101 0xxx
+ assertEquals(0, tree.read(createBitInputStream(0xd0))); // 1101 0xxx
assertEquals(14, tree.read(createBitInputStream(0xd8))); // 1101 1xxx
assertEquals(15, tree.read(createBitInputStream(0xe0))); // 1110 0xxx
assertEquals(16, tree.read(createBitInputStream(0xe8))); // 1110 1xxx
- assertEquals(1, tree.read(createBitInputStream(0xf0))); // 1111 00xx
- assertEquals(2, tree.read(createBitInputStream(0xf4))); // 1111 01xx
- assertEquals(6, tree.read(createBitInputStream(0xf8))); // 1111 100x
- assertEquals(7, tree.read(createBitInputStream(0xfa))); // 1111 101x
- assertEquals(8, tree.read(createBitInputStream(0xfc))); // 1111 110x
- assertEquals(5, tree.read(createBitInputStream(0xfe))); // 1111 1110
+ assertEquals(1, tree.read(createBitInputStream(0xf0))); // 1111 00xx
+ assertEquals(2, tree.read(createBitInputStream(0xf4))); // 1111 01xx
+ assertEquals(6, tree.read(createBitInputStream(0xf8))); // 1111 100x
+ assertEquals(7, tree.read(createBitInputStream(0xfa))); // 1111 101x
+ assertEquals(8, tree.read(createBitInputStream(0xfc))); // 1111 110x
+ assertEquals(5, tree.read(createBitInputStream(0xfe))); // 1111 1110
assertEquals(18, tree.read(createBitInputStream(0xff))); // 1111 1111
}
}
diff --git
a/src/test/java/org/apache/commons/compress/compressors/lha/CircularBufferTest.java
b/src/test/java/org/apache/commons/compress/archivers/lha/CircularBufferTest.java
similarity index 99%
rename from
src/test/java/org/apache/commons/compress/compressors/lha/CircularBufferTest.java
rename to
src/test/java/org/apache/commons/compress/archivers/lha/CircularBufferTest.java
index 569509741..81c02429f 100644
---
a/src/test/java/org/apache/commons/compress/compressors/lha/CircularBufferTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/lha/CircularBufferTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -27,18 +27,16 @@
import org.junit.jupiter.api.Test;
class CircularBufferTest {
+
@Test
void testCopy1() {
final CircularBuffer buffer = new CircularBuffer(16);
-
buffer.put(1);
buffer.put(2);
buffer.get();
buffer.get();
-
// copy uninitialized data
buffer.copy(6, 8);
-
for (int i = 2; i < 6; i++) {
assertEquals(0, buffer.get(), "buffer[" + i + "]");
}
@@ -46,17 +44,13 @@ void testCopy1() {
assertEquals(2, buffer.get(), "buffer[" + 7 + "]");
assertEquals(0, buffer.get(), "buffer[" + 8 + "]");
assertEquals(0, buffer.get(), "buffer[" + 9 + "]");
-
for (int i = 10; i < 14; i++) {
buffer.put(i);
buffer.get();
}
-
assertFalse(buffer.available(), "available");
-
// copy data and wrap
buffer.copy(2, 8);
-
for (int i = 14; i < 18; i++) {
assertEquals(i % 2 == 0 ? 12 : 13, buffer.get(), "buffer[" + i +
"]");
}
@@ -65,22 +59,18 @@ void testCopy1() {
@Test
void testCopy2() {
final CircularBuffer buffer = new CircularBuffer(16);
-
// Write some bytes
buffer.put(0x01);
buffer.put(0x02);
buffer.put(0x03);
buffer.put(0x04);
-
buffer.copy(2, 2); // Copy last two bytes (0x03, 0x04)
-
assertEquals(0x01, buffer.get());
assertEquals(0x02, buffer.get());
assertEquals(0x03, buffer.get());
assertEquals(0x04, buffer.get());
assertEquals(0x03, buffer.get());
assertEquals(0x04, buffer.get());
-
assertFalse(buffer.available());
assertEquals(-1, buffer.get());
}
@@ -88,22 +78,18 @@ void testCopy2() {
@Test
void testCopy3() {
final CircularBuffer buffer = new CircularBuffer(16);
-
// Write some bytes
buffer.put(0x01);
buffer.put(0x02);
buffer.put(0x03);
buffer.put(0x04);
-
buffer.copy(4, 2); // Copy first two bytes (0x01, 0x02)
-
assertEquals(0x01, buffer.get());
assertEquals(0x02, buffer.get());
assertEquals(0x03, buffer.get());
assertEquals(0x04, buffer.get());
assertEquals(0x01, buffer.get()); // Copied byte
assertEquals(0x02, buffer.get()); // Copied byte
-
assertFalse(buffer.available());
assertEquals(-1, buffer.get());
}
@@ -111,7 +97,6 @@ void testCopy3() {
@Test
void testCopy4() {
final CircularBuffer buffer = new CircularBuffer(6);
-
// Write some bytes
buffer.put(0x01);
buffer.put(0x02);
@@ -119,19 +104,15 @@ void testCopy4() {
buffer.put(0x04);
buffer.put(0x05);
buffer.put(0x06);
-
// Read four bytes to make space
assertEquals(0x01, buffer.get());
assertEquals(0x02, buffer.get());
assertEquals(0x03, buffer.get());
assertEquals(0x04, buffer.get());
-
// Write two more bytes and making the buffer wrap around
buffer.put(0x07);
buffer.put(0x08);
-
buffer.copy(3, 2); // Copy two bytes from 3 bytes ago (0x06, 0x07)
where the buffer wraps around
-
// Read rest of the buffer
assertEquals(0x05, buffer.get());
assertEquals(0x06, buffer.get());
@@ -139,7 +120,6 @@ void testCopy4() {
assertEquals(0x08, buffer.get());
assertEquals(0x06, buffer.get()); // Copied byte
assertEquals(0x07, buffer.get()); // Copied byte
-
assertFalse(buffer.available());
assertEquals(-1, buffer.get());
}
@@ -147,17 +127,14 @@ void testCopy4() {
@Test
void testCopyCausingBufferOverflow() {
final CircularBuffer buffer = new CircularBuffer(4);
-
// Write some bytes
buffer.put(0x01);
buffer.put(0x02);
buffer.put(0x03);
buffer.put(0x04);
-
// Read some bytes to make space
assertEquals(0x01, buffer.get());
assertEquals(0x02, buffer.get());
-
try {
buffer.copy(4, 4); // Copying 4 bytes and write to the buffer that
will be full during copy
fail("Expected IllegalStateException for buffer overflow during
copy");
@@ -169,13 +146,11 @@ void testCopyCausingBufferOverflow() {
@Test
void testCopyDistanceExceedingBufferSize() {
final CircularBuffer buffer = new CircularBuffer(4);
-
// Write some bytes
buffer.put(0x01);
buffer.put(0x02);
buffer.put(0x03);
buffer.put(0x04);
-
try {
buffer.copy(5, 2); // Try to copy from a distance that is bigger
than the buffer size
fail("Expected IllegalArgumentException for distance exceeding
buffer size");
@@ -187,11 +162,9 @@ void testCopyDistanceExceedingBufferSize() {
@Test
void testCopyDistanceInvalid() {
final CircularBuffer buffer = new CircularBuffer(4);
-
// Write some bytes
buffer.put(0x01);
buffer.put(0x02);
-
try {
buffer.copy(0, 2); // Try to copy from distance 0
fail("Expected IllegalArgumentException for invalid distance");
@@ -203,13 +176,10 @@ void testCopyDistanceInvalid() {
@Test
void testCopyRunLengthEncoding1() {
final CircularBuffer buffer = new CircularBuffer(16);
-
// Write two bytes
buffer.put(0x01);
buffer.put(0x02);
-
buffer.copy(1, 8); // Copy last byte (0x02) eight times
-
// Read the buffer
assertEquals(0x01, buffer.get());
assertEquals(0x02, buffer.get());
@@ -221,7 +191,6 @@ void testCopyRunLengthEncoding1() {
assertEquals(0x02, buffer.get()); // Copied byte 6
assertEquals(0x02, buffer.get()); // Copied byte 7
assertEquals(0x02, buffer.get()); // Copied byte 8
-
assertFalse(buffer.available());
assertEquals(-1, buffer.get());
}
@@ -233,13 +202,10 @@ void testPutAndGet1() {
for (int i = 0; i < size / 2; i++) {
buffer.put(i);
}
-
assertTrue(buffer.available(), "available");
-
for (int i = 0; i < size / 2; i++) {
assertEquals(i, buffer.get(), "buffer[" + i + "]");
}
-
assertEquals(-1, buffer.get());
assertFalse(buffer.available(), "available");
}
@@ -247,18 +213,15 @@ void testPutAndGet1() {
@Test
void testPutAndGet2() {
final CircularBuffer buffer = new CircularBuffer(8);
-
// Nothing to read
assertFalse(buffer.available());
assertEquals(-1, buffer.get());
-
// Write a byte and read it
buffer.put(0x01);
assertTrue(buffer.available());
assertEquals(0x01, buffer.get());
assertFalse(buffer.available());
assertEquals(-1, buffer.get());
-
// Write multiple bytes and read them
buffer.put(0x02);
buffer.put(0x03);
@@ -274,16 +237,13 @@ void testPutAndGet2() {
@Test
void testPutAndGetWrappingAround() {
final CircularBuffer buffer = new CircularBuffer(4);
-
// Nothing to read
assertFalse(buffer.available());
assertEquals(-1, buffer.get());
-
// Write two bytes and read them in a loop making the buffer wrap
around several times
for (int i = 0; i < 8; i++) {
buffer.put(i * 2);
buffer.put(i * 2 + 1);
-
assertTrue(buffer.available());
assertEquals(i * 2, buffer.get());
assertEquals(i * 2 + 1, buffer.get());
@@ -295,13 +255,11 @@ void testPutAndGetWrappingAround() {
@Test
void testPutOverflow() {
final CircularBuffer buffer = new CircularBuffer(4);
-
// Write more bytes than the buffer can hold
buffer.put(0x01);
buffer.put(0x02);
buffer.put(0x03);
buffer.put(0x04);
-
try {
buffer.put(0x05);
fail("Expected IllegalStateException for buffer overflow");
diff --git
a/src/test/java/org/apache/commons/compress/compressors/lha/Lh4CompressorInputStreamTest.java
b/src/test/java/org/apache/commons/compress/archivers/lha/Lh4CompressorInputStreamTest.java
similarity index 90%
rename from
src/test/java/org/apache/commons/compress/compressors/lha/Lh4CompressorInputStreamTest.java
rename to
src/test/java/org/apache/commons/compress/archivers/lha/Lh4CompressorInputStreamTest.java
index 6c93da3a5..37045e23e 100644
---
a/src/test/java/org/apache/commons/compress/compressors/lha/Lh4CompressorInputStreamTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/lha/Lh4CompressorInputStreamTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -28,8 +28,6 @@
import java.nio.charset.StandardCharsets;
import org.apache.commons.compress.AbstractTest;
-import org.apache.commons.compress.archivers.lha.LhaArchiveEntry;
-import org.apache.commons.compress.archivers.lha.LhaArchiveInputStream;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
@@ -37,10 +35,10 @@
* Tests {@link LhStaticHuffmanCompressorInputStream} for LH4.
*/
class Lh4CompressorInputStreamTest extends AbstractTest {
+
@Test
void testConfiguration() throws IOException {
- try (LhStaticHuffmanCompressorInputStream in =
LhStaticHuffmanCompressorInputStream
- .lh4CompressorInputStream(new ByteArrayInputStream(new
byte[0]))) {
+ try (LhStaticHuffmanCompressorInputStream in =
LhStaticHuffmanCompressorInputStream.lh4CompressorInputStream(new
ByteArrayInputStream(new byte[0]))) {
assertEquals(12, in.getDictionaryBits());
assertEquals(4096, in.getDictionarySize());
assertEquals(4, in.getDistanceBits());
@@ -62,11 +60,9 @@ void testDecompress() throws IOException {
assertEquals(41583, entry.getCompressedSize());
assertEquals("-lh4-", entry.getCompressionMethod());
assertEquals(0x8c8a, entry.getCrcValue());
-
// Decompress entry
assertTrue(archive.canReadEntryData(entry));
final byte[] data = IOUtils.toByteArray(archive);
-
assertEquals(144060, data.length);
assertEquals("\nLorem ipsum", new String(data, 0, 12,
StandardCharsets.US_ASCII));
}
diff --git
a/src/test/java/org/apache/commons/compress/compressors/lha/Lh5CompressorInputStreamTest.java
b/src/test/java/org/apache/commons/compress/archivers/lha/Lh5CompressorInputStreamTest.java
similarity index 93%
rename from
src/test/java/org/apache/commons/compress/compressors/lha/Lh5CompressorInputStreamTest.java
rename to
src/test/java/org/apache/commons/compress/archivers/lha/Lh5CompressorInputStreamTest.java
index 77530db3c..73e297860 100644
---
a/src/test/java/org/apache/commons/compress/compressors/lha/Lh5CompressorInputStreamTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/lha/Lh5CompressorInputStreamTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -28,8 +28,6 @@
import java.nio.charset.StandardCharsets;
import org.apache.commons.compress.AbstractTest;
-import org.apache.commons.compress.archivers.lha.LhaArchiveEntry;
-import org.apache.commons.compress.archivers.lha.LhaArchiveInputStream;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
diff --git
a/src/test/java/org/apache/commons/compress/compressors/lha/Lh6CompressorInputStreamTest.java
b/src/test/java/org/apache/commons/compress/archivers/lha/Lh6CompressorInputStreamTest.java
similarity index 87%
rename from
src/test/java/org/apache/commons/compress/compressors/lha/Lh6CompressorInputStreamTest.java
rename to
src/test/java/org/apache/commons/compress/archivers/lha/Lh6CompressorInputStreamTest.java
index b68f8b449..dd5bef451 100644
---
a/src/test/java/org/apache/commons/compress/compressors/lha/Lh6CompressorInputStreamTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/lha/Lh6CompressorInputStreamTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -28,8 +28,6 @@
import java.nio.charset.StandardCharsets;
import org.apache.commons.compress.AbstractTest;
-import org.apache.commons.compress.archivers.lha.LhaArchiveEntry;
-import org.apache.commons.compress.archivers.lha.LhaArchiveInputStream;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
@@ -37,10 +35,10 @@
* Tests {@link LhStaticHuffmanCompressorInputStream} for LH6.
*/
class Lh6CompressorInputStreamTest extends AbstractTest {
+
@Test
void testConfiguration() throws IOException {
- try (LhStaticHuffmanCompressorInputStream in =
LhStaticHuffmanCompressorInputStream
- .lh6CompressorInputStream(new ByteArrayInputStream(new
byte[0]))) {
+ try (LhStaticHuffmanCompressorInputStream in =
LhStaticHuffmanCompressorInputStream.lh6CompressorInputStream(new
ByteArrayInputStream(new byte[0]))) {
assertEquals(15, in.getDictionaryBits());
assertEquals(32768, in.getDictionarySize());
assertEquals(5, in.getDistanceBits());
@@ -52,7 +50,7 @@ void testConfiguration() throws IOException {
@Test
void testDecompress() throws IOException {
- try (LhaArchiveInputStream archive = LhaArchiveInputStream
.builder().setInputStream(newInputStream("test-macos-l0-lh6.lha")).get()) {
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newInputStream("test-macos-l0-lh6.lha")).get())
{
// Check entry
final LhaArchiveEntry entry = archive.getNextEntry();
assertNotNull(entry);
@@ -61,11 +59,9 @@ void testDecompress() throws IOException {
assertEquals(38037, entry.getCompressedSize());
assertEquals("-lh6-", entry.getCompressionMethod());
assertEquals(0x8c8a, entry.getCrcValue());
-
// Decompress entry
assertTrue(archive.canReadEntryData(entry));
final byte[] data = IOUtils.toByteArray(archive);
-
assertEquals(144060, data.length);
assertEquals("\nLorem ipsum", new String(data, 0, 12,
StandardCharsets.US_ASCII));
}
diff --git
a/src/test/java/org/apache/commons/compress/compressors/lha/Lh7CompressorInputStreamTest.java
b/src/test/java/org/apache/commons/compress/archivers/lha/Lh7CompressorInputStreamTest.java
similarity index 90%
rename from
src/test/java/org/apache/commons/compress/compressors/lha/Lh7CompressorInputStreamTest.java
rename to
src/test/java/org/apache/commons/compress/archivers/lha/Lh7CompressorInputStreamTest.java
index 5f8e10bd6..1990606cc 100644
---
a/src/test/java/org/apache/commons/compress/compressors/lha/Lh7CompressorInputStreamTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/lha/Lh7CompressorInputStreamTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -28,8 +28,6 @@
import java.nio.charset.StandardCharsets;
import org.apache.commons.compress.AbstractTest;
-import org.apache.commons.compress.archivers.lha.LhaArchiveEntry;
-import org.apache.commons.compress.archivers.lha.LhaArchiveInputStream;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
@@ -40,8 +38,7 @@ class Lh7CompressorInputStreamTest extends AbstractTest {
@Test
void testConfiguration() throws IOException {
- try (LhStaticHuffmanCompressorInputStream in =
LhStaticHuffmanCompressorInputStream
- .lh7CompressorInputStream(new ByteArrayInputStream(new
byte[0]))) {
+ try (LhStaticHuffmanCompressorInputStream in =
LhStaticHuffmanCompressorInputStream.lh7CompressorInputStream(new
ByteArrayInputStream(new byte[0]))) {
assertEquals(16, in.getDictionaryBits());
assertEquals(65536, in.getDictionarySize());
assertEquals(5, in.getDistanceBits());
diff --git
a/src/test/java/org/apache/commons/compress/compressors/lha/LhStaticHuffmanCompressorInputStreamTest.java
b/src/test/java/org/apache/commons/compress/archivers/lha/LhStaticHuffmanCompressorInputStreamTest.java
similarity index 99%
rename from
src/test/java/org/apache/commons/compress/compressors/lha/LhStaticHuffmanCompressorInputStreamTest.java
rename to
src/test/java/org/apache/commons/compress/archivers/lha/LhStaticHuffmanCompressorInputStreamTest.java
index 7de34cddd..151ba655a 100644
---
a/src/test/java/org/apache/commons/compress/compressors/lha/LhStaticHuffmanCompressorInputStreamTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/lha/LhStaticHuffmanCompressorInputStreamTest.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.commons.compress.compressors.lha;
+package org.apache.commons.compress.archivers.lha;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
diff --git
a/src/test/java/org/apache/commons/compress/archivers/lha/LhaArchiveInputStreamTest.java
b/src/test/java/org/apache/commons/compress/archivers/lha/LhaArchiveInputStreamTest.java
index 3e43cac85..f38aab93e 100644
---
a/src/test/java/org/apache/commons/compress/archivers/lha/LhaArchiveInputStreamTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/lha/LhaArchiveInputStreamTest.java
@@ -47,6 +47,8 @@
import org.junit.jupiter.api.Test;
class LhaArchiveInputStreamTest extends AbstractTest {
+
+ // @formatter:off
private static final int[] VALID_HEADER_LEVEL_0_FILE = {
0x2b, 0x70, 0x2d, 0x6c, 0x68, 0x35, 0x2d, 0x34, 0x00, 0x00, 0x00,
0x39, 0x00, 0x00, 0x00, 0x4b, // |+p-lh5-4...9...K|
0x80, 0x03, 0x5b, 0x20, 0x00, 0x09, 0x74, 0x65, 0x73, 0x74, 0x31,
0x2e, 0x74, 0x78, 0x74, 0x96, // |..[ ..test1.txt.|
@@ -101,6 +103,7 @@ class LhaArchiveInputStreamTest extends AbstractTest {
0xc0, 0x3b, 0xae, 0xc0, 0xc4, 0xe6, 0x78, 0x28, 0xa1, 0x78, 0x75,
0x60, 0xd3, 0xaa, 0x76, 0x4e, // |.;....x(.xu`..vN|
0xbb, 0xc1, 0x7c, 0x1d, 0x9a, 0x63, 0xaf, 0xc3, 0xe4, 0xaf, 0x7c, 0x00
// |..|..c....|.|
};
+ // @formatter:on
private static byte[] toByteArray(final int... data) {
final byte[] bytes = new byte[data.length];
@@ -115,9 +118,8 @@ private static ByteBuffer toByteBuffer(final int... data) {
}
/**
- * The timestamp used in header level 0 and 1 entries has no time zone
information and is
- * converted in the system default time zone. This method converts the
date to UTC to verify
- * the timestamp in unit tests.
+ * The timestamp used in header level 0 and 1 entries has no time zone
information and is converted in the system default time zone. This method
converts
+ * the date to UTC to verify the timestamp in unit tests.
*
* @param date the date to convert
* @return a ZonedDateTime in UTC
@@ -136,10 +138,7 @@ private InputStream newEmptyInputStream() {
@Test
void testDecompressLh0() throws Exception {
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newInputStream("test-macos-l0.lha"))
- .get()) {
-
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newInputStream("test-macos-l0.lha")).get())
{
final List<String> files = new ArrayList<>();
files.add("dir1" + File.separatorChar);
files.add("dir1" + File.separatorChar + "dir1-1" +
File.separatorChar);
@@ -169,8 +168,8 @@ void testDecompressLh5() throws Exception {
}
/**
- * Test decompressing a file with lh5 compression that contains only one
characters and thus is
- * basically RLE encoded. The distance tree contains only one entry (root
node).
+ * Test decompressing a file with lh5 compression that contains only one
characters and thus is basically RLE encoded. The distance tree contains only
one
+ * entry (root node).
*/
@Test
void testDecompressLh5Rle() throws Exception {
@@ -211,13 +210,10 @@ void testDecompressLz4() throws Exception {
@Test
void testGetBytesReadReflectsDecompressedBytes() throws IOException {
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE)))
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE)))
.get()) {
-
final LhaArchiveEntry entry = archive.getNextEntry();
assertNotNull(entry);
-
final byte[] content = IOUtils.toByteArray(archive);
assertEquals(entry.getSize(), content.length);
assertEquals(entry.getSize(), archive.getBytesRead());
@@ -228,7 +224,6 @@ void testGetBytesReadReflectsDecompressedBytes() throws
IOException {
void testGetCompressionMethod() throws IOException {
assertEquals("-lh0-",
LhaArchiveInputStream.getCompressionMethod(ByteBuffer.wrap(toByteArray(0x00,
0x00, '-', 'l', 'h', '0', '-'))));
assertEquals("-lhd-",
LhaArchiveInputStream.getCompressionMethod(ByteBuffer.wrap(toByteArray(0x00,
0x00, '-', 'l', 'h', 'd', '-'))));
-
try {
LhaArchiveInputStream.getCompressionMethod(ByteBuffer.wrap(toByteArray(0x00,
0x00, '-', 'l', 'h', '0', 0xff)));
fail("Expected ArchiveException for invalid compression method");
@@ -285,7 +280,6 @@ void testGetPathnameUnixFileSeparatorCharDefaultEncoding()
throws IOException, U
assertEquals("folder/file.txt", getPathname(is, 'f', 'o', 'l',
'd', 'e', 'r', 0xff, 'f', 'i', 'l', 'e', '.', 't', 'x', 't'));
assertEquals("folder/file.txt", getPathname(is, 0xff, 'f', 'o',
'l', 'd', 'e', 'r', 0xff, 'f', 'i', 'l', 'e', '.', 't', 'x', 't'));
assertEquals("folder/file.txt", getPathname(is, '\\', 'f', 'o',
'l', 'd', 'e', 'r', '\\', 'f', 'i', 'l', 'e', '.', 't', 'x', 't'));
-
// Unicode replacement characters for unsupported characters
assertEquals("\uFFFD/\uFFFD/\uFFFD.txt", getPathname(is, 0xe5,
0xff, 0xe4, 0xff, 0xf6, '.', 't', 'x', 't'));
assertEquals("\uFFFD/\uFFFD/\uFFFD.txt", getPathname(is, 0xe5,
'\\', 0xe4, '\\', 0xf6, '.', 't', 'x', 't'));
@@ -294,12 +288,8 @@ void testGetPathnameUnixFileSeparatorCharDefaultEncoding()
throws IOException, U
@Test
void testGetPathnameUnixFileSeparatorCharIso88591() throws IOException,
UnsupportedEncodingException {
- try (LhaArchiveInputStream is = LhaArchiveInputStream.builder()
- .setInputStream(newEmptyInputStream())
- .setCharset(StandardCharsets.ISO_8859_1)
- .setFileSeparatorChar('/')
- .get()) {
-
+ try (LhaArchiveInputStream is =
LhaArchiveInputStream.builder().setInputStream(newEmptyInputStream()).setCharset(StandardCharsets.ISO_8859_1)
+ .setFileSeparatorChar('/').get()) {
assertEquals("\u00E5/\u00E4/\u00F6.txt", getPathname(is, 0xe5,
0xff, 0xe4, 0xff, 0xf6, '.', 't', 'x', 't'));
assertEquals("\u00E5/\u00E4/\u00F6.txt", getPathname(is, 0xe5,
'\\', 0xe4, '\\', 0xf6, '.', 't', 'x', 't'));
}
@@ -312,7 +302,6 @@ void
testGetPathnameWindowsFileSeparatorCharDefaultEncoding() throws IOException
assertEquals("folder\\file.txt", getPathname(is, 'f', 'o', 'l',
'd', 'e', 'r', 0xff, 'f', 'i', 'l', 'e', '.', 't', 'x', 't'));
assertEquals("folder\\file.txt", getPathname(is, 0xff, 'f', 'o',
'l', 'd', 'e', 'r', 0xff, 'f', 'i', 'l', 'e', '.', 't', 'x', 't'));
assertEquals("folder\\file.txt", getPathname(is, '\\', 'f', 'o',
'l', 'd', 'e', 'r', '\\', 'f', 'i', 'l', 'e', '.', 't', 'x', 't'));
-
// Unicode replacement characters for unsupported characters
assertEquals("\uFFFD\\\uFFFD\\\uFFFD.txt", getPathname(is, 0xe5,
0xff, 0xe4, 0xff, 0xf6, '.', 't', 'x', 't'));
assertEquals("\uFFFD\\\uFFFD\\\uFFFD.txt", getPathname(is, 0xe5,
'\\', 0xe4, '\\', 0xf6, '.', 't', 'x', 't'));
@@ -321,12 +310,8 @@ void
testGetPathnameWindowsFileSeparatorCharDefaultEncoding() throws IOException
@Test
void testGetPathnameWindowsFileSeparatorCharIso88591() throws IOException,
UnsupportedEncodingException {
- try (LhaArchiveInputStream is = LhaArchiveInputStream.builder()
- .setInputStream(newEmptyInputStream())
- .setCharset(StandardCharsets.ISO_8859_1)
- .setFileSeparatorChar('\\')
- .get()) {
-
+ try (LhaArchiveInputStream is =
LhaArchiveInputStream.builder().setInputStream(newEmptyInputStream()).setCharset(StandardCharsets.ISO_8859_1)
+ .setFileSeparatorChar('\\').get()) {
assertEquals("\u00E5\\\u00E4\\\u00F6.txt", getPathname(is, 0xe5,
0xff, 0xe4, 0xff, 0xf6, '.', 't', 'x', 't'));
assertEquals("\u00E5\\\u00E4\\\u00F6.txt", getPathname(is, 0xe5,
'\\', 0xe4, '\\', 0xf6, '.', 't', 'x', 't'));
}
@@ -335,9 +320,7 @@ void testGetPathnameWindowsFileSeparatorCharIso88591()
throws IOException, Unsup
@Test
void testInvalidHeaderLevel() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_0_FILE);
-
data[20] = 4; // Change the header level to an invalid value
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid header level");
@@ -349,9 +332,7 @@ void testInvalidHeaderLevel() throws IOException {
@Test
void testInvalidHeaderLevel0Checksum() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_0_FILE);
-
data[1] = 0x55; // Change the second byte to an invalid header checksum
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid header checksum");
@@ -363,9 +344,7 @@ void testInvalidHeaderLevel0Checksum() throws IOException {
@Test
void testInvalidHeaderLevel0FilenameLength() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_0_FILE);
-
data[21] = 22; // Change the length of the filename
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid filename");
@@ -377,9 +356,7 @@ void testInvalidHeaderLevel0FilenameLength() throws
IOException {
@Test
void testInvalidHeaderLevel0Length() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_0_FILE);
-
data[0] = 0x10; // Change the first byte to an invalid length
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid header length");
@@ -391,9 +368,7 @@ void testInvalidHeaderLevel0Length() throws IOException {
@Test
void testInvalidHeaderLevel1Checksum() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_1_FILE);
-
data[1] = 0x55; // Change the second byte to an invalid header checksum
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid header checksum");
@@ -405,11 +380,9 @@ void testInvalidHeaderLevel1Checksum() throws IOException {
@Test
void testInvalidHeaderLevel1Crc() throws IOException {
final byte[] data =
toByteArray(VALID_HEADER_LEVEL_1_FILE_MSDOS_WITH_CHECKSUM_AND_CRC);
-
// Change header CRC to an invalid value
data[41] = 0x33;
data[42] = 0x22;
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid header checksum");
@@ -421,9 +394,7 @@ void testInvalidHeaderLevel1Crc() throws IOException {
@Test
void testInvalidHeaderLevel1FilenameLength() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_1_FILE);
-
data[21] = 10; // Change the length of the filename
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid filename");
@@ -435,9 +406,7 @@ void testInvalidHeaderLevel1FilenameLength() throws
IOException {
@Test
void testInvalidHeaderLevel1Length() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_1_FILE);
-
data[0] = 0x10; // Change the first byte to an invalid length
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid header length");
@@ -449,14 +418,12 @@ void testInvalidHeaderLevel1Length() throws IOException {
@Test
void testInvalidHeaderLevel1NegativeCompressedSize() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_1_FILE);
-
// Zero out the 4-byte skip size field (offset 7) so that subtracting
the extended header
// sizes underflows to a negative compressed size.
data[7] = 0x00;
data[8] = 0x00;
data[9] = 0x00;
data[10] = 0x00;
-
// Recompute the base header checksum so the header passes checksum
validation and reaches
// the compressed size check.
final int baseHeaderSize = (data[0] & 0xff) + 2;
@@ -465,7 +432,6 @@ void testInvalidHeaderLevel1NegativeCompressedSize() throws
IOException {
sum += data[i] & 0xff;
}
data[1] = (byte) (sum & 0xff);
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for negative compressed size");
@@ -477,11 +443,9 @@ void testInvalidHeaderLevel1NegativeCompressedSize()
throws IOException {
@Test
void testInvalidHeaderLevel2Checksum() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_2_FILE);
-
// Change header CRC to an invalid value
data[27] = 0x33;
data[28] = 0x22;
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid header checksum");
@@ -493,9 +457,7 @@ void testInvalidHeaderLevel2Checksum() throws IOException {
@Test
void testInvalidHeaderLevel2Length() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_2_FILE);
-
data[0] = 25; // Change the first byte to an invalid length
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid header length");
@@ -507,7 +469,6 @@ void testInvalidHeaderLevel2Length() throws IOException {
@Test
void testInvalidHeaderLevelLength() throws IOException {
final byte[] data = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
archive.getNextEntry();
fail("Expected ArchiveException for invalid header length");
@@ -519,20 +480,16 @@ void testInvalidHeaderLevelLength() throws IOException {
@Test
void testMatches() {
byte[] data;
-
assertTrue(LhaArchiveInputStream.matches(toByteArray(VALID_HEADER_LEVEL_0_FILE),
VALID_HEADER_LEVEL_0_FILE.length));
assertTrue(LhaArchiveInputStream.matches(toByteArray(VALID_HEADER_LEVEL_1_FILE),
VALID_HEADER_LEVEL_1_FILE.length));
assertTrue(LhaArchiveInputStream.matches(toByteArray(VALID_HEADER_LEVEL_2_FILE),
VALID_HEADER_LEVEL_2_FILE.length));
-
// Header to short
data = toByteArray(0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09);
assertFalse(LhaArchiveInputStream.matches(data, data.length));
-
// Change the header level to an invalid value
data = toByteArray(VALID_HEADER_LEVEL_0_FILE);
data[20] = 3;
assertFalse(LhaArchiveInputStream.matches(data, data.length));
-
// Change the compression method to an invalid value
data = toByteArray(VALID_HEADER_LEVEL_0_FILE);
data[6] = 0x08;
@@ -546,7 +503,6 @@ void testParseExtendedHeaderCommon() throws IOException {
final LhaArchiveEntry.Builder entryBuilder =
LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x00, 0x22, 0x33, 0x00,
0x00), entryBuilder);
assertEquals(0x3322, entryBuilder.get().getHeaderCrc());
-
// Invalid length
try {
archive.parseExtendedHeader(toByteBuffer(0x00, 0x22, 0x00,
0x00), entryBuilder);
@@ -559,16 +515,11 @@ void testParseExtendedHeaderCommon() throws IOException {
@Test
void testParseExtendedHeaderDirectoryName() throws IOException {
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newEmptyInputStream())
- .setFileSeparatorChar('/')
- .get()) {
-
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newEmptyInputStream()).setFileSeparatorChar('/').get())
{
// Valid
final LhaArchiveEntry.Builder entryBuilder =
LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x02, 'd', 'i', 'r', '1',
0xff, 0x00, 0x00), entryBuilder);
assertEquals("dir1/", entryBuilder.get().getName());
-
// Invalid length
try {
archive.parseExtendedHeader(toByteBuffer(0x02, 0x00),
entryBuilder);
@@ -586,7 +537,6 @@ void testParseExtendedHeaderFilename() throws IOException {
final LhaArchiveEntry.Builder entryBuilder =
LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x01, 't', 'e', 's', 't',
'.', 't', 'x', 't', 0x00, 0x00), entryBuilder);
assertEquals("test.txt", entryBuilder.get().getName());
-
// Invalid length
try {
archive.parseExtendedHeader(toByteBuffer(0x01, 0x00),
entryBuilder);
@@ -599,37 +549,28 @@ void testParseExtendedHeaderFilename() throws IOException
{
@Test
void testParseExtendedHeaderFilenameAndDirectoryName() throws IOException {
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newEmptyInputStream())
- .setFileSeparatorChar('/')
- .get()) {
-
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newEmptyInputStream()).setFileSeparatorChar('/').get())
{
LhaArchiveEntry.Builder entryBuilder;
-
// Test filename and directory name order
entryBuilder = LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x01, 't', 'e', 's', 't',
'.', 't', 'x', 't', 0x00, 0x00), entryBuilder);
archive.parseExtendedHeader(toByteBuffer(0x02, 'd', 'i', 'r', '1',
0xff, 0x00, 0x00), entryBuilder);
assertEquals("dir1/test.txt", entryBuilder.get().getName());
-
// Test filename and directory name order, no trailing slash
entryBuilder = LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x01, 't', 'e', 's', 't',
'.', 't', 'x', 't', 0x00, 0x00), entryBuilder);
archive.parseExtendedHeader(toByteBuffer(0x02, 'd', 'i', 'r', '1',
0x00, 0x00), entryBuilder);
assertEquals("dir1/test.txt", entryBuilder.get().getName());
-
// Test directory name and filename order
entryBuilder = LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x02, 'd', 'i', 'r', '1',
0xff, 0x00, 0x00), entryBuilder);
archive.parseExtendedHeader(toByteBuffer(0x01, 't', 'e', 's', 't',
'.', 't', 'x', 't', 0x00, 0x00), entryBuilder);
assertEquals("dir1/test.txt", entryBuilder.get().getName());
-
// Test directory name and filename order, no trailing slash
entryBuilder = LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x02, 'd', 'i', 'r', '1',
0x00, 0x00), entryBuilder);
archive.parseExtendedHeader(toByteBuffer(0x01, 't', 'e', 's', 't',
'.', 't', 'x', 't', 0x00, 0x00), entryBuilder);
assertEquals("dir1/test.txt", entryBuilder.get().getName());
-
// Test empty directory name, no trailing slash
entryBuilder = LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x02, 0x00, 0x00),
entryBuilder);
@@ -645,7 +586,6 @@ void testParseExtendedHeaderMSdosFileAttributes() throws
IOException {
final LhaArchiveEntry.Builder entryBuilder =
LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x40, 0x10, 0x00, 0x00,
0x00), entryBuilder);
assertEquals(0x10, entryBuilder.get().getMsdosFileAttributes());
-
// Invalid length
try {
archive.parseExtendedHeader(toByteBuffer(0x40, 0x10, 0x00,
0x00), entryBuilder);
@@ -677,7 +617,6 @@ void testParseExtendedHeaderUnixPermission() throws
IOException {
archive.parseExtendedHeader(toByteBuffer(0x50, 0xa4, 0x81, 0x00,
0x00), entryBuilder);
assertEquals(0x81a4, entryBuilder.get().getUnixPermissionMode());
assertEquals(0100644, entryBuilder.get().getUnixPermissionMode());
-
// Invalid length
try {
archive.parseExtendedHeader(toByteBuffer(0x50, 0xa4, 0x00,
0x00), entryBuilder);
@@ -695,7 +634,6 @@ void testParseExtendedHeaderUnixTimestamp() throws
IOException {
final LhaArchiveEntry.Builder entryBuilder =
LhaArchiveEntry.builder();
archive.parseExtendedHeader(toByteBuffer(0x54, 0x5c, 0x73, 0x9c,
0x68, 0x00, 0x00), entryBuilder);
assertEquals(0x689c735cL,
entryBuilder.get().getLastModifiedDate().getTime() / 1000);
-
// Invalid length
try {
archive.parseExtendedHeader(toByteBuffer(0x54, 0x5c, 0x73,
0x9c, 0x00, 0x00), entryBuilder);
@@ -714,7 +652,6 @@ void testParseExtendedHeaderUnixUidGid() throws IOException
{
archive.parseExtendedHeader(toByteBuffer(0x51, 0x14, 0x00, 0xf5,
0x01, 0x00, 0x00), entryBuilder);
assertEquals(0x0014, entryBuilder.get().getUnixGroupId());
assertEquals(0x01f5, entryBuilder.get().getUnixUserId());
-
// Invalid length
try {
archive.parseExtendedHeader(toByteBuffer(0x51, 0x14, 0x00,
0xf5, 0x00, 0x00), entryBuilder);
@@ -727,10 +664,8 @@ void testParseExtendedHeaderUnixUidGid() throws
IOException {
@Test
void testParseHeaderLevel0File() throws IOException {
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE)))
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE)))
.get()) {
-
// Entry should be parsed correctly
final LhaArchiveEntry entry = archive.getNextEntry();
assertNotNull(entry);
@@ -748,7 +683,6 @@ void testParseHeaderLevel0File() throws IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -757,15 +691,11 @@ void testParseHeaderLevel0File() throws IOException {
@Test
void testParseHeaderLevel0FileMacosUtf8() throws IOException {
try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE_MACOS_UTF8)))
- .setCharset(StandardCharsets.UTF_8)
- .get()) {
-
+ .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE_MACOS_UTF8))).setCharset(StandardCharsets.UTF_8).get())
{
// Entry name should be parsed correctly
final LhaArchiveEntry entry = archive.getNextEntry();
assertNotNull(entry);
assertEquals("test-\u00E5\u00E4\u00F6.txt", entry.getName());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -774,15 +704,12 @@ void testParseHeaderLevel0FileMacosUtf8() throws
IOException {
@Test
void testParseHeaderLevel0FileMsdosIso88591() throws IOException {
try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE_MSDOS_ISO8859_1)))
- .setCharset(StandardCharsets.ISO_8859_1)
+ .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE_MSDOS_ISO8859_1))).setCharset(StandardCharsets.ISO_8859_1)
.get()) {
-
// Entry name should be parsed correctly
final LhaArchiveEntry entry = archive.getNextEntry();
assertNotNull(entry);
assertEquals("test-\u00E5\u00E4\u00F6.txt", entry.getName());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -791,14 +718,11 @@ void testParseHeaderLevel0FileMsdosIso88591() throws
IOException {
@Test
void testParseHeaderLevel0FileMsdosIso88591DefaultEncoding() throws
IOException {
try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE_MSDOS_ISO8859_1)))
- .get()) {
-
+ .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_0_FILE_MSDOS_ISO8859_1))).get())
{
// First entry should be with replacement characters for
unsupported characters
final LhaArchiveEntry entry = archive.getNextEntry();
assertNotNull(entry);
assertEquals("test-\uFFFD\uFFFD\uFFFD.txt", entry.getName()); //
Unicode replacement characters for unsupported characters
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -807,13 +731,9 @@ void
testParseHeaderLevel0FileMsdosIso88591DefaultEncoding() throws IOException
@Test
void testParseHeaderLevel0FileWithFoldersMacos() throws IOException {
// The lha file was generated by LHa for UNIX version 1.14i-ac20211125
for Macos
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newInputStream("test-macos-l0.lha"))
- .setFileSeparatorChar('/')
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newInputStream("test-macos-l0.lha")).setFileSeparatorChar('/')
.get()) {
-
LhaArchiveEntry entry;
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -831,7 +751,6 @@ void testParseHeaderLevel0FileWithFoldersMacos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -849,7 +768,6 @@ void testParseHeaderLevel0FileWithFoldersMacos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -867,7 +785,6 @@ void testParseHeaderLevel0FileWithFoldersMacos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -885,7 +802,6 @@ void testParseHeaderLevel0FileWithFoldersMacos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -903,7 +819,6 @@ void testParseHeaderLevel0FileWithFoldersMacos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -912,12 +827,9 @@ void testParseHeaderLevel0FileWithFoldersMacos() throws
IOException {
@Test
void testParseHeaderLevel0FileWithFoldersMsdos() throws IOException {
// The lha file was generated by LHA32 v2.67.00 for Windows
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newInputStream("test-msdos-l0.lha"))
- .setFileSeparatorChar('/')
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newInputStream("test-msdos-l0.lha")).setFileSeparatorChar('/')
.get()) {
LhaArchiveEntry entry;
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -935,7 +847,6 @@ void testParseHeaderLevel0FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -953,7 +864,6 @@ void testParseHeaderLevel0FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -971,7 +881,6 @@ void testParseHeaderLevel0FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -989,7 +898,6 @@ void testParseHeaderLevel0FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1007,7 +915,6 @@ void testParseHeaderLevel0FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1034,7 +941,6 @@ void testParseHeaderLevel0Larc() throws IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1042,10 +948,8 @@ void testParseHeaderLevel0Larc() throws IOException {
@Test
void testParseHeaderLevel1File() throws IOException {
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_1_FILE)))
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_1_FILE)))
.get()) {
-
// Entry should be parsed correctly
final LhaArchiveEntry entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1063,7 +967,6 @@ void testParseHeaderLevel1File() throws IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1073,12 +976,8 @@ void testParseHeaderLevel1File() throws IOException {
void testParseHeaderLevel1FileMsdosChecksumAndCrc() throws IOException {
// The lha file was generated by LHA32 v2.67.00 for Windows
try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_1_FILE_MSDOS_WITH_CHECKSUM_AND_CRC)))
- .setFileSeparatorChar('/')
- .get()) {
-
+ .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_1_FILE_MSDOS_WITH_CHECKSUM_AND_CRC))).setFileSeparatorChar('/').get())
{
LhaArchiveEntry entry;
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1096,7 +995,6 @@ void testParseHeaderLevel1FileMsdosChecksumAndCrc() throws
IOException {
assertNull(entry.getUnixUserId());
assertEquals(0x0010, entry.getMsdosFileAttributes());
assertEquals(0xb772, entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1114,7 +1012,6 @@ void testParseHeaderLevel1FileMsdosChecksumAndCrc()
throws IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0x9b71, entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1123,13 +1020,9 @@ void testParseHeaderLevel1FileMsdosChecksumAndCrc()
throws IOException {
@Test
void testParseHeaderLevel1FileWithFoldersMacos() throws IOException {
// The lha file was generated by LHa for UNIX version 1.14i-ac20211125
for Macos
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newInputStream("test-macos-l1.lha"))
- .setFileSeparatorChar('/')
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newInputStream("test-macos-l1.lha")).setFileSeparatorChar('/')
.get()) {
-
LhaArchiveEntry entry;
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1147,7 +1040,6 @@ void testParseHeaderLevel1FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1165,7 +1057,6 @@ void testParseHeaderLevel1FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1183,7 +1074,6 @@ void testParseHeaderLevel1FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1201,7 +1091,6 @@ void testParseHeaderLevel1FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1219,7 +1108,6 @@ void testParseHeaderLevel1FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertNull(entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1228,13 +1116,9 @@ void testParseHeaderLevel1FileWithFoldersMacos() throws
IOException {
@Test
void testParseHeaderLevel1FileWithFoldersMsdos() throws IOException {
// The lha file was generated by LHA32 v2.67.00 for Windows
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newInputStream("test-msdos-l1.lha"))
- .setFileSeparatorChar('/')
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newInputStream("test-msdos-l1.lha")).setFileSeparatorChar('/')
.get()) {
-
LhaArchiveEntry entry;
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1252,7 +1136,6 @@ void testParseHeaderLevel1FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertEquals(0x0010, entry.getMsdosFileAttributes());
assertEquals(0xd458, entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1270,7 +1153,6 @@ void testParseHeaderLevel1FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertEquals(0x0010, entry.getMsdosFileAttributes());
assertEquals(0x40de, entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1288,7 +1170,6 @@ void testParseHeaderLevel1FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0x34b0, entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1306,7 +1187,6 @@ void testParseHeaderLevel1FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertEquals(0x0010, entry.getMsdosFileAttributes());
assertEquals(0x21b2, entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1324,7 +1204,6 @@ void testParseHeaderLevel1FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0x8f0c, entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1332,11 +1211,8 @@ void testParseHeaderLevel1FileWithFoldersMsdos() throws
IOException {
@Test
void testParseHeaderLevel2File() throws IOException {
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_2_FILE)))
- .setFileSeparatorChar('/')
- .get()) {
-
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(toByteArray(VALID_HEADER_LEVEL_2_FILE)))
+ .setFileSeparatorChar('/').get()) {
// Entry should be parsed correctly
final LhaArchiveEntry entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1354,7 +1230,6 @@ void testParseHeaderLevel2File() throws IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0x01a5, entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1363,15 +1238,10 @@ void testParseHeaderLevel2File() throws IOException {
@Test
void testParseHeaderLevel2FileWithFoldersAmiga() throws IOException {
// The lha file was generated by LhA 2.15 on Amiga
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newInputStream("test-amiga-l2.lha"))
- .setFileSeparatorChar('/')
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newInputStream("test-amiga-l2.lha")).setFileSeparatorChar('/')
.get()) {
-
LhaArchiveEntry entry;
-
// No -lhd- directory entries in Amiga LHA files, so we expect
only file entries
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1389,7 +1259,6 @@ void testParseHeaderLevel2FileWithFoldersAmiga() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0xe1a5, entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1407,7 +1276,6 @@ void testParseHeaderLevel2FileWithFoldersAmiga() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0xd6b0, entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1416,13 +1284,9 @@ void testParseHeaderLevel2FileWithFoldersAmiga() throws
IOException {
@Test
void testParseHeaderLevel2FileWithFoldersMacos() throws IOException {
// The lha file was generated by LHa for UNIX version 1.14i-ac20211125
for Macos
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newInputStream("test-macos-l2.lha"))
- .setFileSeparatorChar('/')
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newInputStream("test-macos-l2.lha")).setFileSeparatorChar('/')
.get()) {
-
LhaArchiveEntry entry;
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1440,7 +1304,6 @@ void testParseHeaderLevel2FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0xf3f7, entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1458,7 +1321,6 @@ void testParseHeaderLevel2FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0x50d3, entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1476,7 +1338,6 @@ void testParseHeaderLevel2FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0x589e, entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1494,7 +1355,6 @@ void testParseHeaderLevel2FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0x126d, entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1512,7 +1372,6 @@ void testParseHeaderLevel2FileWithFoldersMacos() throws
IOException {
assertEquals(501, entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0xdbdd, entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1521,13 +1380,9 @@ void testParseHeaderLevel2FileWithFoldersMacos() throws
IOException {
@Test
void testParseHeaderLevel2FileWithFoldersMsdos() throws IOException {
// The lha file was generated by LHA32 v2.67.00 for Windows
- try (LhaArchiveInputStream archive = LhaArchiveInputStream.builder()
- .setInputStream(newInputStream("test-msdos-l2.lha"))
- .setFileSeparatorChar('/')
+ try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(newInputStream("test-msdos-l2.lha")).setFileSeparatorChar('/')
.get()) {
-
LhaArchiveEntry entry;
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1545,7 +1400,6 @@ void testParseHeaderLevel2FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertEquals(0x0010, entry.getMsdosFileAttributes());
assertEquals(0x496a, entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1563,7 +1417,6 @@ void testParseHeaderLevel2FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertEquals(0x0010, entry.getMsdosFileAttributes());
assertEquals(0xebe7, entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1581,7 +1434,6 @@ void testParseHeaderLevel2FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0x214a, entry.getHeaderCrc());
-
// Check directory entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1599,7 +1451,6 @@ void testParseHeaderLevel2FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertEquals(0x0010, entry.getMsdosFileAttributes());
assertEquals(0x74ca, entry.getHeaderCrc());
-
// Check file entry
entry = archive.getNextEntry();
assertNotNull(entry);
@@ -1617,7 +1468,6 @@ void testParseHeaderLevel2FileWithFoldersMsdos() throws
IOException {
assertNull(entry.getUnixUserId());
assertNull(entry.getMsdosFileAttributes());
assertEquals(0x165f, entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1644,7 +1494,6 @@ void testParseHeaderLevel2FileWithMsdosAttributes()
throws IOException {
assertNull(entry.getUnixUserId());
assertEquals(0x0021, entry.getMsdosFileAttributes());
assertEquals(0x14bb, entry.getHeaderCrc());
-
// No more entries expected
assertNull(archive.getNextEntry());
}
@@ -1653,7 +1502,6 @@ void testParseHeaderLevel2FileWithMsdosAttributes()
throws IOException {
@Test
void testReadDataBeforeEntry() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_0_FILE);
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
try {
IOUtils.toByteArray(archive);
@@ -1667,17 +1515,13 @@ void testReadDataBeforeEntry() throws IOException {
@Test
void testUnsupportedCompressionMethod() throws IOException {
final byte[] data = toByteArray(VALID_HEADER_LEVEL_0_FILE);
-
data[1] = (byte) 0x9c; // Change the header checksum
data[5] = 'a'; // Change the compression method to an unsupported value
-
try (LhaArchiveInputStream archive =
LhaArchiveInputStream.builder().setInputStream(new
ByteArrayInputStream(data)).get()) {
final LhaArchiveEntry entry = archive.getNextEntry();
assertNotNull(entry);
assertEquals("-lha-", entry.getCompressionMethod());
-
assertFalse(archive.canReadEntryData(entry));
-
try {
IOUtils.toByteArray(archive);
fail("Expected ArchiveException for unsupported compression
method");