You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/11/15 20:23:59 UTC
(commons-compress) branch master updated: Fix Checkstyle in tests
This is an automated email from the ASF dual-hosted git repository.
ggregory 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 8d21ef6b2 Fix Checkstyle in tests
8d21ef6b2 is described below
commit 8d21ef6b25e135c9b7fc501883c9d6d68afe37c2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Nov 15 15:23:48 2023 -0500
Fix Checkstyle in tests
---
pom.xml | 2 +-
.../org/apache/commons/compress/AbstractTest.java | 27 +-
.../apache/commons/compress/ArchiveReadTest.java | 7 +-
.../apache/commons/compress/ArchiveUtilsTest.java | 12 +-
.../org/apache/commons/compress/ChainingTest.java | 4 +-
.../org/apache/commons/compress/IOMethodsTest.java | 3 +-
.../org/apache/commons/compress/OsgiITest.java | 24 +-
.../apache/commons/compress/archivers/ArTest.java | 6 +-
.../archivers/ArchiveServiceLoaderTest.java | 2 +-
.../archivers/ArchiveStreamFactoryTest.java | 169 +-
.../commons/compress/archivers/CpioTest.java | 3 +-
.../compress/archivers/ExceptionMessageTest.java | 14 +-
.../apache/commons/compress/archivers/JarTest.java | 3 +-
.../commons/compress/archivers/LongPathTest.java | 11 +-
.../compress/archivers/LongSymLinkTest.java | 8 +-
.../apache/commons/compress/archivers/TarTest.java | 52 +-
.../archivers/TestArchiveStreamProvider.java | 8 +-
.../apache/commons/compress/archivers/ZipTest.java | 60 +-
.../archivers/ar/ArArchiveInputStreamTest.java | 25 +-
.../archivers/arj/ArjArchiveInputStreamTest.java | 10 +-
.../compress/archivers/arj/CoverageTest.java | 2 +
.../archivers/cpio/CpioArchiveInputStreamTest.java | 12 +-
.../cpio/CpioArchiveOutputStreamTest.java | 2 +-
.../compress/archivers/cpio/CpioArchiveTest.java | 2 +-
.../compress/archivers/cpio/CpioUtilTest.java | 8 +-
.../archivers/dump/DumpArchiveEntryTest.java | 6 +-
.../archivers/dump/DumpArchiveInputStreamTest.java | 12 +-
.../archivers/dump/DumpArchiveUtilTest.java | 18 +-
.../examples/ParameterizedArchiverTest.java | 19 +-
.../archivers/examples/SevenZArchiverTest.java | 9 +-
.../compress/archivers/jar/ExpandApkTest.java | 5 +-
.../archivers/jar/JarArchiveOutputStreamTest.java | 2 +-
.../archivers/memory/MemoryArchiveInputStream.java | 2 +-
.../compress/archivers/sevenz/FolderTest.java | 8 +-
.../archivers/sevenz/SevenZArchiveEntryTest.java | 1 -
.../compress/archivers/sevenz/SevenZFileTest.java | 26 +-
.../archivers/sevenz/SevenZNativeHeapTest.java | 13 +-
.../archivers/sevenz/SevenZOutputFileTest.java | 4 +-
.../commons/compress/archivers/tar/BigFilesIT.java | 12 +-
.../compress/archivers/tar/FileTimesIT.java | 84 +-
.../compress/archivers/tar/SparseFilesTest.java | 10 +-
.../archivers/tar/TarArchiveEntryTest.java | 57 +-
.../archivers/tar/TarArchiveInputStreamTest.java | 66 +-
.../archivers/tar/TarArchiveOutputStreamTest.java | 9 +-
.../compress/archivers/tar/TarFileTest.java | 68 +-
.../commons/compress/archivers/tar/TarLister.java | 11 +-
.../archivers/tar/TarMemoryFileSystemTest.java | 16 +-
.../compress/archivers/tar/TarUtilsTest.java | 337 +-
.../compress/archivers/zip/AsiExtraFieldTest.java | 61 +-
...fd9eaeb86cda597d07b5e3c3d81363633c2da_Test.java | 2 +-
.../archivers/zip/EncryptedArchiveTest.java | 11 +-
.../archivers/zip/ExtraFieldUtilsTest.java | 80 +-
.../archivers/zip/GeneralPurposeBitTest.java | 38 +-
.../commons/compress/archivers/zip/Lister.java | 28 +-
.../archivers/zip/Maven221MultiVolumeTest.java | 27 +-
.../zip/ParallelScatterZipCreatorTest.java | 4 +-
.../compress/archivers/zip/ScatterSample.java | 5 +-
.../compress/archivers/zip/ScatterSampleTest.java | 8 +-
.../archivers/zip/X5455_ExtendedTimestampTest.java | 138 +-
.../compress/archivers/zip/X7875_NewUnixTest.java | 70 +-
.../Zip64ExtendedInformationExtraFieldTest.java | 49 +-
.../compress/archivers/zip/Zip64SupportIT.java | 3438 +++++++++-----------
.../archivers/zip/ZipArchiveEntryTest.java | 62 +-
.../archivers/zip/ZipArchiveInputStreamTest.java | 25 +-
.../archivers/zip/ZipClassCoverageTest.java | 7 +-
.../archivers/zip/ZipEightByteIntegerTest.java | 18 +-
.../compress/archivers/zip/ZipEncodingTest.java | 83 +-
.../zip/ZipFileIgnoringLocalFileHeaderTest.java | 11 +-
.../compress/archivers/zip/ZipFileTest.java | 14 +-
.../compress/archivers/zip/ZipLongTest.java | 2 +-
.../archivers/zip/ZipMemoryFileSystemTest.java | 33 +-
.../compress/archivers/zip/ZipShortTest.java | 6 +-
.../compress/archivers/zip/ZipUtilTest.java | 64 +-
.../compress/changes/ChangeSetRawTypesTest.java | 4 +-
.../compress/changes/ChangeSetSafeTypesTest.java | 4 +-
.../commons/compress/compressors/BZip2Test.java | 7 +-
.../compressors/CompressorServiceLoaderTest.java | 4 +-
.../CompressorStreamFactoryRoundtripTest.java | 2 +-
.../commons/compress/compressors/DeflateTest.java | 2 +-
.../compress/compressors/DetectCompressorTest.java | 11 +-
.../compress/compressors/FramedSnappyTest.java | 23 +-
.../commons/compress/compressors/GZipTest.java | 21 +-
.../commons/compress/compressors/LZMATest.java | 7 +-
.../commons/compress/compressors/Pack200Test.java | 23 +-
.../compressors/TestCompressorStreamProvider.java | 7 +-
.../brotli/BrotliCompressorInputStreamTest.java | 10 +-
.../bzip2/BZip2CompressorInputStreamTest.java | 51 +-
.../bzip2/BZip2NSelectorsOverflowTest.java | 4 +-
.../compress/compressors/bzip2/BlockSortTest.java | 86 +-
.../bzip2/PythonTruncatedBzip2Test.java | 9 +-
.../deflate/DeflateCompressorOutputStreamTest.java | 4 +-
.../compressors/deflate64/Deflate64BugsTest.java | 2 +-
.../Deflate64CompressorInputStreamTest.java | 148 +-
.../compressors/deflate64/HuffmanDecoderTest.java | 23 +-
.../gzip/GzipCompressorOutputStreamTest.java | 3 +-
.../lz4/BlockLZ4CompressorOutputStreamTest.java | 46 +-
.../lz4/BlockLZ4CompressorRoundtripTest.java | 6 +-
.../lz4/CompressionDegradationTest.java | 2 +-
.../lz4/FramedLZ4CompressorInputStreamTest.java | 356 +-
.../lz4/FramedLZ4CompressorRoundtripTest.java | 19 +-
.../compress/compressors/lz4/XXHash32Test.java | 7 +-
.../AbstractLZ77CompressorInputStreamTest.java | 4 +-
.../lz77support/LZ77CompressorTest.java | 76 +-
.../compressors/lz77support/ParametersTest.java | 20 +-
.../compress/compressors/lzma/LZMAUtilsTest.java | 4 +-
.../FramedSnappyCompressorInputStreamTest.java | 8 +-
.../compressors/snappy/SnappyRoundtripTest.java | 63 +-
.../xz/XZCompressorOutputStreamTest.java | 5 +-
.../compress/compressors/xz/XZUtilsTest.java | 4 +-
.../compressors/z/ZCompressorInputStreamTest.java | 3 +-
.../compressors/zstandard/ZstdRoundtripTest.java | 8 +-
.../compressors/zstandard/ZstdUtilsTest.java | 8 +-
.../harmony/pack200/tests/ArchiveTest.java | 2 +-
.../harmony/pack200/tests/BHSDCodecTest.java | 13 +-
.../harmony/pack200/tests/CodecEncodingTest.java | 174 +-
.../compress/harmony/pack200/tests/CodecTest.java | 61 +-
.../harmony/pack200/tests/Compress626Test.java | 30 +-
.../compress/harmony/pack200/tests/HelloWorld.java | 1 +
.../pack200/tests/NewAttributeBandsTest.java | 93 +-
.../harmony/pack200/tests/PackingOptionsTest.java | 2 +-
.../harmony/pack200/tests/PopulationCodecTest.java | 12 +-
.../harmony/pack200/tests/RunCodecTest.java | 54 +-
.../harmony/unpack200/tests/AbstractBandsTest.java | 5 +-
.../harmony/unpack200/tests/ArchiveTest.java | 6 +-
.../unpack200/tests/AttributeLayoutMapTest.java | 12 +-
.../unpack200/tests/AttributeLayoutTest.java | 55 +-
.../harmony/unpack200/tests/BandSetTest.java | 3 +-
.../harmony/unpack200/tests/BcBandsTest.java | 105 +-
.../harmony/unpack200/tests/ClassBandsTest.java | 32 +-
.../harmony/unpack200/tests/CodeAttributeTest.java | 38 +-
.../Codec_decodeInts_OutOfMemoryErrorTest.java | 6 +-
.../harmony/unpack200/tests/ICTupleTest.java | 26 +-
.../unpack200/tests/NewAttributeBandsTest.java | 66 +-
.../tests/SegmentConstantPoolArrayCacheTest.java | 8 +-
.../unpack200/tests/SegmentConstantPoolTest.java | 66 +-
.../harmony/unpack200/tests/SegmentTest.java | 2 +-
.../harmony/unpack200/tests/SegmentUtilsTest.java | 40 +-
.../unpack200/tests/bytecode/ByteCodeTest.java | 6 +-
.../tests/bytecode/ClassFileEntryTest.java | 24 +-
.../unpack200/tests/bytecode/ConstantPoolTest.java | 6 +-
.../commons/compress/utils/BitInputStreamTest.java | 75 +-
.../BoundedSeekableByteChannelInputStreamTest.java | 2 +-
.../utils/ChecksumCalculatingInputStreamTest.java | 2 +-
.../utils/ChecksumVerifyingInputStreamTest.java | 5 +-
.../commons/compress/utils/CountingStreamTest.java | 7 +-
.../utils/FixedLengthBlockOutputStreamTest.java | 27 +-
.../MultiReadOnlySeekableByteChannelTest.java | 5 +-
.../utils/SkipShieldingInputStreamTest.java | 92 +-
.../commons/compress/utils/TimeUtilsTest.java | 103 +-
.../ZipSplitReadOnlySeekableByteChannelTest.java | 8 +-
150 files changed, 3355 insertions(+), 4568 deletions(-)
diff --git a/pom.xml b/pom.xml
index 243b1ed21..cd8d26939 100644
--- a/pom.xml
+++ b/pom.xml
@@ -495,7 +495,7 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
<configuration>
<configLocation>${basedir}/src/conf/checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
- <includeTestSourceDirectory>false</includeTestSourceDirectory>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
<enableRulesSummary>false</enableRulesSummary>
<excludes>target/**</excludes>
</configuration>
diff --git a/src/test/java/org/apache/commons/compress/AbstractTest.java b/src/test/java/org/apache/commons/compress/AbstractTest.java
index 01db384ef..42af55459 100644
--- a/src/test/java/org/apache/commons/compress/AbstractTest.java
+++ b/src/test/java/org/apache/commons/compress/AbstractTest.java
@@ -135,11 +135,10 @@ public abstract class AbstractTest extends AbstractTempDirTest {
* Checks that an archive input stream can be read, and that the file data matches file sizes.
*
* @param inputStream
- * @param expected list of expected entries or {@code null} if no check of names desired
+ * @param expected list of expected entries or {@code null} if no check of names desired
* @throws Exception
*/
- protected void checkArchiveContent(final ArchiveInputStream<?> inputStream, final List<String> expected)
- throws Exception {
+ protected void checkArchiveContent(final ArchiveInputStream<?> inputStream, final List<String> expected) throws Exception {
checkArchiveContent(inputStream, expected, true);
}
@@ -147,13 +146,12 @@ public abstract class AbstractTest extends AbstractTempDirTest {
* Checks that an archive input stream can be read, and that the file data matches file sizes.
*
* @param inputStream
- * @param expected list of expected entries or {@code null} if no check of names desired
- * @param cleanUp Cleans up resources if true
+ * @param expected list of expected entries or {@code null} if no check of names desired
+ * @param cleanUp Cleans up resources if true
* @return returns the created result file if cleanUp = false, or null otherwise
* @throws Exception
*/
- protected File checkArchiveContent(final ArchiveInputStream<?> inputStream, final List<String> expected, final boolean cleanUp)
- throws Exception {
+ protected File checkArchiveContent(final ArchiveInputStream<?> inputStream, final List<String> expected, final boolean cleanUp) throws Exception {
final Path result = createTempDirectory("dir-result");
try {
@@ -224,9 +222,8 @@ public abstract class AbstractTest extends AbstractTempDirTest {
}
/**
- * Creates an archive of text-based files in several directories. The
- * archive name is the factory identifier for the archiver, for example zip,
- * tar, cpio, jar, ar. The archive is created as a temp file.
+ * Creates an archive of text-based files in several directories. The archive name is the factory identifier for the archiver, for example zip, tar, cpio,
+ * jar, ar. The archive is created as a temp file.
*
* The archive contains the following files:
* <ul>
@@ -241,11 +238,9 @@ public abstract class AbstractTest extends AbstractTempDirTest {
* <li>test with spaces.txt</li>
* </ul>
*
- * @param archiveName
- * the identifier of this archive
+ * @param archiveName the identifier of this archive
* @return the newly created file
- * @throws Exception
- * in case something goes wrong
+ * @throws Exception in case something goes wrong
*/
protected Path createArchive(final String archiveName) throws Exception {
final Path archivePath = createTempPath("test", "." + archiveName);
@@ -277,6 +272,7 @@ public abstract class AbstractTest extends AbstractTempDirTest {
/**
* Create an empty archive.
+ *
* @param archiveName
* @return the archive File
* @throws Exception
@@ -315,8 +311,7 @@ public abstract class AbstractTest extends AbstractTempDirTest {
}
/**
- * Override this method to change what is to be compared in the List.
- * For example, size + name instead of just name.
+ * Override this method to change what is to be compared in the List. For example, size + name instead of just name.
*
* @param entry
* @return returns the entry name
diff --git a/src/test/java/org/apache/commons/compress/ArchiveReadTest.java b/src/test/java/org/apache/commons/compress/ArchiveReadTest.java
index 463189937..25baad55e 100644
--- a/src/test/java/org/apache/commons/compress/ArchiveReadTest.java
+++ b/src/test/java/org/apache/commons/compress/ArchiveReadTest.java
@@ -39,8 +39,7 @@ import org.junit.jupiter.params.provider.MethodSource;
*
* This is a very simple implementation.
*
- * Files must be in resources/archives, and there must be a file.txt containing
- * the list of files in the archives.
+ * Files must be in resources/archives, and there must be a file.txt containing the list of files in the archives.
*/
public class ArchiveReadTest extends AbstractTest {
@@ -51,7 +50,7 @@ public class ArchiveReadTest extends AbstractTest {
static {
try {
ARCDIR = new File(CLASSLOADER.getResource("archives").toURI());
- } catch (final URISyntaxException e) {
+ } catch (URISyntaxException e) {
throw new AssertionError(e);
}
}
@@ -70,7 +69,7 @@ public class ArchiveReadTest extends AbstractTest {
assertTrue(ARCDIR.exists());
final File listing = new File(ARCDIR, "files.txt");
assertTrue(listing.canRead(), "files.txt is readable");
- try (final BufferedReader br = new BufferedReader(Files.newBufferedReader(listing.toPath()))) {
+ try (BufferedReader br = new BufferedReader(Files.newBufferedReader(listing.toPath()))) {
String line;
while ((line = br.readLine()) != null) {
if (!line.startsWith("#")) {
diff --git a/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java b/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java
index bf4858576..b686f0856 100644
--- a/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/ArchiveUtilsTest.java
@@ -58,8 +58,8 @@ public class ArchiveUtilsTest extends AbstractTest {
@Test
public void testCompareAscii() {
- final byte[] buffer1 = {'a', 'b', 'c'};
- final byte[] buffer2 = {'d', 'e', 'f', 0};
+ final byte[] buffer1 = { 'a', 'b', 'c' };
+ final byte[] buffer2 = { 'd', 'e', 'f', 0 };
assertTrue(ArchiveUtils.matchAsciiBuffer("abc", buffer1));
assertFalse(ArchiveUtils.matchAsciiBuffer("abc\0", buffer1));
assertTrue(ArchiveUtils.matchAsciiBuffer("def\0", buffer2));
@@ -68,9 +68,9 @@ public class ArchiveUtilsTest extends AbstractTest {
@Test
public void testCompareBA() {
- final byte[] buffer1 = {1, 2, 3};
- final byte[] buffer2 = {1, 2, 3, 0};
- final byte[] buffer3 = {1, 2, 3};
+ final byte[] buffer1 = { 1, 2, 3 };
+ final byte[] buffer2 = { 1, 2, 3, 0 };
+ final byte[] buffer3 = { 1, 2, 3 };
assertTrue(ArchiveUtils.isEqual(buffer1, buffer2, true));
assertFalse(ArchiveUtils.isEqual(buffer1, buffer2, false));
assertFalse(ArchiveUtils.isEqual(buffer1, buffer2));
@@ -126,7 +126,7 @@ public class ArchiveUtilsTest extends AbstractTest {
@Test
public void testToAsciiBytes() {
final byte[] byteArray = ArchiveUtils.toAsciiBytes("SOCKET");
- assertArrayEquals(new byte[] {(byte) 83, (byte) 79, (byte) 67, (byte) 75, (byte) 69, (byte) 84}, byteArray);
+ assertArrayEquals(new byte[] { (byte) 83, (byte) 79, (byte) 67, (byte) 75, (byte) 69, (byte) 84 }, byteArray);
assertFalse(ArchiveUtils.isEqualWithNull(byteArray, 0, 46, byteArray, 63, 0));
}
diff --git a/src/test/java/org/apache/commons/compress/ChainingTest.java b/src/test/java/org/apache/commons/compress/ChainingTest.java
index 1af167115..551bd4965 100644
--- a/src/test/java/org/apache/commons/compress/ChainingTest.java
+++ b/src/test/java/org/apache/commons/compress/ChainingTest.java
@@ -31,7 +31,7 @@ public class ChainingTest extends AbstractTest {
@Test
public void testTarBzip2() throws Exception {
- try (final TarArchiveInputStream is = new TarArchiveInputStream(new BZip2CompressorInputStream(newInputStream("bla.tar.bz2")))) {
+ try (TarArchiveInputStream is = new TarArchiveInputStream(new BZip2CompressorInputStream(newInputStream("bla.tar.bz2")))) {
final TarArchiveEntry entry = is.getNextEntry();
assertNotNull(entry);
assertEquals("test1.xml", entry.getName());
@@ -41,7 +41,7 @@ public class ChainingTest extends AbstractTest {
@Test
public void testTarGzip() throws Exception {
- try (final TarArchiveInputStream is = new TarArchiveInputStream(new GzipCompressorInputStream(newInputStream("bla.tgz")))) {
+ try (TarArchiveInputStream is = new TarArchiveInputStream(new GzipCompressorInputStream(newInputStream("bla.tgz")))) {
final TarArchiveEntry entry = is.getNextEntry();
assertNotNull(entry);
assertEquals("test1.xml", entry.getName());
diff --git a/src/test/java/org/apache/commons/compress/IOMethodsTest.java b/src/test/java/org/apache/commons/compress/IOMethodsTest.java
index 1dff82adc..d5ba41372 100644
--- a/src/test/java/org/apache/commons/compress/IOMethodsTest.java
+++ b/src/test/java/org/apache/commons/compress/IOMethodsTest.java
@@ -38,8 +38,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.junit.jupiter.api.Test;
/**
- * Check that the different write methods create the same output.
- * TODO perform the same checks for reads.
+ * Check that the different write methods create the same output. TODO perform the same checks for reads.
*/
public class IOMethodsTest extends AbstractTest {
diff --git a/src/test/java/org/apache/commons/compress/OsgiITest.java b/src/test/java/org/apache/commons/compress/OsgiITest.java
index 6935181f8..b9967906c 100644
--- a/src/test/java/org/apache/commons/compress/OsgiITest.java
+++ b/src/test/java/org/apache/commons/compress/OsgiITest.java
@@ -47,21 +47,15 @@ public class OsgiITest {
@Configuration
public Option[] config() {
- return new Option[] {
- systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
- systemProperty("org.ops4j.pax.url.mvn.useFallbackRepositories").value("false"),
- systemProperty("org.ops4j.pax.url.mvn.repositories").value("https://repo.maven.apache.org/maven2"),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.scr")
- .version("2.0.14"),
- mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.configadmin")
- .version("1.8.16"),
- composite(systemProperty("pax.exam.invoker").value("junit"),
- bundle("link:classpath:META-INF/links/org.ops4j.pax.tipi.junit.link"),
- bundle("link:classpath:META-INF/links/org.ops4j.pax.exam.invoker.junit.link"),
- mavenBundle().groupId("org.apache.servicemix.bundles")
- .artifactId("org.apache.servicemix.bundles.hamcrest").version("1.3_1")),
- bundle("reference:file:target/classes/").start()
- };
+ return new Option[] { systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
+ systemProperty("org.ops4j.pax.url.mvn.useFallbackRepositories").value("false"),
+ systemProperty("org.ops4j.pax.url.mvn.repositories").value("https://repo.maven.apache.org/maven2"),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.scr").version("2.0.14"),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.configadmin").version("1.8.16"),
+ composite(systemProperty("pax.exam.invoker").value("junit"), bundle("link:classpath:META-INF/links/org.ops4j.pax.tipi.junit.link"),
+ bundle("link:classpath:META-INF/links/org.ops4j.pax.exam.invoker.junit.link"),
+ mavenBundle().groupId("org.apache.servicemix.bundles").artifactId("org.apache.servicemix.bundles.hamcrest").version("1.3_1")),
+ bundle("reference:file:target/classes/").start() };
}
private Bundle loadBundle() {
diff --git a/src/test/java/org/apache/commons/compress/archivers/ArTest.java b/src/test/java/org/apache/commons/compress/archivers/ArTest.java
index bd79e57c7..a4fe80e6b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ArTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ArTest.java
@@ -47,7 +47,7 @@ public final class ArTest extends AbstractTest {
final File file1 = getFile("test1.xml");
final File file2 = getFile("test2.xml");
- try (final OutputStream out = Files.newOutputStream(output.toPath());
+ try (OutputStream out = Files.newOutputStream(output.toPath());
ArArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("ar", out)) {
os.putArchiveEntry(new ArArchiveEntry("test1.xml", file1.length()));
Files.copy(file1.toPath(), os);
@@ -158,8 +158,8 @@ public final class ArTest extends AbstractTest {
}
// UnArArchive Operation
- try (final InputStream is = Files.newInputStream(output.toPath());
- final ArchiveInputStream<ArArchiveEntry> in = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is))) {
+ try (InputStream is = Files.newInputStream(output.toPath());
+ ArchiveInputStream<ArArchiveEntry> in = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is))) {
final ArArchiveEntry entry = in.getNextEntry();
final File target = newTempFile(entry.getName());
diff --git a/src/test/java/org/apache/commons/compress/archivers/ArchiveServiceLoaderTest.java b/src/test/java/org/apache/commons/compress/archivers/ArchiveServiceLoaderTest.java
index 198f9348d..26ce49c8f 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ArchiveServiceLoaderTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ArchiveServiceLoaderTest.java
@@ -31,7 +31,7 @@ public class ArchiveServiceLoaderTest {
@Test
public void testInputStream() {
assertThrows(ArchiveException.class,
- () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream("ArchiveTestInput1", new ByteArrayInputStream(new byte[] {})));
+ () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream("ArchiveTestInput1", new ByteArrayInputStream(new byte[] {})));
}
@Test
diff --git a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
index 23adb65a8..e97ddfc80 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
@@ -53,7 +53,8 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
final String type;
final boolean hasOutputStream;
- TestData(final String testFile, final String type, final boolean hasOut, final String expectedEncoding, final ArchiveStreamFactory fac, final String fieldName) {
+ TestData(final String testFile, final String type, final boolean hasOut, final String expectedEncoding, final ArchiveStreamFactory fac,
+ final String fieldName) {
this.testFile = testFile;
this.expectedEncoding = expectedEncoding;
this.fac = fac;
@@ -64,8 +65,8 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
@Override
public String toString() {
- return "TestData [testFile=" + testFile + ", expectedEncoding=" + expectedEncoding + ", fac=" + fac
- + ", fieldName=" + fieldName + ", type=" + type + ", hasOutputStream=" + hasOutputStream + "]";
+ return "TestData [testFile=" + testFile + ", expectedEncoding=" + expectedEncoding + ", fac=" + fac + ", fieldName=" + fieldName + ", type=" + type
+ + ", hasOutputStream=" + hasOutputStream + "]";
}
}
@@ -88,19 +89,19 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
private static final String DUMP_DEFAULT;
- private static final String ZIP_DEFAULT = getField(new ZipArchiveInputStream(null),"encoding");
+ private static final String ZIP_DEFAULT = getField(new ZipArchiveInputStream(null), "encoding");
- private static final String CPIO_DEFAULT = getField(new CpioArchiveInputStream(null),"encoding");
+ private static final String CPIO_DEFAULT = getField(new CpioArchiveInputStream(null), "encoding");
- private static final String TAR_DEFAULT = getField(new TarArchiveInputStream(null),"encoding");
- private static final String JAR_DEFAULT = getField(new JarArchiveInputStream(null),"encoding");
+ private static final String TAR_DEFAULT = getField(new TarArchiveInputStream(null), "encoding");
+ private static final String JAR_DEFAULT = getField(new JarArchiveInputStream(null), "encoding");
static {
String dflt;
dflt = UNKNOWN;
try (ArjArchiveInputStream inputStream = new ArjArchiveInputStream(newInputStream("bla.arj"))) {
dflt = getField(inputStream, "charsetName");
- } catch (final Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
}
ARJ_DEFAULT = dflt;
@@ -108,49 +109,48 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
try (DumpArchiveInputStream inputStream = new DumpArchiveInputStream(newInputStream("bla.dump"))) {
dflt = getField(inputStream, "encoding");
- } catch (final Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
}
DUMP_DEFAULT = dflt;
}
- static final TestData[] TESTS = {
- new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, ARJ_DEFAULT, FACTORY, "charsetName"),
- new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, CharsetNames.UTF_8, FACTORY_UTF8, "charsetName"),
- new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, "ASCII", FACTORY_ASCII, "charsetName"),
- new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, CharsetNames.UTF_8, FACTORY_SET_UTF8, "charsetName"),
- new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, "ASCII", FACTORY_SET_ASCII, "charsetName"),
-
- new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, CPIO_DEFAULT, FACTORY, "encoding"),
- new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
- new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, "ASCII", FACTORY_ASCII, "encoding"),
- new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
- new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, "ASCII", FACTORY_SET_ASCII, "encoding"),
-
- new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, DUMP_DEFAULT, FACTORY, "encoding"),
- new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
- new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, "ASCII", FACTORY_ASCII, "encoding"),
- new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
- new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, "ASCII", FACTORY_SET_ASCII, "encoding"),
-
- new TestData("bla.tar", ArchiveStreamFactory.TAR, true, TAR_DEFAULT, FACTORY, "encoding"),
- new TestData("bla.tar", ArchiveStreamFactory.TAR, true, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
- new TestData("bla.tar", ArchiveStreamFactory.TAR, true, "ASCII", FACTORY_ASCII, "encoding"),
- new TestData("bla.tar", ArchiveStreamFactory.TAR, true, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
- new TestData("bla.tar", ArchiveStreamFactory.TAR, true, "ASCII", FACTORY_SET_ASCII, "encoding"),
-
- new TestData("bla.jar", ArchiveStreamFactory.JAR, true, JAR_DEFAULT, FACTORY, "encoding"),
- new TestData("bla.jar", ArchiveStreamFactory.JAR, true, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
- new TestData("bla.jar", ArchiveStreamFactory.JAR, true, "ASCII", FACTORY_ASCII, "encoding"),
- new TestData("bla.jar", ArchiveStreamFactory.JAR, true, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
- new TestData("bla.jar", ArchiveStreamFactory.JAR, true, "ASCII", FACTORY_SET_ASCII, "encoding"),
-
- new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, ZIP_DEFAULT, FACTORY, "encoding"),
- new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
- new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, "ASCII", FACTORY_ASCII, "encoding"),
- new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
- new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, "ASCII", FACTORY_SET_ASCII, "encoding"),
- };
+ static final TestData[] TESTS = { new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, ARJ_DEFAULT, FACTORY, "charsetName"),
+ new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, CharsetNames.UTF_8, FACTORY_UTF8, "charsetName"),
+ new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, "ASCII", FACTORY_ASCII, "charsetName"),
+ new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, CharsetNames.UTF_8, FACTORY_SET_UTF8, "charsetName"),
+ new TestData("bla.arj", ArchiveStreamFactory.ARJ, false, "ASCII", FACTORY_SET_ASCII, "charsetName"),
+
+ new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, CPIO_DEFAULT, FACTORY, "encoding"),
+ new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
+ new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, "ASCII", FACTORY_ASCII, "encoding"),
+ new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
+ new TestData("bla.cpio", ArchiveStreamFactory.CPIO, true, "ASCII", FACTORY_SET_ASCII, "encoding"),
+
+ new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, DUMP_DEFAULT, FACTORY, "encoding"),
+ new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
+ new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, "ASCII", FACTORY_ASCII, "encoding"),
+ new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
+ new TestData("bla.dump", ArchiveStreamFactory.DUMP, false, "ASCII", FACTORY_SET_ASCII, "encoding"),
+
+ new TestData("bla.tar", ArchiveStreamFactory.TAR, true, TAR_DEFAULT, FACTORY, "encoding"),
+ new TestData("bla.tar", ArchiveStreamFactory.TAR, true, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
+ new TestData("bla.tar", ArchiveStreamFactory.TAR, true, "ASCII", FACTORY_ASCII, "encoding"),
+ new TestData("bla.tar", ArchiveStreamFactory.TAR, true, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
+ new TestData("bla.tar", ArchiveStreamFactory.TAR, true, "ASCII", FACTORY_SET_ASCII, "encoding"),
+
+ new TestData("bla.jar", ArchiveStreamFactory.JAR, true, JAR_DEFAULT, FACTORY, "encoding"),
+ new TestData("bla.jar", ArchiveStreamFactory.JAR, true, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
+ new TestData("bla.jar", ArchiveStreamFactory.JAR, true, "ASCII", FACTORY_ASCII, "encoding"),
+ new TestData("bla.jar", ArchiveStreamFactory.JAR, true, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
+ new TestData("bla.jar", ArchiveStreamFactory.JAR, true, "ASCII", FACTORY_SET_ASCII, "encoding"),
+
+ new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, ZIP_DEFAULT, FACTORY, "encoding"),
+ new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, CharsetNames.UTF_8, FACTORY_UTF8, "encoding"),
+ new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, "ASCII", FACTORY_ASCII, "encoding"),
+ new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, CharsetNames.UTF_8, FACTORY_SET_UTF8, "encoding"),
+ new TestData("bla.zip", ArchiveStreamFactory.ZIP, true, "ASCII", FACTORY_SET_ASCII, "encoding"), };
+
// equals allowing null
private static boolean eq(final String exp, final String act) {
if (exp == null) {
@@ -158,6 +158,7 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
}
return exp.equals(act);
}
+
@SuppressWarnings("deprecation") // test of deprecated method
static ArchiveStreamFactory getFactory(final String entryEncoding) {
final ArchiveStreamFactory fac = new ArchiveStreamFactory();
@@ -170,13 +171,13 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
Field fld;
try {
fld = cls.getDeclaredField(name);
- } catch (final NoSuchFieldException nsfe) {
- try {
- fld = cls.getSuperclass().getDeclaredField(name);
- } catch (final NoSuchFieldException e) {
- System.out.println("Cannot find " + name + " in class " + instance.getClass().getSimpleName());
- return UNKNOWN;
- }
+ } catch (NoSuchFieldException nsfe) {
+ try {
+ fld = cls.getSuperclass().getDeclaredField(name);
+ } catch (NoSuchFieldException e) {
+ System.out.println("Cannot find " + name + " in class " + instance.getClass().getSimpleName());
+ return UNKNOWN;
+ }
}
final boolean isAccessible = fld.isAccessible();
try {
@@ -189,7 +190,7 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
}
System.out.println("Wrong type: " + object.getClass().getCanonicalName() + " for " + name + " in class " + instance.getClass().getSimpleName());
return UNKNOWN;
- } catch (final Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
return UNKNOWN;
} finally {
@@ -198,6 +199,7 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
}
}
}
+
private String detect(final String resource) throws IOException, ArchiveException {
try (InputStream in = new BufferedInputStream(newInputStream(resource))) {
return ArchiveStreamFactory.detect(in);
@@ -209,6 +211,7 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
throws IOException, ArchiveException {
return factory.createArchiveInputStream(new BufferedInputStream(newInputStream(resource)));
}
+
@SuppressWarnings("resource")
private <T extends ArchiveInputStream<? extends E>, E extends ArchiveEntry> T getInputStream(final String type, final String resource,
final ArchiveStreamFactory factory) throws IOException, ArchiveException {
@@ -219,13 +222,14 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
throws ArchiveException {
return factory.createArchiveOutputStream(type, new ByteArrayOutputStream());
}
+
/**
* see https://issues.apache.org/jira/browse/COMPRESS-191
*/
@Test
public void testAiffFilesAreNoTARs() throws Exception {
- try (final InputStream fis = newInputStream("testAIFF.aif");
- final InputStream is = new BufferedInputStream(fis)) {
+ try (InputStream fis = newInputStream("testAIFF.aif");
+ InputStream is = new BufferedInputStream(fis)) {
final ArchiveException ae = assertThrows(ArchiveException.class, () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(is),
"created an input stream for a non-archive");
assertTrue(ae.getMessage().startsWith("No Archiver found"));
@@ -234,20 +238,20 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
@Test
public void testCantRead7zFromStream() throws Exception {
- assertThrows(StreamingNotSupportedException.class,
- () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(ArchiveStreamFactory.SEVEN_Z, new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY)));
+ assertThrows(StreamingNotSupportedException.class, () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(ArchiveStreamFactory.SEVEN_Z,
+ new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY)));
}
@Test
public void testCantWrite7zToStream() throws Exception {
assertThrows(StreamingNotSupportedException.class,
- () -> ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.SEVEN_Z, new ByteArrayOutputStream()));
+ () -> ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.SEVEN_Z, new ByteArrayOutputStream()));
}
@Test
public void testCOMPRESS209() throws Exception {
- try (final InputStream fis = newInputStream("testCompress209.doc");
- final InputStream bis = new BufferedInputStream(fis)) {
+ try (InputStream fis = newInputStream("testCompress209.doc");
+ InputStream bis = new BufferedInputStream(fis)) {
final ArchiveException ae = assertThrows(ArchiveException.class, () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(bis),
"created an input stream for a non-archive");
assertTrue(ae.getMessage().startsWith("No Archiver found"));
@@ -256,18 +260,11 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
@Test
public void testDetect() throws Exception {
- for (final String extension : new String[]{
- ArchiveStreamFactory.AR,
- ArchiveStreamFactory.ARJ,
- ArchiveStreamFactory.CPIO,
- ArchiveStreamFactory.DUMP,
+ for (final String extension : new String[] { ArchiveStreamFactory.AR, ArchiveStreamFactory.ARJ, ArchiveStreamFactory.CPIO, ArchiveStreamFactory.DUMP,
// Compress doesn't know how to detect JARs, see COMPRESS-91
- // ArchiveStreamFactory.JAR,
- ArchiveStreamFactory.SEVEN_Z,
- ArchiveStreamFactory.TAR,
- ArchiveStreamFactory.ZIP
- }) {
- assertEquals(extension, detect("bla."+extension));
+ // ArchiveStreamFactory.JAR,
+ ArchiveStreamFactory.SEVEN_Z, ArchiveStreamFactory.TAR, ArchiveStreamFactory.ZIP }) {
+ assertEquals(extension, detect("bla." + extension));
}
final ArchiveException e1 = assertThrows(ArchiveException.class,
@@ -285,16 +282,14 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
}
/**
- * Test case for
- * <a href="https://issues.apache.org/jira/browse/COMPRESS-267"
- * >COMPRESS-267</a>.
+ * Test case for <a href="https://issues.apache.org/jira/browse/COMPRESS-267" >COMPRESS-267</a>.
*/
@Test
public void testDetectsAndThrowsFor7z() throws Exception {
- try (final InputStream fis = newInputStream("bla.7z");
- final InputStream bis = new BufferedInputStream(fis)) {
- final StreamingNotSupportedException ex = assertThrows(StreamingNotSupportedException.class, () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(bis),
- "Expected a StreamingNotSupportedException");
+ try (InputStream fis = newInputStream("bla.7z");
+ InputStream bis = new BufferedInputStream(fis)) {
+ final StreamingNotSupportedException ex = assertThrows(StreamingNotSupportedException.class,
+ () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(bis), "Expected a StreamingNotSupportedException");
assertEquals(ArchiveStreamFactory.SEVEN_Z, ex.getFormat());
}
}
@@ -328,7 +323,7 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
int failed = 0;
for (int i = 1; i <= TESTS.length; i++) {
final TestData test = TESTS[i - 1];
- try (final ArchiveInputStream<?> ais = getInputStream(test.type, test.testFile, test.fac)) {
+ try (ArchiveInputStream<?> ais = getInputStream(test.type, test.testFile, test.fac)) {
final String field = getField(ais, test.fieldName);
if (!eq(test.expectedEncoding, field)) {
System.err.println("Failed test " + i + ". expected: " + test.expectedEncoding + " actual: " + field + " type: " + test.type);
@@ -346,7 +341,7 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
int failed = 0;
for (int i = 1; i <= TESTS.length; i++) {
final TestData test = TESTS[i - 1];
- try (final ArchiveInputStream<?> ais = getInputStream(test.testFile, test.fac)) {
+ try (ArchiveInputStream<?> ais = getInputStream(test.testFile, test.fac)) {
final String field = getField(ais, test.fieldName);
if (!eq(test.expectedEncoding, field)) {
System.err.println("Failed test " + i + ". expected: " + test.expectedEncoding + " actual: " + field + " type: " + test.type);
@@ -365,7 +360,7 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
for (int i = 1; i <= TESTS.length; i++) {
final TestData test = TESTS[i - 1];
if (test.hasOutputStream) {
- try (final ArchiveOutputStream<?> ais = getOutputStream(test.type, test.fac)) {
+ try (ArchiveOutputStream<?> ais = getOutputStream(test.type, test.fac)) {
final String field = getField(ais, test.fieldName);
if (!eq(test.expectedEncoding, field)) {
System.err.println("Failed test " + i + ". expected: " + test.expectedEncoding + " actual: " + field + " type: " + test.type);
@@ -384,15 +379,15 @@ public class ArchiveStreamFactoryTest extends AbstractTest {
*/
@Test
public void testShortTextFilesAreNoTARs() {
- final ArchiveException ae = assertThrows(ArchiveException.class, () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(
- new ByteArrayInputStream("This certainly is not a tar archive, really, no kidding".getBytes())), "created an input stream for a non-archive");
+ final ArchiveException ae = assertThrows(ArchiveException.class,
+ () -> ArchiveStreamFactory.DEFAULT
+ .createArchiveInputStream(new ByteArrayInputStream("This certainly is not a tar archive, really, no kidding".getBytes())),
+ "created an input stream for a non-archive");
assertTrue(ae.getMessage().startsWith("No Archiver found"));
}
/**
- * Test case for
- * <a href="https://issues.apache.org/jira/browse/COMPRESS-208"
- * >COMPRESS-208</a>.
+ * Test case for <a href="https://issues.apache.org/jira/browse/COMPRESS-208" >COMPRESS-208</a>.
*/
@Test
public void testSkipsPK00Prefix() throws Exception {
diff --git a/src/test/java/org/apache/commons/compress/archivers/CpioTest.java b/src/test/java/org/apache/commons/compress/archivers/CpioTest.java
index 1164ea5f4..626d8504d 100644
--- a/src/test/java/org/apache/commons/compress/archivers/CpioTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/CpioTest.java
@@ -47,8 +47,7 @@ public final class CpioTest extends AbstractTest {
final File file2 = getFile("test2.xml");
try (OutputStream outputStream = Files.newOutputStream(output.toPath());
- final ArchiveOutputStream<CpioArchiveEntry> archiveOutputStream = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("cpio",
- outputStream)) {
+ ArchiveOutputStream<CpioArchiveEntry> archiveOutputStream = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("cpio", outputStream)) {
archiveOutputStream.putArchiveEntry(new CpioArchiveEntry("test1.xml", file1.length()));
Files.copy(file1.toPath(), archiveOutputStream);
archiveOutputStream.closeArchiveEntry();
diff --git a/src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java b/src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java
index eb0fc977b..707f7e021 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ExceptionMessageTest.java
@@ -35,33 +35,29 @@ public class ExceptionMessageTest {
@Test
public void testMessageWhenArchiverNameIsNull_1() {
final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
- () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(null, System.in),
- "Should raise an IllegalArgumentException.");
+ () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream(null, System.in), "Should raise an IllegalArgumentException.");
assertEquals(ARCHIVER_NULL_MESSAGE, e.getMessage());
}
@Test
public void testMessageWhenArchiverNameIsNull_2() {
final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
- () -> ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(null, System.out),
- "Should raise an IllegalArgumentException.");
+ () -> ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(null, System.out), "Should raise an IllegalArgumentException.");
assertEquals(ARCHIVER_NULL_MESSAGE, e.getMessage());
}
@Test
public void testMessageWhenInputStreamIsNull() {
final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
- () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", null),
- "Should raise an IllegalArgumentException.");
+ () -> ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", null), "Should raise an IllegalArgumentException.");
assertEquals(INPUTSTREAM_NULL_MESSAGE, e.getMessage());
}
@Test
public void testMessageWhenOutputStreamIsNull() {
final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
- () -> ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", null),
- "Should raise an IllegalArgumentException.");
+ () -> ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", null), "Should raise an IllegalArgumentException.");
assertEquals(OUTPUTSTREAM_NULL_MESSAGE, e.getMessage());
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/commons/compress/archivers/JarTest.java b/src/test/java/org/apache/commons/compress/archivers/JarTest.java
index 1fdb070d9..b321abcc1 100644
--- a/src/test/java/org/apache/commons/compress/archivers/JarTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/JarTest.java
@@ -49,7 +49,6 @@ public final class JarTest extends AbstractTest {
}
}
-
@Test
public void testJarUnarchive() throws Exception {
final File input = getFile("bla.jar");
@@ -77,7 +76,7 @@ public final class JarTest extends AbstractTest {
public void testJarUnarchiveAll() throws Exception {
final File input = getFile("bla.jar");
try (InputStream is = Files.newInputStream(input.toPath());
- final ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+ ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
ArchiveEntry entry = in.getNextEntry();
while (entry != null) {
diff --git a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
index cd7c73102..38201b788 100644
--- a/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/LongPathTest.java
@@ -44,8 +44,7 @@ import org.junit.jupiter.params.provider.MethodSource;
/**
* Test that can read various tar file examples.
*
- * Files must be in resources/longpath, and there must be a file.txt containing
- * the list of files in the archives.
+ * Files must be in resources/longpath, and there must be a file.txt containing the list of files in the archives.
*/
public class LongPathTest extends AbstractTest {
@@ -56,7 +55,7 @@ public class LongPathTest extends AbstractTest {
static {
try {
ARCDIR = new File(CLASSLOADER.getResource("longpath").toURI());
- } catch (final URISyntaxException e) {
+ } catch (URISyntaxException e) {
throw new AssertionError(e);
}
}
@@ -125,9 +124,11 @@ public class LongPathTest extends AbstractTest {
// CPIO does not store directories or directory names
expected.clear();
for (final String ent : FILELIST) {
- if (!ent.endsWith("/")) {// not a directory
+ if (!ent.endsWith("/")) {
+ // not a directory
final int lastSlash = ent.lastIndexOf('/');
- if (lastSlash >= 0) { // extract path name
+ if (lastSlash >= 0) {
+ // extract path name
expected.add(ent.substring(lastSlash + 1));
} else {
expected.add(ent);
diff --git a/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java b/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java
index 75b49f981..1a95a2eda 100644
--- a/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/LongSymLinkTest.java
@@ -54,7 +54,7 @@ public class LongSymLinkTest extends AbstractTest {
static {
try {
ARCDIR = new File(CLASSLOADER.getResource("longsymlink").toURI());
- } catch (final URISyntaxException e) {
+ } catch (URISyntaxException e) {
throw new AssertionError(e);
}
}
@@ -123,9 +123,11 @@ public class LongSymLinkTest extends AbstractTest {
// CPIO does not store directories or directory names
expected.clear();
for (final String ent : FILELIST) {
- if (!ent.endsWith("/")) {// not a directory
+ if (!ent.endsWith("/")) {
+ // not a directory
final int lastSlash = ent.lastIndexOf('/');
- if (lastSlash >= 0) { // extract path name
+ if (lastSlash >= 0) {
+ // extract path name
expected.add(ent.substring(lastSlash + 1));
} else {
expected.add(ent);
diff --git a/src/test/java/org/apache/commons/compress/archivers/TarTest.java b/src/test/java/org/apache/commons/compress/archivers/TarTest.java
index a1cf0b1c8..0bf52ee2c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/TarTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/TarTest.java
@@ -60,7 +60,7 @@ public final class TarTest extends AbstractTest {
private byte[] createTarWithOneLongNameEntry(final String longName) throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
final TarArchiveEntry longFileNameEntry = new TarArchiveEntry(longName);
tos.putArchiveEntry(longFileNameEntry);
@@ -72,8 +72,8 @@ public final class TarTest extends AbstractTest {
@Test
public void testCOMPRESS114() throws Exception {
final File input = getFile("COMPRESS-114.tar");
- try (final InputStream is = Files.newInputStream(input.toPath());
- final TarArchiveInputStream in = new TarArchiveInputStream(is, CharsetNames.ISO_8859_1)) {
+ try (InputStream is = Files.newInputStream(input.toPath());
+ TarArchiveInputStream in = new TarArchiveInputStream(is, CharsetNames.ISO_8859_1)) {
TarArchiveEntry entry = in.getNextEntry();
assertEquals("3\u00b1\u00b1\u00b1F06\u00b1W2345\u00b1ZB\u00b1la\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1BLA", entry.getName());
assertEquals(TarConstants.LF_NORMAL, entry.getLinkFlag());
@@ -97,8 +97,8 @@ public final class TarTest extends AbstractTest {
@Test
public void testCOMPRESS178Lenient() throws Exception {
final File input = getFile("COMPRESS-178.tar");
- try (final InputStream is = Files.newInputStream(input.toPath());
- final ArchiveInputStream<?> in = new TarArchiveInputStream(is, true)) {
+ try (InputStream is = Files.newInputStream(input.toPath());
+ ArchiveInputStream<?> in = new TarArchiveInputStream(is, true)) {
in.getNextEntry();
}
}
@@ -130,8 +130,8 @@ public final class TarTest extends AbstractTest {
@Test
public void testDirectoryRead() throws IOException {
final File input = getFile("directory.tar");
- try (final InputStream is = Files.newInputStream(input.toPath());
- final TarArchiveInputStream in = new TarArchiveInputStream(is)) {
+ try (InputStream is = Files.newInputStream(input.toPath());
+ TarArchiveInputStream in = new TarArchiveInputStream(is)) {
final TarArchiveEntry directoryEntry = in.getNextTarEntry();
assertEquals("directory/", directoryEntry.getName());
assertEquals(TarConstants.LF_DIR, directoryEntry.getLinkFlag());
@@ -228,8 +228,8 @@ public final class TarTest extends AbstractTest {
final String fileName = createLongName(length);
assertEquals(length.intValue(), fileName.length());
final byte[] data = createTarWithOneLongNameEntry(fileName);
- try (final ByteArrayInputStream bis = new ByteArrayInputStream(data);
- final TarArchiveInputStream tis = new TarArchiveInputStream(bis)) {
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(data);
+ TarArchiveInputStream tis = new TarArchiveInputStream(bis)) {
assertEquals(fileName, tis.getNextTarEntry().getName());
}
}
@@ -293,7 +293,7 @@ public final class TarTest extends AbstractTest {
os2.putArchiveEntry(entry);
Files.copy(file1.toPath(), os2);
os2.closeArchiveEntry();
- } catch (final IOException e) {
+ } catch (IOException e) {
assertTrue(true);
}
}
@@ -301,7 +301,7 @@ public final class TarTest extends AbstractTest {
@Test
public void testTarFileCOMPRESS114() throws Exception {
final File input = getFile("COMPRESS-114.tar");
- try (final TarFile tarFile = new TarFile(input, CharsetNames.ISO_8859_1)) {
+ try (TarFile tarFile = new TarFile(input, CharsetNames.ISO_8859_1)) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
TarArchiveEntry entry = entries.get(0);
assertEquals("3\u00b1\u00b1\u00b1F06\u00b1W2345\u00b1ZB\u00b1la\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1BLA", entry.getName());
@@ -316,7 +316,7 @@ public final class TarTest extends AbstractTest {
public void testTarFileCOMPRESS178() throws Exception {
final File input = getFile("COMPRESS-178.tar");
final IOException e = assertThrows(IOException.class, () -> {
- try (final TarFile tarFile = new TarFile(input)) {
+ try (TarFile tarFile = new TarFile(input)) {
// Compared to the TarArchiveInputStream all entries are read when instantiating the tar file
}
}, "Expected IOException");
@@ -327,7 +327,7 @@ public final class TarTest extends AbstractTest {
@Test
public void testTarFileCOMPRESS178Lenient() throws Exception {
final File input = getFile("COMPRESS-178.tar");
- try (final TarFile tarFile = new TarFile(input, true)) {
+ try (TarFile tarFile = new TarFile(input, true)) {
// Compared to the TarArchiveInputStream all entries are read when instantiating the tar file
}
}
@@ -336,13 +336,13 @@ public final class TarTest extends AbstractTest {
public void testTarFileDirectoryEntryFromFile() throws Exception {
final File archive = createTempFile("test.", ".tar");
final File dir = getTempDirFile();
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
final long beforeArchiveWrite = dir.lastModified();
final TarArchiveEntry in = new TarArchiveEntry(dir, "foo");
tos.putArchiveEntry(in);
tos.closeArchiveEntry();
tos.close();
- try (final TarFile tarFile = new TarFile(archive)) {
+ try (TarFile tarFile = new TarFile(archive)) {
final TarArchiveEntry entry = tarFile.getEntries().get(0);
assertNotNull(entry);
assertEquals("foo/", entry.getName());
@@ -374,18 +374,18 @@ public final class TarTest extends AbstractTest {
public void testTarFileEntryFromFile() throws Exception {
final File tmp = createTempFile();
final File archive = createTempFile("test.", ".tar");
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
final TarArchiveEntry in = new TarArchiveEntry(tmp, "foo");
tos.putArchiveEntry(in);
final byte[] b = new byte[(int) tmp.length()];
- try (final InputStream fis = Files.newInputStream(tmp.toPath())) {
+ try (InputStream fis = Files.newInputStream(tmp.toPath())) {
while (fis.read(b) > 0) {
tos.write(b);
}
}
tos.closeArchiveEntry();
tos.close();
- try (final TarFile tarFile = new TarFile(archive)) {
+ try (TarFile tarFile = new TarFile(archive)) {
final TarArchiveEntry entry = tarFile.getEntries().get(0);
assertNotNull(entry);
assertEquals("foo", entry.getName());
@@ -400,14 +400,14 @@ public final class TarTest extends AbstractTest {
@Test
public void testTarFileExplicitDirectoryEntry() throws Exception {
final File archive = createTempFile("test.", ".tar");
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
final long beforeArchiveWrite = getTempDirFile().lastModified();
final TarArchiveEntry in = new TarArchiveEntry("foo/");
in.setModTime(beforeArchiveWrite);
tos.putArchiveEntry(in);
tos.closeArchiveEntry();
tos.close();
- try (final TarFile tarFile = new TarFile(archive)) {
+ try (TarFile tarFile = new TarFile(archive)) {
final TarArchiveEntry entry = tarFile.getEntries().get(0);
assertNotNull(entry);
assertEquals("foo/", entry.getName());
@@ -423,20 +423,20 @@ public final class TarTest extends AbstractTest {
public void testTarFileExplicitFileEntry() throws Exception {
final File tmp = createTempFile();
final File archive = createTempFile("test.", ".tar");
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(Files.newOutputStream(archive.toPath()))) {
final TarArchiveEntry in = new TarArchiveEntry("foo");
in.setModTime(tmp.lastModified());
in.setSize(tmp.length());
tos.putArchiveEntry(in);
final byte[] b = new byte[(int) tmp.length()];
- try (final InputStream fis = Files.newInputStream(tmp.toPath())) {
+ try (InputStream fis = Files.newInputStream(tmp.toPath())) {
while (fis.read(b) > 0) {
tos.write(b);
}
}
tos.closeArchiveEntry();
- try (final TarFile tarFile = new TarFile(archive)) {
+ try (TarFile tarFile = new TarFile(archive)) {
final TarArchiveEntry entry = tarFile.getEntries().get(0);
assertNotNull(entry);
assertEquals("foo", entry.getName());
@@ -456,7 +456,7 @@ public final class TarTest extends AbstractTest {
final String fileName = createLongName(length);
assertEquals(length.intValue(), fileName.length());
final byte[] data = createTarWithOneLongNameEntry(fileName);
- try (final TarFile tarFile = new TarFile(data)) {
+ try (TarFile tarFile = new TarFile(data)) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertEquals(fileName, entries.get(0).getName());
assertEquals(TarConstants.LF_NORMAL, entries.get(0).getLinkFlag());
@@ -478,8 +478,8 @@ public final class TarTest extends AbstractTest {
@Test
public void testTarUnarchive() throws Exception {
final File input = getFile("bla.tar");
- try (final InputStream is = Files.newInputStream(input.toPath());
- final TarArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
+ try (InputStream is = Files.newInputStream(input.toPath());
+ TarArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
final TarArchiveEntry entry = in.getNextEntry();
Files.copy(in, newTempFile(entry.getName()).toPath());
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/TestArchiveStreamProvider.java b/src/test/java/org/apache/commons/compress/archivers/TestArchiveStreamProvider.java
index ba3287755..d8af346f5 100644
--- a/src/test/java/org/apache/commons/compress/archivers/TestArchiveStreamProvider.java
+++ b/src/test/java/org/apache/commons/compress/archivers/TestArchiveStreamProvider.java
@@ -37,14 +37,14 @@ public class TestArchiveStreamProvider implements ArchiveStreamProvider {
}
@Override
- public <T extends ArchiveInputStream<? extends ArchiveEntry>> T createArchiveInputStream(final String name, final InputStream in,
- final String encoding) throws ArchiveException {
+ public <T extends ArchiveInputStream<? extends ArchiveEntry>> T createArchiveInputStream(final String name, final InputStream in, final String encoding)
+ throws ArchiveException {
throw new ArchiveInvocationConfirmationException(name);
}
@Override
- public <T extends ArchiveOutputStream<? extends ArchiveEntry>> T createArchiveOutputStream(final String name, final OutputStream out,
- final String encoding) throws ArchiveException {
+ public <T extends ArchiveOutputStream<? extends ArchiveEntry>> T createArchiveOutputStream(final String name, final OutputStream out, final String encoding)
+ throws ArchiveException {
throw new ArchiveInvocationConfirmationException(name);
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/ZipTest.java b/src/test/java/org/apache/commons/compress/archivers/ZipTest.java
index cb0d42702..9eea8ae0c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ZipTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ZipTest.java
@@ -89,8 +89,8 @@ public final class ZipTest extends AbstractTest {
private void assertSameFileContents(final File expectedFile, final File actualFile) throws IOException {
final int size = (int) Math.max(expectedFile.length(), actualFile.length());
- try (final ZipFile expected = new ZipFile(expectedFile);
- final ZipFile actual = new ZipFile(actualFile)) {
+ try (ZipFile expected = new ZipFile(expectedFile);
+ ZipFile actual = new ZipFile(actualFile)) {
final byte[] expectedBuf = new byte[size];
final byte[] actualBuf = new byte[size];
@@ -111,8 +111,8 @@ public final class ZipTest extends AbstractTest {
assertEquals(expectedElement.getExternalAttributes(), actualElement.getExternalAttributes());
assertEquals(expectedElement.getInternalAttributes(), actualElement.getInternalAttributes());
- try (final InputStream actualIs = actual.getInputStream(actualElement);
- final InputStream expectedIs = expected.getInputStream(expectedElement)) {
+ try (InputStream actualIs = actual.getInputStream(actualElement);
+ InputStream expectedIs = expected.getInputStream(expectedElement)) {
IOUtils.readFully(expectedIs, expectedBuf);
IOUtils.readFully(actualIs, actualBuf);
}
@@ -150,7 +150,7 @@ public final class ZipTest extends AbstractTest {
private File createReferenceFile(final Zip64Mode zipMode, final String prefix) throws IOException {
final File reference = createTempFile(prefix, ".zip");
- try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(reference)) {
+ try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(reference)) {
zos.setUseZip64(zipMode);
createFirstEntry(zos);
createSecondEntry(zos);
@@ -167,7 +167,7 @@ public final class ZipTest extends AbstractTest {
final File directoryToZip = getFilesToZip();
final File outputZipFile = newTempFile("splitZip.zip");
final long splitSize = 100 * 1024L; /* 100 KB */
- try (final ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(outputZipFile, splitSize)) {
+ try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(outputZipFile, splitSize)) {
addFilesToZip(zipArchiveOutputStream, directoryToZip);
}
}
@@ -251,14 +251,14 @@ public final class ZipTest extends AbstractTest {
final File directoryToZip = getFilesToZip();
final File outputZipFile = newTempFile("splitZip.zip");
final long splitSize = 100 * 1024L; /* 100 KB */
- try (final ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(outputZipFile, splitSize)) {
+ try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(outputZipFile, splitSize)) {
// create a file that has the same name of one of the created split segments
final File sameNameFile = newTempFile("splitZip.z01");
sameNameFile.createNewFile();
assertThrows(IOException.class, () -> addFilesToZip(zipArchiveOutputStream, directoryToZip));
- } catch (final Exception e) {
+ } catch (Exception e) {
// Ignore:
// java.io.IOException: This archive contains unclosed entries.
// at org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream.finish(ZipArchiveOutputStream.java:563)
@@ -289,21 +289,21 @@ public final class ZipTest extends AbstractTest {
final File reference = createReferenceFile(Zip64Mode.Never, "expected.");
final File file1 = createTempFile("src1.", ".zip");
- try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
+ try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
zos.setUseZip64(Zip64Mode.Never);
createFirstEntry(zos).close();
}
final File file2 = createTempFile("src2.", ".zip");
- try (final ZipArchiveOutputStream zos1 = new ZipArchiveOutputStream(file2)) {
+ try (ZipArchiveOutputStream zos1 = new ZipArchiveOutputStream(file2)) {
zos1.setUseZip64(Zip64Mode.Never);
createSecondEntry(zos1).close();
}
- try (final ZipFile zipFile1 = new ZipFile(file1);
- final ZipFile zipFile2 = new ZipFile(file2)) {
+ try (ZipFile zipFile1 = new ZipFile(file1);
+ ZipFile zipFile2 = new ZipFile(file2)) {
final File fileResult = createTempFile("file-actual.", ".zip");
- try (final ZipArchiveOutputStream zos2 = new ZipArchiveOutputStream(fileResult)) {
+ try (ZipArchiveOutputStream zos2 = new ZipArchiveOutputStream(fileResult)) {
zipFile1.copyRawEntries(zos2, allFilesPredicate);
zipFile2.copyRawEntries(zos2, allFilesPredicate);
}
@@ -318,20 +318,20 @@ public final class ZipTest extends AbstractTest {
public void testCopyRawZip64EntryFromFile() throws IOException {
final File reference = createTempFile("z64reference.", ".zip");
- try (final ZipArchiveOutputStream zos1 = new ZipArchiveOutputStream(reference)) {
+ try (ZipArchiveOutputStream zos1 = new ZipArchiveOutputStream(reference)) {
zos1.setUseZip64(Zip64Mode.Always);
createFirstEntry(zos1);
}
final File file1 = createTempFile("zip64src.", ".zip");
- try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
+ try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
zos.setUseZip64(Zip64Mode.Always);
createFirstEntry(zos).close();
}
final File fileResult = createTempFile("file-actual.", ".zip");
- try (final ZipFile zipFile1 = new ZipFile(file1)) {
- try (final ZipArchiveOutputStream zos2 = new ZipArchiveOutputStream(fileResult)) {
+ try (ZipFile zipFile1 = new ZipFile(file1)) {
+ try (ZipArchiveOutputStream zos2 = new ZipArchiveOutputStream(fileResult)) {
zos2.setUseZip64(Zip64Mode.Always);
zipFile1.copyRawEntries(zos2, allFilesPredicate);
}
@@ -440,15 +440,15 @@ public final class ZipTest extends AbstractTest {
final Map<String, List<List<Long>>> actualStatistics = new HashMap<>();
// stream access
- try (final InputStream fis = Files.newInputStream(input.toPath());
- final ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", fis)) {
+ try (InputStream fis = Files.newInputStream(input.toPath());
+ ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", fis)) {
for (ArchiveEntry entry; (entry = in.getNextEntry()) != null;) {
readStream(in, entry, actualStatistics);
}
}
// file access
- try (final ZipFile zf = new ZipFile(input)) {
+ try (ZipFile zf = new ZipFile(input)) {
final Enumeration<ZipArchiveEntry> entries = zf.getEntries();
while (entries.hasMoreElements()) {
final ZipArchiveEntry zae = entries.nextElement();
@@ -526,7 +526,7 @@ public final class ZipTest extends AbstractTest {
final List<String> results = new ArrayList<>();
final List<ZipException> expectedExceptions = new ArrayList<>();
- try (final InputStream fis = Files.newInputStream(input.toPath());
+ try (InputStream fis = Files.newInputStream(input.toPath());
ZipArchiveInputStream in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", fis)) {
ZipArchiveEntry entry;
@@ -539,7 +539,7 @@ public final class ZipTest extends AbstractTest {
while ((nestedEntry = nestedIn.getNextEntry()) != null) {
results.add(nestedEntry.getName());
}
- } catch (final ZipException ex) {
+ } catch (ZipException ex) {
// expected since you cannot create a final ArchiveInputStream from test3.xml
expectedExceptions.add(ex);
}
@@ -580,7 +580,7 @@ public final class ZipTest extends AbstractTest {
al.add("test1.xml");
al.add("test2.xml");
try (InputStream fis = Files.newInputStream(input.toPath());
- final ZipArchiveInputStream inputStream = new ZipArchiveInputStream(fis)) {
+ ZipArchiveInputStream inputStream = new ZipArchiveInputStream(fis)) {
checkArchiveContent(inputStream, al);
}
}
@@ -590,7 +590,7 @@ public final class ZipTest extends AbstractTest {
*/
@Test
public void testTokenizationCompressionMethod() throws IOException {
- try (final ZipFile moby = new ZipFile(getFile("moby.zip"))) {
+ try (ZipFile moby = new ZipFile(getFile("moby.zip"))) {
final ZipArchiveEntry entry = moby.getEntry("README");
assertEquals(ZipMethod.TOKENIZATION.getCode(), entry.getMethod(), "method");
assertFalse(moby.canReadEntryData(entry));
@@ -600,7 +600,7 @@ public final class ZipTest extends AbstractTest {
@Test
public void testUnixModeInAddRaw() throws IOException {
final File file1 = createTempFile("unixModeBits.", ".zip");
- try (final ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
+ try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(file1)) {
final ZipArchiveEntry archiveEntry = new ZipArchiveEntry("fred");
archiveEntry.setUnixMode(0664);
archiveEntry.setMethod(ZipEntry.STORED);
@@ -608,7 +608,7 @@ public final class ZipTest extends AbstractTest {
archiveEntry.setCompressedSize(3);
zos.addRawArchiveEntry(archiveEntry, new ByteArrayInputStream("fud".getBytes()));
}
- try (final ZipFile zf1 = new ZipFile(file1)) {
+ try (ZipFile zf1 = new ZipFile(file1)) {
final ZipArchiveEntry fred = zf1.getEntry("fred");
assertEquals(0664, fred.getUnixMode());
}
@@ -626,7 +626,7 @@ public final class ZipTest extends AbstractTest {
final File file1 = getFile("test1.xml");
final File file2 = getFile("test2.xml");
- try (final OutputStream out = Files.newOutputStream(output.toPath())) {
+ try (OutputStream out = Files.newOutputStream(output.toPath())) {
try (ArchiveOutputStream<ZipArchiveEntry> os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("zip", out)) {
os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
Files.copy(file1.toPath(), os);
@@ -641,7 +641,7 @@ public final class ZipTest extends AbstractTest {
// Unarchive the same
final List<File> results = new ArrayList<>();
- try (final InputStream fileInputStream = Files.newInputStream(output.toPath())) {
+ try (InputStream fileInputStream = Files.newInputStream(output.toPath())) {
try (ArchiveInputStream<ZipArchiveEntry> archiveInputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", fileInputStream)) {
ZipArchiveEntry entry;
while ((entry = archiveInputStream.getNextEntry()) != null) {
@@ -737,8 +737,8 @@ public final class ZipTest extends AbstractTest {
@Test
public void testZipUnarchive() throws Exception {
final File input = getFile("bla.zip");
- try (final InputStream is = Files.newInputStream(input.toPath());
- final ArchiveInputStream<ZipArchiveEntry> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", is)) {
+ try (InputStream is = Files.newInputStream(input.toPath());
+ ArchiveInputStream<ZipArchiveEntry> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("zip", is)) {
final ZipArchiveEntry entry = in.getNextEntry();
Files.copy(in, newTempFile(entry.getName()).toPath());
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java
index ba2d85332..ff876d570 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java
@@ -40,8 +40,8 @@ import org.junit.jupiter.params.provider.ValueSource;
public class ArArchiveInputStreamTest extends AbstractTest {
private void checkLongNameEntry(final String archive) throws Exception {
- try (final InputStream fis = newInputStream(archive);
- final ArArchiveInputStream s = new ArArchiveInputStream(new BufferedInputStream(fis))) {
+ try (InputStream fis = newInputStream(archive);
+ ArArchiveInputStream s = new ArArchiveInputStream(new BufferedInputStream(fis))) {
ArchiveEntry e = s.getNextEntry();
assertEquals("this_is_a_long_file_name.txt", e.getName());
assertEquals(14, e.getSize());
@@ -61,7 +61,7 @@ public class ArArchiveInputStreamTest extends AbstractTest {
@Test
public void testCantReadAfterClose() throws Exception {
try (InputStream in = newInputStream("bla.ar");
- ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
+ ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
archive.close();
assertThrows(IllegalStateException.class, () -> archive.read());
}
@@ -70,7 +70,7 @@ public class ArArchiveInputStreamTest extends AbstractTest {
@Test
public void testCantReadWithoutOpeningAnEntry() throws Exception {
try (InputStream in = newInputStream("bla.ar");
- ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
+ ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
assertThrows(IllegalStateException.class, () -> archive.read());
}
}
@@ -78,25 +78,26 @@ public class ArArchiveInputStreamTest extends AbstractTest {
@Test
public void testInvalidBadTableLength() throws Exception {
try (InputStream in = newInputStream("org/apache/commons/compress/ar/number_parsing/bad_table_length_gnu.ar");
- ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
+ ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
assertThrows(IOException.class, archive::getNextEntry);
}
}
@ParameterizedTest
- @ValueSource(strings = {"bad_long_namelen_bsd.ar", "bad_long_namelen_gnu1.ar", "bad_long_namelen_gnu2.ar", "bad_long_namelen_gnu3.ar", "bad_table_length_gnu.ar"})
+ @ValueSource(strings = { "bad_long_namelen_bsd.ar", "bad_long_namelen_gnu1.ar", "bad_long_namelen_gnu2.ar", "bad_long_namelen_gnu3.ar",
+ "bad_table_length_gnu.ar" })
public void testInvalidLongNameLength(final String testFileName) throws Exception {
try (InputStream in = newInputStream("org/apache/commons/compress/ar/number_parsing/" + testFileName);
- ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
+ ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
assertThrows(IOException.class, archive::getNextEntry);
}
}
@ParameterizedTest
- @ValueSource(strings = {"bad_group.ar", "bad_length.ar", "bad_modified.ar", "bad_user.ar"})
+ @ValueSource(strings = { "bad_group.ar", "bad_length.ar", "bad_modified.ar", "bad_user.ar" })
public void testInvalidNumericFields(final String testFileName) throws Exception {
try (InputStream in = newInputStream("org/apache/commons/compress/ar/number_parsing/" + testFileName);
- ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
+ ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
assertThrows(IOException.class, archive::getNextEntry);
}
}
@@ -105,7 +106,7 @@ public class ArArchiveInputStreamTest extends AbstractTest {
public void testMultiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
final byte[] buf = new byte[2];
try (InputStream in = newInputStream("bla.ar");
- ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
+ ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read(buf));
@@ -125,7 +126,7 @@ public class ArArchiveInputStreamTest extends AbstractTest {
@Test
public void testSimpleInputStream() throws IOException {
- try (final InputStream fileInputStream = newInputStream("bla.ar")) {
+ try (InputStream fileInputStream = newInputStream("bla.ar")) {
// This default implementation of InputStream.available() always returns zero,
// and there are many streams in practice where the total length of the stream is not known.
@@ -155,7 +156,7 @@ public class ArArchiveInputStreamTest extends AbstractTest {
@Test
public void testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
try (InputStream in = newInputStream("bla.ar");
- ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
+ ArArchiveInputStream archive = new ArArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read());
diff --git a/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java
index 4229a8665..262363d32 100644
--- a/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStreamTest.java
@@ -45,7 +45,7 @@ public class ArjArchiveInputStreamTest extends AbstractTest {
expected.append("<empty/>\n");
final StringBuilder result = new StringBuilder();
- try (final ArjArchiveInputStream in = new ArjArchiveInputStream(newInputStream("bla.arj"))) {
+ try (ArjArchiveInputStream in = new ArjArchiveInputStream(newInputStream("bla.arj"))) {
ArjArchiveEntry entry;
while ((entry = in.getNextEntry()) != null) {
@@ -76,7 +76,7 @@ public class ArjArchiveInputStreamTest extends AbstractTest {
public void testMultiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
final byte[] buf = new byte[2];
try (InputStream in = newInputStream("bla.arj");
- ArjArchiveInputStream archive = new ArjArchiveInputStream(in)) {
+ ArjArchiveInputStream archive = new ArjArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read(buf));
@@ -86,7 +86,7 @@ public class ArjArchiveInputStreamTest extends AbstractTest {
@Test
public void testReadingOfAttributesDosVersion() throws Exception {
- try (final ArjArchiveInputStream in = new ArjArchiveInputStream(newInputStream("bla.arj"))) {
+ try (ArjArchiveInputStream in = new ArjArchiveInputStream(newInputStream("bla.arj"))) {
final ArjArchiveEntry entry = in.getNextEntry();
assertEquals("test1.xml", entry.getName());
assertEquals(30, entry.getSize());
@@ -100,7 +100,7 @@ public class ArjArchiveInputStreamTest extends AbstractTest {
@Test
public void testReadingOfAttributesUnixVersion() throws Exception {
- try (final ArjArchiveInputStream in = new ArjArchiveInputStream(newInputStream("bla.unix.arj"))) {
+ try (ArjArchiveInputStream in = new ArjArchiveInputStream(newInputStream("bla.unix.arj"))) {
final ArjArchiveEntry entry = in.getNextEntry();
assertEquals("test1.xml", entry.getName());
assertEquals(30, entry.getSize());
@@ -115,7 +115,7 @@ public class ArjArchiveInputStreamTest extends AbstractTest {
@Test
public void testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
try (InputStream in = newInputStream("bla.arj");
- ArjArchiveInputStream archive = new ArjArchiveInputStream(in)) {
+ ArjArchiveInputStream archive = new ArjArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read());
diff --git a/src/test/java/org/apache/commons/compress/archivers/arj/CoverageTest.java b/src/test/java/org/apache/commons/compress/archivers/arj/CoverageTest.java
index 76da44b86..9b69f835c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/arj/CoverageTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/arj/CoverageTest.java
@@ -30,6 +30,7 @@ public class CoverageTest {
final LocalFileHeader lfh = new LocalFileHeader();
assertNotNull(lfh.toString());
}
+
@Test
public void testHeaderInstances() {
assertNotNull(new LocalFileHeader.FileTypes());
@@ -37,6 +38,7 @@ public class CoverageTest {
assertNotNull(new LocalFileHeader.Flags());
assertNotNull(new MainHeader.Flags());
}
+
@Test
public void testHostOsInstance() {
final HostOs hostOs = new HostOs();
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java
index ba046a7e1..e82f0e337 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java
@@ -39,7 +39,7 @@ public class CpioArchiveInputStreamTest extends AbstractTest {
expected.append("<empty/>\n");
final StringBuilder result = new StringBuilder();
- try (final CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("bla.cpio"))) {
+ try (CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("bla.cpio"))) {
CpioArchiveEntry entry;
while ((entry = in.getNextEntry()) != null) {
@@ -56,7 +56,7 @@ public class CpioArchiveInputStreamTest extends AbstractTest {
@Test
public void testCpioUnarchiveCreatedByRedlineRpm() throws Exception {
int count = 0;
- try (final CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("redline.cpio"))) {
+ try (CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("redline.cpio"))) {
CpioArchiveEntry entry;
while ((entry = in.getNextEntry()) != null) {
@@ -71,7 +71,7 @@ public class CpioArchiveInputStreamTest extends AbstractTest {
@Test
public void testCpioUnarchiveMultibyteCharName() throws Exception {
int count = 0;
- try (final CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("COMPRESS-459.cpio"), CharsetNames.UTF_8)) {
+ try (CpioArchiveInputStream in = new CpioArchiveInputStream(newInputStream("COMPRESS-459.cpio"), CharsetNames.UTF_8)) {
CpioArchiveEntry entry;
while ((entry = in.getNextEntry()) != null) {
@@ -86,7 +86,8 @@ public class CpioArchiveInputStreamTest extends AbstractTest {
@Test
public void testMultiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
final byte[] buf = new byte[2];
- try (InputStream in = newInputStream("bla.cpio"); CpioArchiveInputStream archive = new CpioArchiveInputStream(in)) {
+ try (InputStream in = newInputStream("bla.cpio");
+ CpioArchiveInputStream archive = new CpioArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read(buf));
@@ -96,7 +97,8 @@ public class CpioArchiveInputStreamTest extends AbstractTest {
@Test
public void testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
- try (InputStream in = newInputStream("bla.cpio"); CpioArchiveInputStream archive = new CpioArchiveInputStream(in)) {
+ try (InputStream in = newInputStream("bla.cpio");
+ CpioArchiveInputStream archive = new CpioArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read());
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java
index ecd6170f3..4e5fc8017 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStreamTest.java
@@ -34,7 +34,7 @@ public class CpioArchiveOutputStreamTest extends AbstractTest {
public void testWriteOldBinary() throws Exception {
final File f = getFile("test1.xml");
final File output = newTempFile("test.cpio");
- try (final OutputStream out = Files.newOutputStream(output.toPath());
+ try (OutputStream out = Files.newOutputStream(output.toPath());
CpioArchiveOutputStream os = new CpioArchiveOutputStream(out, CpioConstants.FORMAT_OLD_BINARY)) {
os.putArchiveEntry(new CpioArchiveEntry(CpioConstants.FORMAT_OLD_BINARY, f, "test1.xml"));
Files.copy(f.toPath(), os);
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveTest.java
index 5295e059b..50578be66 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveTest.java
@@ -36,7 +36,7 @@ public class CpioArchiveTest {
public static Stream<Arguments> factory() {
return Stream.of(Arguments.of(CpioConstants.FORMAT_NEW), Arguments.of(CpioConstants.FORMAT_NEW_CRC), Arguments.of(CpioConstants.FORMAT_OLD_ASCII),
- Arguments.of(CpioConstants.FORMAT_OLD_BINARY));
+ Arguments.of(CpioConstants.FORMAT_OLD_BINARY));
}
@ParameterizedTest
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java
index 2989ddeb3..5a6ca4f47 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java
@@ -44,22 +44,22 @@ public class CpioUtilTest {
@Test
public void testOldBinMagic2ByteArrayNotSwapped() {
- assertArrayEquals(new byte[] {(byte) 0xc7, 0x71}, CpioUtil.long2byteArray(CpioConstants.MAGIC_OLD_BINARY, 2, false));
+ assertArrayEquals(new byte[] { (byte) 0xc7, 0x71 }, CpioUtil.long2byteArray(CpioConstants.MAGIC_OLD_BINARY, 2, false));
}
@Test
public void testOldBinMagic2ByteArraySwapped() {
- assertArrayEquals(new byte[] {0x71, (byte) 0xc7,}, CpioUtil.long2byteArray(CpioConstants.MAGIC_OLD_BINARY, 2, true));
+ assertArrayEquals(new byte[] { 0x71, (byte) 0xc7, }, CpioUtil.long2byteArray(CpioConstants.MAGIC_OLD_BINARY, 2, true));
}
@Test
public void testOldBinMagicFromByteArrayNotSwapped() {
- assertEquals(CpioConstants.MAGIC_OLD_BINARY, CpioUtil.byteArray2long(new byte[] {(byte) 0xc7, 0x71}, false));
+ assertEquals(CpioConstants.MAGIC_OLD_BINARY, CpioUtil.byteArray2long(new byte[] { (byte) 0xc7, 0x71 }, false));
}
@Test
public void testOldBinMagicFromByteArraySwapped() {
- assertEquals(CpioConstants.MAGIC_OLD_BINARY, CpioUtil.byteArray2long(new byte[] {0x71, (byte) 0xc7}, true));
+ assertEquals(CpioConstants.MAGIC_OLD_BINARY, CpioUtil.byteArray2long(new byte[] { 0x71, (byte) 0xc7 }, true));
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntryTest.java
index 5406a3eda..203ede8fd 100644
--- a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntryTest.java
@@ -25,9 +25,7 @@ import org.junit.jupiter.api.Test;
public class DumpArchiveEntryTest {
@Test
public void testPublicNameAddsTrailingSlashForDirectories() {
- final DumpArchiveEntry ent = new DumpArchiveEntry("foo", "bar", -1,
- DumpArchiveEntry.TYPE
- .DIRECTORY);
+ final DumpArchiveEntry ent = new DumpArchiveEntry("foo", "bar", -1, DumpArchiveEntry.TYPE.DIRECTORY);
assertEquals("bar", ent.getSimpleName());
assertEquals("foo", ent.getOriginalName());
assertEquals("foo/", ent.getName());
@@ -41,4 +39,4 @@ public class DumpArchiveEntryTest {
assertEquals("foo", ent.getName());
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java
index 29402fd7d..bb6e41d8b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java
@@ -36,7 +36,7 @@ public class DumpArchiveInputStreamTest extends AbstractTest {
@Test
public void testConsumesArchiveCompletely() throws Exception {
- try (final InputStream is = DumpArchiveInputStreamTest.class.getResourceAsStream("/archive_with_trailer.dump");
+ try (InputStream is = DumpArchiveInputStreamTest.class.getResourceAsStream("/archive_with_trailer.dump");
DumpArchiveInputStream dump = new DumpArchiveInputStream(is)) {
while (dump.getNextDumpEntry() != null) {
// just consume the archive
@@ -52,7 +52,7 @@ public class DumpArchiveInputStreamTest extends AbstractTest {
public void testMultiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
final byte[] buf = new byte[2];
try (InputStream in = newInputStream("bla.dump");
- DumpArchiveInputStream archive = new DumpArchiveInputStream(in)) {
+ DumpArchiveInputStream archive = new DumpArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read(buf));
@@ -63,8 +63,7 @@ public class DumpArchiveInputStreamTest extends AbstractTest {
@Test
public void testNotADumpArchive() throws Exception {
try (InputStream is = newInputStream("bla.zip")) {
- final ArchiveException ex = assertThrows(ArchiveException.class, () -> new DumpArchiveInputStream(is).close(),
- "expected an exception");
+ final ArchiveException ex = assertThrows(ArchiveException.class, () -> new DumpArchiveInputStream(is).close(), "expected an exception");
assertTrue(ex.getCause() instanceof ShortFileException);
}
}
@@ -72,8 +71,7 @@ public class DumpArchiveInputStreamTest extends AbstractTest {
@Test
public void testNotADumpArchiveButBigEnough() throws Exception {
try (InputStream is = newInputStream("zip64support.tar.bz2")) {
- final ArchiveException ex = assertThrows(ArchiveException.class, () -> new DumpArchiveInputStream(is).close(),
- "expected an exception");
+ final ArchiveException ex = assertThrows(ArchiveException.class, () -> new DumpArchiveInputStream(is).close(), "expected an exception");
assertInstanceOf(UnrecognizedFormatException.class, ex.getCause());
}
}
@@ -81,7 +79,7 @@ public class DumpArchiveInputStreamTest extends AbstractTest {
@Test
public void testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
try (InputStream in = newInputStream("bla.dump");
- DumpArchiveInputStream archive = new DumpArchiveInputStream(in)) {
+ DumpArchiveInputStream archive = new DumpArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read());
diff --git a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java
index 89a3ad640..7559a535d 100644
--- a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java
@@ -26,26 +26,16 @@ public class DumpArchiveUtilTest {
@Test
public void testConvert16() {
- assertEquals(0xABCD,
- DumpArchiveUtil.convert16(new byte[] {
- (byte) 0xCD, (byte) 0xAB
- }, 0));
+ assertEquals(0xABCD, DumpArchiveUtil.convert16(new byte[] { (byte) 0xCD, (byte) 0xAB }, 0));
}
@Test
public void testConvert32() {
- assertEquals(0xABCDEF01,
- DumpArchiveUtil.convert32(new byte[] {
- 1, (byte) 0xEF, (byte) 0xCD, (byte) 0xAB
- }, 0));
+ assertEquals(0xABCDEF01, DumpArchiveUtil.convert32(new byte[] { 1, (byte) 0xEF, (byte) 0xCD, (byte) 0xAB }, 0));
}
@Test
public void testConvert64() {
- assertEquals(0xABCDEF0123456780L,
- DumpArchiveUtil.convert64(new byte[] {
- (byte) 0x80, 0x67, 0x45, 0x23, 1, (byte) 0xEF,
- (byte) 0xCD, (byte) 0xAB
- }, 0));
+ assertEquals(0xABCDEF0123456780L, DumpArchiveUtil.convert64(new byte[] { (byte) 0x80, 0x67, 0x45, 0x23, 1, (byte) 0xEF, (byte) 0xCD, (byte) 0xAB }, 0));
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
index b4b6b3be7..48b4883f5 100644
--- a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java
@@ -53,11 +53,7 @@ public class ParameterizedArchiverTest extends AbstractTest {
// and reading logic would be different as well - see
// SevenZArchiverTest class
public static Stream<Arguments> data() {
- return Stream.of(
- Arguments.of("tar"),
- Arguments.of("cpio"),
- Arguments.of("zip")
- );
+ return Stream.of(Arguments.of("tar"), Arguments.of("cpio"), Arguments.of("zip"));
}
private File target;
@@ -68,7 +64,7 @@ public class ParameterizedArchiverTest extends AbstractTest {
// TODO How to parameterize a BeforeEach method?
setUp(format);
try (OutputStream os = Files.newOutputStream(target.toPath());
- ArchiveOutputStream<?> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, os)) {
+ ArchiveOutputStream<?> aos = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(format, os)) {
new Archiver().create(aos, getTempDirFile());
}
verifyContent(format);
@@ -80,8 +76,7 @@ public class ParameterizedArchiverTest extends AbstractTest {
assertTrue(entry.isDirectory(), expectedName + " is not a directory");
}
- private void assertHelloWorld(final String expectedName, final String suffix, final ArchiveEntry entry, final InputStream is)
- throws IOException {
+ private void assertHelloWorld(final String expectedName, final String suffix, final ArchiveEntry entry, final InputStream is) throws IOException {
assertNotNull(entry, () -> expectedName + " does not exists");
assertEquals(expectedName, entry.getName());
assertFalse(entry.isDirectory(), expectedName + " is a directory");
@@ -95,8 +90,8 @@ public class ParameterizedArchiverTest extends AbstractTest {
public void channelVersion(final String format) throws Exception {
// TODO How to parameterize a BeforeEach method?
setUp(format);
- try (SeekableByteChannel c = FileChannel.open(target.toPath(), StandardOpenOption.WRITE,
- StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
+ try (SeekableByteChannel c = FileChannel.open(target.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE,
+ StandardOpenOption.TRUNCATE_EXISTING)) {
new Archiver().create(format, c, getTempDirFile());
}
verifyContent(format);
@@ -136,8 +131,8 @@ public class ParameterizedArchiverTest extends AbstractTest {
private void verifyContent(final String format) throws IOException, ArchiveException {
try (InputStream is = Files.newInputStream(target.toPath());
- BufferedInputStream bis = new BufferedInputStream(is);
- ArchiveInputStream<?> ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(format, bis)) {
+ BufferedInputStream bis = new BufferedInputStream(is);
+ ArchiveInputStream<?> ais = ArchiveStreamFactory.DEFAULT.createArchiveInputStream(format, bis)) {
assertDir("a", ais.getNextEntry());
assertDir("a/b", ais.getNextEntry());
final ArchiveEntry n = ais.getNextEntry();
diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java
index 81b80bbbc..a7fa5fdf7 100644
--- a/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java
@@ -51,8 +51,7 @@ public class SevenZArchiverTest extends AbstractTest {
assertTrue(entry.isDirectory(), expectedName + " is not a directory");
}
- private void assertHelloWorld(final String expectedName, final String suffix, final ArchiveEntry entry, final SevenZFile z)
- throws IOException {
+ private void assertHelloWorld(final String expectedName, final String suffix, final ArchiveEntry entry, final SevenZFile z) throws IOException {
assertNotNull(entry, () -> expectedName + " does not exists");
assertEquals(expectedName, entry.getName());
assertFalse(entry.isDirectory(), expectedName + " is a directory");
@@ -78,8 +77,8 @@ public class SevenZArchiverTest extends AbstractTest {
@Test
public void testChannelVersion() throws IOException, ArchiveException {
- try (SeekableByteChannel c = FileChannel.open(target.toPath(), StandardOpenOption.WRITE,
- StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
+ try (SeekableByteChannel c = FileChannel.open(target.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE,
+ StandardOpenOption.TRUNCATE_EXISTING)) {
new Archiver().create("7z", c, getTempDirFile());
}
verifyContent();
@@ -102,7 +101,7 @@ public class SevenZArchiverTest extends AbstractTest {
@Test
public void testUnknownFormat() throws IOException {
try (SeekableByteChannel c = FileChannel.open(target.toPath(), StandardOpenOption.WRITE, StandardOpenOption.CREATE,
- StandardOpenOption.TRUNCATE_EXISTING)) {
+ StandardOpenOption.TRUNCATE_EXISTING)) {
assertThrows(ArchiveException.class, () -> new Archiver().create("unknown format", c, getTempDirFile()));
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/jar/ExpandApkTest.java b/src/test/java/org/apache/commons/compress/archivers/jar/ExpandApkTest.java
index f4063c1db..a8256f793 100644
--- a/src/test/java/org/apache/commons/compress/archivers/jar/ExpandApkTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/jar/ExpandApkTest.java
@@ -38,9 +38,8 @@ public class ExpandApkTest {
@Test
public void test() throws IOException {
- Streams
- .failableStream(
+ Streams.failableStream(
PathUtils.walk(Paths.get("src/test/resources/android"), new SuffixFileFilter("." + ArchiveStreamFactory.APK, IOCase.INSENSITIVE), 100, false))
- .forEach(path -> new Expander().expand(ArchiveStreamFactory.APK, println(path), null));
+ .forEach(path -> new Expander().expand(ArchiveStreamFactory.APK, println(path), null));
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java
index ee4834c21..8940be61e 100644
--- a/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java
@@ -69,4 +69,4 @@ public class JarArchiveOutputStreamTest extends AbstractTempDirTest {
}
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveInputStream.java b/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveInputStream.java
index 0d3782499..6f6487238 100644
--- a/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveInputStream.java
+++ b/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveInputStream.java
@@ -28,7 +28,7 @@ public final class MemoryArchiveInputStream extends ArchiveInputStream<MemoryArc
private final String[] content;
private int p;
- public MemoryArchiveInputStream( final String[][] pFiles ) {
+ public MemoryArchiveInputStream(final String[][] pFiles) {
final int pFilesLength = pFiles.length;
fileNames = new String[pFilesLength];
content = new String[pFilesLength];
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/FolderTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/FolderTest.java
index e93f64986..ea9097f53 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/FolderTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/FolderTest.java
@@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
-
/**
* Unit tests for class {@link Folder}.
*
@@ -30,7 +29,6 @@ import org.junit.jupiter.api.Test;
*/
public class FolderTest {
-
@Test
public void testFindBindPairForInStream() {
@@ -44,7 +42,6 @@ public class FolderTest {
}
-
@Test
public void testGetUnpackSizeForCoderOne() {
@@ -57,7 +54,6 @@ public class FolderTest {
}
-
@Test
public void testGetUnpackSizeOne() {
@@ -73,7 +69,6 @@ public class FolderTest {
}
-
@Test
public void testGetUnpackSizeTwo() {
@@ -83,5 +78,4 @@ public class FolderTest {
}
-
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java
index 258176848..d307709ac 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java
@@ -122,5 +122,4 @@ public class SevenZArchiveEntryTest {
assertThrows(UnsupportedOperationException.class, () -> new SevenZArchiveEntry().getLastModifiedDate());
}
-
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
index 0c0789ba7..2abc70f70 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
@@ -463,11 +463,21 @@ public class SevenZFileTest extends AbstractTest {
@Test
public void testRandomAccessTogetherWithSequentialAccess() throws Exception {
try (SevenZFile sevenZFile = new SevenZFile(getFile("COMPRESS-256.7z"))) {
- final String testTxtContents = "111111111111111111111111111000101011\n" + "111111111111111111111111111000101011\n"
- + "111111111111111111111111111000101011\n" + "111111111111111111111111111000101011\n" + "111111111111111111111111111000101011\n"
- + "111111111111111111111111111000101011\n" + "111111111111111111111111111000101011\n" + "111111111111111111111111111000101011\n"
- + "111111111111111111111111111000101011\n" + "111111111111111111111111111000101011";
- final String filesTxtContents = "0xxxxxxxxx10xxxxxxxx20xxxxxxxx30xxxxxxxx40xxxxxxxx50xxxxxxxx60xxxxxxxx70xxxxxxxx80xxxxxxxx90xxxxxxxx100xxxxxxx110xxxxxxx120xxxxxxx130xxxxxxx -> 0yyyyyyyyy10yyyyyyyy20yyyyyyyy30yyyyyyyy40yyyyyyyy50yyyyyyyy60yyyyyyyy70yyyyyyyy80yyyyyyyy90yyyyyyyy100yyyyyyy110yyyyyyy120yyyyyyy130yyyyyyy\n";
+ // @formatter:off
+ final String testTxtContents = "111111111111111111111111111000101011\n"
+ + "111111111111111111111111111000101011\n"
+ + "111111111111111111111111111000101011\n"
+ + "111111111111111111111111111000101011\n"
+ + "111111111111111111111111111000101011\n"
+ + "111111111111111111111111111000101011\n"
+ + "111111111111111111111111111000101011\n"
+ + "111111111111111111111111111000101011\n"
+ + "111111111111111111111111111000101011\n"
+ + "111111111111111111111111111000101011";
+ final String filesTxtContents = "0xxxxxxxxx10xxxxxxxx20xxxxxxxx30xxxxxxxx40xxxxxxxx50xxxxxxxx60xxxxxxxx70xxxxxxxx80xxxxxxxx90xxxxxxxx100"
+ + "xxxxxxx110xxxxxxx120xxxxxxx130xxxxxxx -> 0yyyyyyyyy10yyyyyyyy20yyyyyyyy30yyyyyyyy40yyyyyyyy50yyyyyyyy60yyyyyyyy70yyyyyyyy80"
+ + "yyyyyyyy90yyyyyyyy100yyyyyyy110yyyyyyy120yyyyyyy130yyyyyyy\n";
+ // @formatter:off
int off;
byte[] contents;
@@ -787,7 +797,7 @@ public class SevenZFileTest extends AbstractTest {
@Test
public void testRetrieveInputStreamForAllEntriesWithoutCRCMultipleTimes() throws IOException {
- try (final SevenZOutputFile out = new SevenZOutputFile(newTempFile("test.7z"))) {
+ try (SevenZOutputFile out = new SevenZOutputFile(newTempFile("test.7z"))) {
final Path inputFile = Files.createTempFile("SevenZTestTemp", "");
final SevenZArchiveEntry entry = out.createArchiveEntry(inputFile.toFile(), "test.txt");
@@ -809,7 +819,7 @@ public class SevenZFileTest extends AbstractTest {
@Test
public void testRetrieveInputStreamForShuffledEntries() throws IOException {
- try (final SevenZFile sevenZFile = new SevenZFile(getFile("COMPRESS-348.7z"))) {
+ try (SevenZFile sevenZFile = new SevenZFile(getFile("COMPRESS-348.7z"))) {
final List<SevenZArchiveEntry> entries = (List<SevenZArchiveEntry>) sevenZFile.getEntries();
Collections.shuffle(entries);
for (final SevenZArchiveEntry entry : entries) {
@@ -820,7 +830,7 @@ public class SevenZFileTest extends AbstractTest {
@Test
public void testSevenZWithEOS() throws IOException {
- try (final SevenZFile sevenZFile = new SevenZFile(getFile("lzma-with-eos.7z"))) {
+ try (SevenZFile sevenZFile = new SevenZFile(getFile("lzma-with-eos.7z"))) {
final List<SevenZArchiveEntry> entries = (List<SevenZArchiveEntry>) sevenZFile.getEntries();
for (final SevenZArchiveEntry entry : entries) {
read(sevenZFile, entry);
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java
index edba49b97..e4413e76f 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZNativeHeapTest.java
@@ -40,7 +40,7 @@ public class SevenZNativeHeapTest extends AbstractTest {
final AtomicBoolean isEnded = new AtomicBoolean();
- public DelegatingDeflater(final Deflater deflater) {
+ DelegatingDeflater(final Deflater deflater) {
this.deflater = deflater;
}
@@ -140,7 +140,6 @@ public class SevenZNativeHeapTest extends AbstractTest {
deflater.setStrategy(strategy);
}
-
}
private static final class DelegatingInflater extends Inflater {
@@ -148,7 +147,8 @@ public class SevenZNativeHeapTest extends AbstractTest {
private final Inflater inflater;
final AtomicBoolean isEnded = new AtomicBoolean();
- public DelegatingInflater(final Inflater inflater) {
+
+ DelegatingInflater(final Inflater inflater) {
this.inflater = inflater;
}
@@ -244,8 +244,7 @@ public class SevenZNativeHeapTest extends AbstractTest {
public void testEndDeflaterOnCloseStream() throws Exception {
final Coders.DeflateDecoder deflateDecoder = new DeflateDecoder();
final DelegatingDeflater delegatingDeflater;
- try (final DeflateDecoderOutputStream outputStream = (DeflateDecoderOutputStream) deflateDecoder
- .encode(new ByteArrayOutputStream(), 9)) {
+ try (DeflateDecoderOutputStream outputStream = (DeflateDecoderOutputStream) deflateDecoder.encode(new ByteArrayOutputStream(), 9)) {
delegatingDeflater = new DelegatingDeflater(outputStream.deflater);
outputStream.deflater = delegatingDeflater;
}
@@ -257,8 +256,8 @@ public class SevenZNativeHeapTest extends AbstractTest {
public void testEndInflaterOnCloseStream() throws Exception {
final Coders.DeflateDecoder deflateDecoder = new DeflateDecoder();
final DelegatingInflater delegatingInflater;
- try (final DeflateDecoderInputStream inputStream = (DeflateDecoderInputStream) deflateDecoder.decode("dummy",
- new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY), 0, null, null, Integer.MAX_VALUE)) {
+ try (DeflateDecoderInputStream inputStream = (DeflateDecoderInputStream) deflateDecoder.decode("dummy",
+ new ByteArrayInputStream(ByteUtils.EMPTY_BYTE_ARRAY), 0, null, null, Integer.MAX_VALUE)) {
delegatingInflater = new DelegatingInflater(inputStream.inflater);
inputStream.inflater = delegatingInflater;
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
index 1b8512f15..a3834bb46 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
@@ -96,7 +96,7 @@ public class SevenZOutputFileTest extends AbstractTest {
}
private void createAndReadBack(final File output, final Iterable<SevenZMethodConfiguration> methods) throws Exception {
- try (final SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
+ try (SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
outArchive.setContentMethods(methods);
addFile(outArchive, 0, true);
}
@@ -107,7 +107,7 @@ public class SevenZOutputFileTest extends AbstractTest {
}
private void createAndReadBack(final SeekableInMemoryByteChannel output, final Iterable<SevenZMethodConfiguration> methods) throws Exception {
- try (final SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
+ try (SevenZOutputFile outArchive = new SevenZOutputFile(output)) {
outArchive.setContentMethods(methods);
addFile(outArchive, 0, true);
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java b/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java
index 2b58c4593..79f442fb5 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java
@@ -37,8 +37,8 @@ public class BigFilesIT extends AbstractTest {
private void readFileBiggerThan8GByte(final String name) throws Exception {
try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(name)));
- GzipCompressorInputStream gzin = new GzipCompressorInputStream(in);
- TarArchiveInputStream tin = new TarArchiveInputStream(gzin)) {
+ GzipCompressorInputStream gzin = new GzipCompressorInputStream(in);
+ TarArchiveInputStream tin = new TarArchiveInputStream(gzin)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertEquals(8200L * 1024 * 1024, e.getSize());
@@ -74,8 +74,8 @@ public class BigFilesIT extends AbstractTest {
@Test
public void testReadFileHeadersOfArchiveBiggerThan8GByte() throws Exception {
try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath("8.posix.tar.gz")));
- GzipCompressorInputStream gzin = new GzipCompressorInputStream(in);
- TarArchiveInputStream tin = new TarArchiveInputStream(gzin)) {
+ GzipCompressorInputStream gzin = new GzipCompressorInputStream(in);
+ TarArchiveInputStream tin = new TarArchiveInputStream(gzin)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertNull(tin.getNextTarEntry());
@@ -87,11 +87,11 @@ public class BigFilesIT extends AbstractTest {
final Path file = getPath("8.posix.tar.gz");
final Path output = tempResultDir.toPath().resolve("8.posix.tar");
try (InputStream in = new BufferedInputStream(Files.newInputStream(file));
- GzipCompressorInputStream gzin = new GzipCompressorInputStream(in)) {
+ GzipCompressorInputStream gzin = new GzipCompressorInputStream(in)) {
Files.copy(gzin, output, StandardCopyOption.REPLACE_EXISTING);
}
- try (final TarFile tarFile = new TarFile(output)) {
+ try (TarFile tarFile = new TarFile(output)) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertEquals(1, entries.size());
assertNotNull(entries.get(0));
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/FileTimesIT.java b/src/test/java/org/apache/commons/compress/archivers/tar/FileTimesIT.java
index 97c28056c..ed8d6c0ea 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/FileTimesIT.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/FileTimesIT.java
@@ -47,8 +47,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarEpax() throws Exception {
final String file = "COMPRESS-612/test-times-epax-folder.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -77,8 +77,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarExustar() throws Exception {
final String file = "COMPRESS-612/test-times-exustar-folder.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertEquals("name", "test/", e.getName());
@@ -107,8 +107,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarGnu() throws Exception {
final String file = "COMPRESS-612/test-times-gnu.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -125,8 +125,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarGnuIncremental() throws Exception {
final String file = "COMPRESS-612/test-times-gnu-incremental.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -152,8 +152,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarGnuTar() throws Exception {
final String file = "COMPRESS-612/test-times-gnutar.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -169,8 +169,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarOldBsdTar() throws Exception {
final String file = "COMPRESS-612/test-times-oldbsdtar.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -187,8 +187,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarOldGnu() throws Exception {
final String file = "COMPRESS-612/test-times-oldgnu.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -205,8 +205,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarOldGnuIncremental() throws Exception {
final String file = "COMPRESS-612/test-times-oldgnu-incremental.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -232,8 +232,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarPax() throws Exception {
final String file = "COMPRESS-612/test-times-pax-folder.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -263,8 +263,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarPosix() throws Exception {
final String file = "COMPRESS-612/test-times-posix.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -281,8 +281,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarPosixLibArchive() throws Exception {
final String file = "COMPRESS-612/test-times-bsd-folder.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -312,8 +312,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarPosixLinux() throws Exception {
final String file = "COMPRESS-612/test-times-posix-linux.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -329,8 +329,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarStarFolder() throws Exception {
final String file = "COMPRESS-612/test-times-star-folder.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -358,8 +358,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarUstar() throws Exception {
final String file = "COMPRESS-612/test-times-ustar.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -375,8 +375,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarV7() throws Exception {
final String file = "COMPRESS-612/test-times-v7.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -392,8 +392,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarXstar() throws Exception {
final String file = "COMPRESS-612/test-times-xstar.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -409,8 +409,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarXstarFolder() throws Exception {
final String file = "COMPRESS-612/test-times-xstar-folder.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -438,8 +438,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarXstarIncremental() throws Exception {
final String file = "COMPRESS-612/test-times-xstar-incremental.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -464,8 +464,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarXustar() throws Exception {
final String file = "COMPRESS-612/test-times-xustar.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
final TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -481,8 +481,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarXustarFolder() throws Exception {
final String file = "COMPRESS-612/test-times-xustar-folder.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
@@ -510,8 +510,8 @@ public class FileTimesIT extends AbstractTest {
@Test
public void testReadTimeFromTarXustarIncremental() throws Exception {
final String file = "COMPRESS-612/test-times-xustar-incremental.tar";
- try (final InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
- final TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(getPath(file)));
+ TarArchiveInputStream tin = new TarArchiveInputStream(in)) {
TarArchiveEntry e = tin.getNextTarEntry();
assertNotNull(e);
assertTrue(e.getExtraPaxHeaders().isEmpty());
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
index 44c8acc64..3b975a900 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
@@ -337,8 +337,8 @@ public class SparseFilesTest extends AbstractTest {
@DisabledOnOs(OS.WINDOWS)
public void testTarFileExtractOldGNU() throws IOException, InterruptedException {
final File file = getFile("oldgnu_sparse.tar");
- try (final InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile");
- final TarFile tarFile = new TarFile(file)) {
+ try (InputStream sparseFileInputStream = extractTarAndGetInputStream(file, "sparsefile");
+ TarFile tarFile = new TarFile(file)) {
final TarArchiveEntry entry = tarFile.getEntries().get(0);
try (InputStream tarInput = tarFile.getInputStream(entry)) {
assertArrayEquals(IOUtils.toByteArray(tarInput), IOUtils.toByteArray(sparseFileInputStream));
@@ -355,7 +355,7 @@ public class SparseFilesTest extends AbstractTest {
assumeFalse(getTarBinaryHelp().startsWith("tar (GNU tar) 1.28"), "This test should be ignored if GNU tar is version 1.28");
final File file = getFile("pax_gnu_sparse.tar");
- try (final TarFile paxGnu = new TarFile(file)) {
+ try (TarFile paxGnu = new TarFile(file)) {
final List<TarArchiveEntry> entries = paxGnu.getEntries();
TarArchiveEntry entry = entries.get(0);
@@ -421,7 +421,7 @@ public class SparseFilesTest extends AbstractTest {
@Test
public void testTarFileOldGNU() throws Throwable {
final File file = getFile("oldgnu_sparse.tar");
- try (final TarFile tarFile = new TarFile(file)) {
+ try (TarFile tarFile = new TarFile(file)) {
final TarArchiveEntry ae = tarFile.getEntries().get(0);
assertEquals("sparsefile", ae.getName());
assertEquals(TarConstants.LF_GNUTYPE_SPARSE, ae.getLinkFlag());
@@ -461,7 +461,7 @@ public class SparseFilesTest extends AbstractTest {
@Test
public void testTarFilePaxGNU() throws IOException {
final File file = getFile("pax_gnu_sparse.tar");
- try (final TarFile tarFile = new TarFile(file)) {
+ try (TarFile tarFile = new TarFile(file)) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertPaxGNUEntry(entries.get(0), "0.0");
assertPaxGNUEntry(entries.get(1), "0.1");
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
index 3d3e9e944..ec04eb0b7 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
@@ -223,26 +223,27 @@ public class TarArchiveEntryTest implements TarConstants {
@Test
public void testNegativeOffsetInConstructorNotAllowed() {
// @formatter:off
- final byte[] entryContent = ("test1.xml\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u00000000644\u00000000765\u00000000765" +
- "\u000000000001142\u000010716545626\u0000012260\u0000 0\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000ustar " +
- "\u0000tcurdt\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000tcurdt\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
- "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000").getBytes(UTF_8);
+ final byte[] entryContent = (
+ "test1.xml\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u00000000644\u00000000765\u00000000765\u000000000001142\u000010716545626\u0000012260\u0000 0\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000ustar \u0000tcurdt\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000tcurdt\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
+ + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000").getBytes(UTF_8);
// @formatter:on
assertThrows(IllegalArgumentException.class,
() -> new TarArchiveEntry(entryContent, ZipEncodingHelper.getZipEncoding(CharsetNames.ISO_8859_1), false, -1));
@@ -293,13 +294,13 @@ public class TarArchiveEntryTest implements TarConstants {
@Test
public void testShouldNotWriteTimePaxHeadersByDefault() throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
final TarArchiveEntry entry = createEntryForTimeTests();
tos.putArchiveEntry(entry);
tos.write('W');
tos.closeArchiveEntry();
}
- try (final TarArchiveInputStream tis = new TarArchiveInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
+ try (TarArchiveInputStream tis = new TarArchiveInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
final TarArchiveEntry entry = tis.getNextTarEntry();
assertNotNull(entry, "couldn't get entry");
@@ -339,14 +340,14 @@ public class TarArchiveEntryTest implements TarConstants {
@Test
public void testShouldWriteTimesAsPaxHeadersForPosixMode() throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
final TarArchiveEntry entry = createEntryForTimeTests();
tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
tos.putArchiveEntry(entry);
tos.write('W');
tos.closeArchiveEntry();
}
- try (final TarArchiveInputStream tis = new TarArchiveInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
+ try (TarArchiveInputStream tis = new TarArchiveInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
final TarArchiveEntry entry = tis.getNextTarEntry();
assertNotNull(entry, "couldn't get entry");
@@ -370,7 +371,7 @@ public class TarArchiveEntryTest implements TarConstants {
@Test
public void testShouldWriteTimesAsPaxHeadersForPosixModeAndCreationTimeShouldBeUsedAsCtime() throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
final TarArchiveEntry entry = createEntryForTimeTests();
entry.setStatusChangeTime(null);
tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
@@ -378,7 +379,7 @@ public class TarArchiveEntryTest implements TarConstants {
tos.write('W');
tos.closeArchiveEntry();
}
- try (final TarArchiveInputStream tis = new TarArchiveInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
+ try (TarArchiveInputStream tis = new TarArchiveInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
final TarArchiveEntry entry = tis.getNextTarEntry();
assertNotNull(entry, "couldn't get entry");
@@ -402,14 +403,14 @@ public class TarArchiveEntryTest implements TarConstants {
@Test
public void testShouldWriteTimesForStarMode() throws IOException {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
final TarArchiveEntry entry = createEntryForTimeTests();
tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
tos.putArchiveEntry(entry);
tos.write('W');
tos.closeArchiveEntry();
}
- try (final TarArchiveInputStream tis = new TarArchiveInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
+ try (TarArchiveInputStream tis = new TarArchiveInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
final TarArchiveEntry entry = tis.getNextTarEntry();
assertNotNull(entry, "couldn't get entry");
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
index eb91675c4..d8a518b9d 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
@@ -71,10 +71,8 @@ public class TarArchiveInputStreamTest extends AbstractTest {
});
}
-
private TarArchiveInputStream getTestStream(final String name) {
- return new TarArchiveInputStream(
- TarArchiveInputStreamTest.class.getResourceAsStream(name));
+ return new TarArchiveInputStream(TarArchiveInputStreamTest.class.getResourceAsStream(name));
}
@Test
@@ -84,7 +82,7 @@ public class TarArchiveInputStreamTest extends AbstractTest {
while (entry != null) {
entry = tar.getNextTarEntry();
}
- } catch (final IOException e) {
+ } catch (IOException e) {
fail("COMPRESS-197: " + e.getMessage());
}
}
@@ -92,11 +90,15 @@ public class TarArchiveInputStreamTest extends AbstractTest {
@Test
public void testCompress558() throws IOException {
final String folderName = "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/";
- final String consumerJavaName = "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Consumer.java";
- final String producerJavaName = "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Producer.java";
+ // @formatter:off
+ final String consumerJavaName =
+ "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Consumer.java";
+ final String producerJavaName =
+ "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Producer.java";
+ // @formatter:on
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
final TarArchiveEntry rootfolder = new TarArchiveEntry(folderName);
tos.putArchiveEntry(rootfolder);
@@ -107,8 +109,8 @@ public class TarArchiveInputStreamTest extends AbstractTest {
tos.closeArchiveEntry();
}
final byte[] data = bos.toByteArray();
- try (final ByteArrayInputStream bis = new ByteArrayInputStream(data);
- final TarArchiveInputStream tis = new TarArchiveInputStream(bis)) {
+ try (ByteArrayInputStream bis = new ByteArrayInputStream(data);
+ TarArchiveInputStream tis = new TarArchiveInputStream(bis)) {
assertEquals(folderName, tis.getNextTarEntry().getName());
assertEquals(TarConstants.LF_DIR, tis.getCurrentEntry().getLinkFlag());
assertEquals(consumerJavaName, tis.getNextTarEntry().getName());
@@ -151,7 +153,7 @@ public class TarArchiveInputStreamTest extends AbstractTest {
// -----------------------
final String fileName = "/" + dirDirectory + "/" + subDir;
final File tarF = new File(rootPath + "/tar" + i + ".tar");
- try (final OutputStream dest = Files.newOutputStream(tarF.toPath())) {
+ try (OutputStream dest = Files.newOutputStream(tarF.toPath())) {
final TarArchiveOutputStream out = new TarArchiveOutputStream(new BufferedOutputStream(dest));
out.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
out.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
@@ -167,8 +169,8 @@ public class TarArchiveInputStreamTest extends AbstractTest {
// -----------------------
// untar these tars
// -----------------------
- try (final InputStream is = Files.newInputStream(tarF.toPath());
- final TarArchiveInputStream debInputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
+ try (InputStream is = Files.newInputStream(tarF.toPath());
+ TarArchiveInputStream debInputStream = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
TarArchiveEntry outEntry;
while ((outEntry = debInputStream.getNextEntry()) != null) {
assertTrue(outEntry.getName().endsWith("/"), outEntry.getName());
@@ -203,7 +205,7 @@ public class TarArchiveInputStreamTest extends AbstractTest {
public void testMultiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
final byte[] buf = new byte[2];
try (InputStream in = newInputStream("bla.tar");
- TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read(buf));
@@ -214,7 +216,7 @@ public class TarArchiveInputStreamTest extends AbstractTest {
@Test
public void testParseTarTruncatedInContent() throws IOException {
try (InputStream in = newInputStream("COMPRESS-544_truncated_in_content.tar");
- TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
getNextEntryUntilIOException(archive);
}
}
@@ -222,21 +224,23 @@ public class TarArchiveInputStreamTest extends AbstractTest {
@Test
public void testParseTarTruncatedInPadding() throws IOException {
try (InputStream in = newInputStream("COMPRESS-544_truncated_in_padding.tar");
- TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
getNextEntryUntilIOException(archive);
}
}
@Test
public void testParseTarWithNonNumberPaxHeaders() throws IOException {
- try (InputStream in = newInputStream("COMPRESS-529.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ try (InputStream in = newInputStream("COMPRESS-529.tar");
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
assertThrows(IOException.class, () -> archive.getNextEntry());
}
}
+
@Test
public void testParseTarWithSpecialPaxHeaders() throws IOException {
try (InputStream in = newInputStream("COMPRESS-530.tar");
- TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
assertThrows(IOException.class, () -> archive.getNextEntry());
assertThrows(IOException.class, () -> IOUtils.toByteArray(archive));
}
@@ -255,14 +259,15 @@ public class TarArchiveInputStreamTest extends AbstractTest {
}
assertEquals(31, count);
}
- } catch (final IOException e) {
+ } catch (IOException e) {
fail("COMPRESS-245: " + e.getMessage());
}
}
@Test
public void testRejectsArchivesWithNegativeSizes() throws Exception {
- try (InputStream in = newInputStream("COMPRESS-569.tar"); TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ try (InputStream in = newInputStream("COMPRESS-569.tar");
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
getNextEntryUntilIOException(archive);
}
}
@@ -273,7 +278,7 @@ public class TarArchiveInputStreamTest extends AbstractTest {
@Test
public void testShouldConsumeArchiveCompletely() throws Exception {
try (InputStream is = TarArchiveInputStreamTest.class.getResourceAsStream("/archive_with_trailer.tar");
- TarArchiveInputStream tar = new TarArchiveInputStream(is)) {
+ TarArchiveInputStream tar = new TarArchiveInputStream(is)) {
while (tar.getNextTarEntry() != null) {
// just consume the archive
}
@@ -298,7 +303,7 @@ public class TarArchiveInputStreamTest extends AbstractTest {
}
final byte[] data = bos.toByteArray();
final ByteArrayInputStream bis = new ByteArrayInputStream(data);
- try (final TarArchiveInputStream tis = new TarArchiveInputStream(bis)) {
+ try (TarArchiveInputStream tis = new TarArchiveInputStream(bis)) {
final TarArchiveEntry t = tis.getNextTarEntry();
assertEquals(4294967294L, t.getLongGroupId());
}
@@ -311,10 +316,10 @@ public class TarArchiveInputStreamTest extends AbstractTest {
public void testShouldReadGNULongNameEntryWithWrongName() throws Exception {
try (TarArchiveInputStream is = getTestStream("/COMPRESS-324.tar")) {
final TarArchiveEntry entry = is.getNextTarEntry();
- assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890"
- + "1234567890123456789012345678901234567890123456789012345678901234567890"
+ assertEquals(
+ "1234567890123456789012345678901234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890123456789012345678901234567890"
- + "1234567890123456789012345678901234567890.txt",
+ + "1234567890123456789012345678901234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890.txt",
entry.getName());
}
}
@@ -336,13 +341,10 @@ public class TarArchiveInputStreamTest extends AbstractTest {
}
@Test
- public void testShouldUseSpecifiedEncodingWhenReadingGNULongNames()
- throws Exception {
+ public void testShouldUseSpecifiedEncodingWhenReadingGNULongNames() throws Exception {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final String encoding = CharsetNames.UTF_16;
- final String name = "1234567890123456789012345678901234567890123456789"
- + "01234567890123456789012345678901234567890123456789"
- + "01234567890\u00e4";
+ final String name = "1234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" + "01234567890\u00e4";
try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, encoding)) {
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
final TarArchiveEntry t = new TarArchiveEntry(name);
@@ -362,7 +364,7 @@ public class TarArchiveInputStreamTest extends AbstractTest {
@Test
public void testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
try (InputStream in = newInputStream("bla.tar");
- TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
final ArchiveEntry e = archive.getNextEntry();
IOUtils.toByteArray(archive);
assertEquals(-1, archive.read());
@@ -413,7 +415,7 @@ public class TarArchiveInputStreamTest extends AbstractTest {
@Test
public void testThrowException() throws IOException {
try (InputStream in = newInputStream("COMPRESS-553.tar");
- TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
getNextEntryUntilIOException(archive);
}
}
@@ -421,7 +423,7 @@ public class TarArchiveInputStreamTest extends AbstractTest {
@Test
public void testThrowExceptionWithNullEntry() throws IOException {
try (InputStream in = newInputStream("COMPRESS-554.tar");
- TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
getNextEntryUntilIOException(archive);
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
index 0863436eb..ee85e7e59 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
@@ -156,11 +156,11 @@ public class TarArchiveOutputStreamTest extends AbstractTest {
public void testCount() throws Exception {
final File f = createTempFile("commons-compress-tarcount", ".tar");
try (OutputStream fos = Files.newOutputStream(f.toPath());
- final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, fos)) {
+ ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, fos)) {
final File file1 = getFile("test1.xml");
final TarArchiveEntry sEntry = new TarArchiveEntry(file1, file1.getName());
tarOut.putArchiveEntry(sEntry);
- try (final InputStream in = Files.newInputStream(file1.toPath())) {
+ try (InputStream in = Files.newInputStream(file1.toPath())) {
final byte[] buf = new byte[8192];
int read = 0;
while ((read = in.read(buf)) > 0) {
@@ -180,7 +180,10 @@ public class TarArchiveOutputStreamTest extends AbstractTest {
*/
@Test
public void testLongNameMd5Hash() throws Exception {
- final String longFileName = "a/considerably/longer/file/name/which/forces/use/of/the/long/link/header/which/appears/to/always/use/the/current/time/as/modification/date";
+ // @formatter:off
+ final String longFileName =
+ "a/considerably/longer/file/name/which/forces/use/of/the/long/link/header/which/appears/to/always/use/the/current/time/as/modification/date";
+ // @formatter:on
final Date modificationDate = new Date();
final byte[] archive1 = createTarArchiveContainingOneDirectory(longFileName, modificationDate);
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java
index d1b73d852..2677fe9df 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarFileTest.java
@@ -45,7 +45,7 @@ import org.junit.jupiter.api.Test;
public class TarFileTest extends AbstractTest {
private void datePriorToEpoch(final String archive) throws Exception {
- try (final TarFile tarFile = new TarFile(getPath(archive))) {
+ try (TarFile tarFile = new TarFile(getPath(archive))) {
final TarArchiveEntry entry = tarFile.getEntries().get(0);
assertEquals("foo", entry.getName());
assertEquals(TarConstants.LF_NORMAL, entry.getLinkFlag());
@@ -62,8 +62,8 @@ public class TarFileTest extends AbstractTest {
*/
@Test
public void testArchiveWithTrailer() throws IOException {
- try (final SeekableByteChannel channel = Files.newByteChannel(getPath("archive_with_trailer.tar"));
- final TarFile tarfile = new TarFile(channel, TarConstants.DEFAULT_BLKSIZE, TarConstants.DEFAULT_RCDSIZE, null, false)) {
+ try (SeekableByteChannel channel = Files.newByteChannel(getPath("archive_with_trailer.tar"));
+ TarFile tarfile = new TarFile(channel, TarConstants.DEFAULT_BLKSIZE, TarConstants.DEFAULT_RCDSIZE, null, false)) {
final String tarAppendix = "Hello, world!\n";
final ByteBuffer buffer = ByteBuffer.allocate(tarAppendix.length());
channel.read(buffer);
@@ -73,7 +73,7 @@ public class TarFileTest extends AbstractTest {
@Test
public void testCompress197() throws IOException {
- try (final TarFile tarFile = new TarFile(getPath("COMPRESS-197.tar"))) {
+ try (TarFile tarFile = new TarFile(getPath("COMPRESS-197.tar"))) {
// noop
}
}
@@ -81,11 +81,15 @@ public class TarFileTest extends AbstractTest {
@Test
public void testCompress558() throws IOException {
final String folderName = "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/";
- final String consumerJavaName = "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Consumer.java";
- final String producerJavaName = "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Producer.java";
+ // @formatter:off
+ final String consumerJavaName =
+ "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Consumer.java";
+ final String producerJavaName =
+ "apache-activemq-5.16.0/examples/openwire/advanced-scenarios/jms-example-exclusive-consumer/src/main/java/example/queue/exclusive/Producer.java";
+ // @formatter:on
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
final TarArchiveEntry rootfolder = new TarArchiveEntry(folderName);
tos.putArchiveEntry(rootfolder);
@@ -96,7 +100,7 @@ public class TarFileTest extends AbstractTest {
tos.closeArchiveEntry();
}
final byte[] data = bos.toByteArray();
- try (final TarFile tarFile = new TarFile(data)) {
+ try (TarFile tarFile = new TarFile(data)) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertEquals(folderName, entries.get(0).getName());
assertEquals(TarConstants.LF_DIR, entries.get(0).getLinkFlag());
@@ -142,7 +146,7 @@ public class TarFileTest extends AbstractTest {
final String fileName = "/" + dirDirectory + "/" + subDir;
final File tarF = new File(rootPath + "/tar" + i + ".tar");
try (OutputStream dest = Files.newOutputStream(tarF.toPath());
- TarArchiveOutputStream out = new TarArchiveOutputStream(new BufferedOutputStream(dest))) {
+ TarArchiveOutputStream out = new TarArchiveOutputStream(new BufferedOutputStream(dest))) {
out.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
out.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
@@ -167,8 +171,8 @@ public class TarFileTest extends AbstractTest {
@Test
public void testMultiByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
final byte[] buf = new byte[2];
- try (final TarFile tarFile = new TarFile(getPath("bla.tar"));
- final InputStream input = tarFile.getInputStream(tarFile.getEntries().get(0))) {
+ try (TarFile tarFile = new TarFile(getPath("bla.tar"));
+ InputStream input = tarFile.getInputStream(tarFile.getEntries().get(0))) {
IOUtils.toByteArray(input);
assertEquals(-1, input.read(buf));
assertEquals(-1, input.read(buf));
@@ -199,14 +203,13 @@ public class TarFileTest extends AbstractTest {
public void testReadsArchiveCompletely_COMPRESS245() {
try {
final Path tempTar = tempResultDir.toPath().resolve("COMPRESS-245.tar");
- try (final GZIPInputStream gin = new GZIPInputStream(
- Files.newInputStream(getPath("COMPRESS-245.tar.gz")))) {
+ try (GZIPInputStream gin = new GZIPInputStream(Files.newInputStream(getPath("COMPRESS-245.tar.gz")))) {
Files.copy(gin, tempTar);
}
- try (final TarFile tarFile = new TarFile(tempTar)) {
+ try (TarFile tarFile = new TarFile(tempTar)) {
assertEquals(31, tarFile.getEntries().size());
}
- } catch (final IOException e) {
+ } catch (IOException e) {
fail("COMPRESS-245: " + e.getMessage());
}
}
@@ -219,7 +222,7 @@ public class TarFileTest extends AbstractTest {
@Test
public void testShouldReadBigGid() throws Exception {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos)) {
tos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
final TarArchiveEntry t = new TarArchiveEntry("name");
t.setGroupId(4294967294L);
@@ -229,7 +232,7 @@ public class TarFileTest extends AbstractTest {
tos.closeArchiveEntry();
}
final byte[] data = bos.toByteArray();
- try (final TarFile tarFile = new TarFile(data)) {
+ try (TarFile tarFile = new TarFile(data)) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertEquals(4294967294L, entries.get(0).getLongGroupId());
}
@@ -240,12 +243,12 @@ public class TarFileTest extends AbstractTest {
*/
@Test
public void testShouldReadGNULongNameEntryWithWrongName() throws Exception {
- try (final TarFile tarFile = new TarFile(getPath("COMPRESS-324.tar"))) {
+ try (TarFile tarFile = new TarFile(getPath("COMPRESS-324.tar"))) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
- assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890"
+ assertEquals(
+ "1234567890123456789012345678901234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890123456789012345678901234567890"
- + "1234567890123456789012345678901234567890123456789012345678901234567890"
- + "1234567890123456789012345678901234567890.txt",
+ + "1234567890123456789012345678901234567890123456789012345678901234567890" + "1234567890123456789012345678901234567890.txt",
entries.get(0).getName());
}
}
@@ -257,14 +260,11 @@ public class TarFileTest extends AbstractTest {
}
@Test
- public void testShouldUseSpecifiedEncodingWhenReadingGNULongNames()
- throws Exception {
+ public void testShouldUseSpecifiedEncodingWhenReadingGNULongNames() throws Exception {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final String encoding = CharsetNames.UTF_16;
- final String name = "1234567890123456789012345678901234567890123456789"
- + "01234567890123456789012345678901234567890123456789"
- + "01234567890\u00e4";
- try (final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, encoding)) {
+ final String name = "1234567890123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" + "01234567890\u00e4";
+ try (TarArchiveOutputStream tos = new TarArchiveOutputStream(bos, encoding)) {
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
final TarArchiveEntry t = new TarArchiveEntry(name);
t.setSize(1);
@@ -273,7 +273,7 @@ public class TarFileTest extends AbstractTest {
tos.closeArchiveEntry();
}
final byte[] data = bos.toByteArray();
- try (final TarFile tarFile = new TarFile(data, encoding)) {
+ try (TarFile tarFile = new TarFile(data, encoding)) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertEquals(1, entries.size());
assertEquals(name, entries.get(0).getName());
@@ -282,8 +282,8 @@ public class TarFileTest extends AbstractTest {
@Test
public void testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws Exception {
- try (final TarFile tarFile = new TarFile(getPath("bla.tar"));
- final InputStream input = tarFile.getInputStream(tarFile.getEntries().get(0))) {
+ try (TarFile tarFile = new TarFile(getPath("bla.tar"));
+ InputStream input = tarFile.getInputStream(tarFile.getEntries().get(0))) {
IOUtils.toByteArray(input);
assertEquals(-1, input.read());
assertEquals(-1, input.read());
@@ -295,7 +295,7 @@ public class TarFileTest extends AbstractTest {
*/
@Test
public void testSkipsDevNumbersWhenEntryIsNoDevice() throws Exception {
- try (final TarFile tarFile = new TarFile(getPath("COMPRESS-417.tar"))) {
+ try (TarFile tarFile = new TarFile(getPath("COMPRESS-417.tar"))) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertEquals(2, entries.size());
assertEquals("test1.xml", entries.get(0).getName());
@@ -310,7 +310,7 @@ public class TarFileTest extends AbstractTest {
*/
@Test
public void testSurvivesBlankLinesInPaxHeader() throws Exception {
- try (final TarFile tarFile = new TarFile(getPath("COMPRESS-355.tar"))) {
+ try (TarFile tarFile = new TarFile(getPath("COMPRESS-355.tar"))) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertEquals(1, entries.size());
assertEquals("package/package.json", entries.get(0).getName());
@@ -323,7 +323,7 @@ public class TarFileTest extends AbstractTest {
*/
@Test
public void testSurvivesPaxHeaderWithNameEndingInSlash() throws Exception {
- try (final TarFile tarFile = new TarFile(getPath("COMPRESS-356.tar"))) {
+ try (TarFile tarFile = new TarFile(getPath("COMPRESS-356.tar"))) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertEquals(1, entries.size());
assertEquals("package/package.json", entries.get(0).getName());
@@ -343,7 +343,7 @@ public class TarFileTest extends AbstractTest {
@Test
public void testWorkaroundForBrokenTimeHeader() throws IOException {
- try (final TarFile tarFile = new TarFile(getPath("simple-aix-native-tar.tar"))) {
+ try (TarFile tarFile = new TarFile(getPath("simple-aix-native-tar.tar"))) {
final List<TarArchiveEntry> entries = tarFile.getEntries();
assertEquals(3, entries.size());
final TarArchiveEntry entry = entries.get(1);
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarLister.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarLister.java
index d338374dd..e3b58277b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarLister.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarLister.java
@@ -25,16 +25,19 @@ import java.nio.file.Files;
/**
* Simple command line application that lists the contents of a tar archive.
*
- * <p>The name of the archive must be given as a command line argument.</p>
- * <p>The optional second argument specifies the encoding to assume for file names.</p>
+ * <p>
+ * The name of the archive must be given as a command line argument.
+ * </p>
+ * <p>
+ * The optional second argument specifies the encoding to assume for file names.
+ * </p>
*
* @since 1.11
*/
public final class TarLister {
private static void log(final TarArchiveEntry ae) {
- final StringBuilder sb = new StringBuilder(Integer.toOctalString(ae.getMode()))
- .append(" ");
+ final StringBuilder sb = new StringBuilder(Integer.toOctalString(ae.getMode())).append(" ");
String name = ae.getUserName();
if (name != null && !name.isEmpty()) {
sb.append(name);
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java
index 78c8194b8..86e686026 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java
@@ -53,8 +53,8 @@ public class TarMemoryFileSystemTest {
Files.setAttribute(source, "posix:group", (GroupPrincipal) () -> group);
final Path target = fileSystem.getPath("original-file.tar");
- try (final OutputStream out = Files.newOutputStream(target);
- final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
+ try (OutputStream out = Files.newOutputStream(target);
+ ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
final TarArchiveEntry entry = new TarArchiveEntry(source);
tarOut.putArchiveEntry(entry);
@@ -62,8 +62,8 @@ public class TarMemoryFileSystemTest {
tarOut.closeArchiveEntry();
}
- try (final InputStream input = Files.newInputStream(target);
- final TarArchiveInputStream tarIn = new TarArchiveInputStream(input)) {
+ try (InputStream input = Files.newInputStream(target);
+ TarArchiveInputStream tarIn = new TarArchiveInputStream(input)) {
final TarArchiveEntry nextTarEntry = tarIn.getNextTarEntry();
assertEquals(user, nextTarEntry.getUserName());
@@ -79,8 +79,8 @@ public class TarMemoryFileSystemTest {
Files.write(p, "Test".getBytes(UTF_8));
final File f = File.createTempFile("commons-compress-memoryfs", ".tar");
- try (final OutputStream out = Files.newOutputStream(f.toPath());
- final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
+ try (OutputStream out = Files.newOutputStream(f.toPath());
+ ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
final TarArchiveEntry entry = new TarArchiveEntry(p);
tarOut.putArchiveEntry(entry);
@@ -98,8 +98,8 @@ public class TarMemoryFileSystemTest {
try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) {
final Path p = fileSystem.getPath("target.tar");
- try (final OutputStream out = Files.newOutputStream(p);
- final ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
+ try (OutputStream out = Files.newOutputStream(p);
+ ArchiveOutputStream<ArchiveEntry> tarOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.TAR, out)) {
final String content = "Test";
final TarArchiveEntry entry = new TarArchiveEntry("test.txt");
entry.setSize(content.length());
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
index 02656702b..22547ae3c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
@@ -90,14 +90,14 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testNegative() {
- final byte [] buffer = new byte[22];
+ final byte[] buffer = new byte[22];
TarUtils.formatUnsignedOctalString(-1, buffer, 0, buffer.length);
assertEquals("1777777777777777777777", new String(buffer, UTF_8));
}
@Test
public void testOverflow() {
- final byte [] buffer = new byte[8-1]; // a lot of the numbers have 8-byte buffers (nul term)
+ final byte[] buffer = new byte[8 - 1]; // a lot of the numbers have 8-byte buffers (nul term)
TarUtils.formatUnsignedOctalString(07777777L, buffer, 0, buffer.length);
assertEquals("7777777", new String(buffer, UTF_8));
assertThrows(IllegalArgumentException.class, () -> TarUtils.formatUnsignedOctalString(017777777L, buffer, 0, buffer.length),
@@ -146,36 +146,34 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testParseOctal() {
long value;
- byte [] buffer;
- final long MAX_OCTAL = 077777777777L; // Allowed 11 digits
- final long MAX_OCTAL_OVERFLOW = 0777777777777L; // in fact 12 for some implementations
+ byte[] buffer;
+ final long MAX_OCTAL = 077777777777L; // Allowed 11 digits
+ final long MAX_OCTAL_OVERFLOW = 0777777777777L; // in fact 12 for some implementations
final String maxOctal = "777777777777"; // Maximum valid octal
buffer = maxOctal.getBytes(UTF_8);
- value = TarUtils.parseOctal(buffer,0, buffer.length);
+ value = TarUtils.parseOctal(buffer, 0, buffer.length);
assertEquals(MAX_OCTAL_OVERFLOW, value);
buffer[buffer.length - 1] = ' ';
- value = TarUtils.parseOctal(buffer,0, buffer.length);
+ value = TarUtils.parseOctal(buffer, 0, buffer.length);
assertEquals(MAX_OCTAL, value);
- buffer[buffer.length-1]=0;
- value = TarUtils.parseOctal(buffer,0, buffer.length);
+ buffer[buffer.length - 1] = 0;
+ value = TarUtils.parseOctal(buffer, 0, buffer.length);
assertEquals(MAX_OCTAL, value);
- buffer=new byte[]{0,0};
- value = TarUtils.parseOctal(buffer,0, buffer.length);
+ buffer = new byte[] { 0, 0 };
+ value = TarUtils.parseOctal(buffer, 0, buffer.length);
assertEquals(0, value);
- buffer=new byte[]{0,' '};
- value = TarUtils.parseOctal(buffer,0, buffer.length);
+ buffer = new byte[] { 0, ' ' };
+ value = TarUtils.parseOctal(buffer, 0, buffer.length);
assertEquals(0, value);
- buffer=new byte[]{' ',0};
- value = TarUtils.parseOctal(buffer,0, buffer.length);
+ buffer = new byte[] { ' ', 0 };
+ value = TarUtils.parseOctal(buffer, 0, buffer.length);
assertEquals(0, value);
}
@Test
public void testParseOctalCompress330() {
final long expected = 0100000;
- final byte [] buffer = {
- 32, 32, 32, 32, 32, 49, 48, 48, 48, 48, 48, 32
- };
+ final byte[] buffer = { 32, 32, 32, 32, 32, 49, 48, 48, 48, 48, 48, 32 };
assertEquals(expected, TarUtils.parseOctalOrBinary(buffer, 0, buffer.length));
}
@@ -185,21 +183,19 @@ public class TarUtilsTest extends AbstractTest {
assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer1, 0, buffer1.length),
"Expected IllegalArgumentException - should be at least 2 bytes long");
- final byte[] buffer2 = {0}; // 1-byte array
+ final byte[] buffer2 = { 0 }; // 1-byte array
assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer2, 0, buffer2.length),
"Expected IllegalArgumentException - should be at least 2 bytes long");
final byte[] buffer3 = "abcdef ".getBytes(UTF_8); // Invalid input
- assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer3, 0, buffer3.length),
- "Expected IllegalArgumentException");
+ assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer3, 0, buffer3.length), "Expected IllegalArgumentException");
final byte[] buffer4 = " 0 07 ".getBytes(UTF_8); // Invalid - embedded space
assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer3, 0, buffer3.length),
"Expected IllegalArgumentException - embedded space");
final byte[] buffer5 = " 0\00007 ".getBytes(UTF_8); // Invalid - embedded NUL
- assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer5, 0, buffer5.length),
- "Expected IllegalArgumentException - embedded NUL");
+ assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer5, 0, buffer5.length), "Expected IllegalArgumentException - embedded NUL");
}
@Test
@@ -210,10 +206,7 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testParsePAX1XSparseHeaders() throws Exception {
- final byte[] header = ("1\n"
- + "0\n"
- + "20\n")
- .getBytes();
+ final byte[] header = ("1\n" + "0\n" + "20\n").getBytes();
final byte[] block = new byte[512];
System.arraycopy(header, 0, block, 0, header.length);
try (ByteArrayInputStream in = new ByteArrayInputStream(block)) {
@@ -225,13 +218,9 @@ public class TarUtilsTest extends AbstractTest {
}
}
-
@Test
public void testParsePAX1XSparseHeadersRejectsIncompleteLastLine() throws Exception {
- final byte[] header = ("1\n"
- + "0\n"
- + "20")
- .getBytes();
+ final byte[] header = ("1\n" + "0\n" + "20").getBytes();
try (ByteArrayInputStream in = new ByteArrayInputStream(header)) {
assertThrows(IOException.class, () -> TarUtils.parsePAX1XSparseHeaders(in, 512));
}
@@ -239,10 +228,7 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testParsePAX1XSparseHeadersRejectsNegativeNumberOfEntries() throws Exception {
- final byte[] header = ("111111111111111111111111111111111111111111111111111111111111111\n"
- + "0\n"
- + "20\n")
- .getBytes();
+ final byte[] header = ("111111111111111111111111111111111111111111111111111111111111111\n" + "0\n" + "20\n").getBytes();
final byte[] block = new byte[512];
System.arraycopy(header, 0, block, 0, header.length);
try (ByteArrayInputStream in = new ByteArrayInputStream(block)) {
@@ -252,10 +238,7 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testParsePAX1XSparseHeadersRejectsNegativeNumbytes() throws Exception {
- final byte[] header = ("1\n"
- + "0\n"
- + "111111111111111111111111111111111111111111111111111111111111111\n")
- .getBytes();
+ final byte[] header = ("1\n" + "0\n" + "111111111111111111111111111111111111111111111111111111111111111\n").getBytes();
final byte[] block = new byte[512];
System.arraycopy(header, 0, block, 0, header.length);
try (ByteArrayInputStream in = new ByteArrayInputStream(block)) {
@@ -265,10 +248,7 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testParsePAX1XSparseHeadersRejectsNegativeOffset() throws Exception {
- final byte[] header = ("1\n"
- + "111111111111111111111111111111111111111111111111111111111111111\n"
- + "20\n")
- .getBytes();
+ final byte[] header = ("1\n" + "111111111111111111111111111111111111111111111111111111111111111\n" + "20\n").getBytes();
final byte[] block = new byte[512];
System.arraycopy(header, 0, block, 0, header.length);
try (ByteArrayInputStream in = new ByteArrayInputStream(block)) {
@@ -278,10 +258,7 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testParsePAX1XSparseHeadersRejectsNonNumericNumberOfEntries() throws Exception {
- final byte[] header = ("x\n"
- + "0\n"
- + "20\n")
- .getBytes();
+ final byte[] header = ("x\n" + "0\n" + "20\n").getBytes();
final byte[] block = new byte[512];
System.arraycopy(header, 0, block, 0, header.length);
try (ByteArrayInputStream in = new ByteArrayInputStream(block)) {
@@ -291,10 +268,7 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testParsePAX1XSparseHeadersRejectsNonNumericNumbytes() throws Exception {
- final byte[] header = ("1\n"
- + "0\n"
- + "2x\n")
- .getBytes();
+ final byte[] header = ("1\n" + "0\n" + "2x\n").getBytes();
final byte[] block = new byte[512];
System.arraycopy(header, 0, block, 0, header.length);
try (ByteArrayInputStream in = new ByteArrayInputStream(block)) {
@@ -304,10 +278,7 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testParsePAX1XSparseHeadersRejectsNonNumericOffset() throws Exception {
- final byte[] header = ("1\n"
- + "x\n"
- + "20\n")
- .getBytes();
+ final byte[] header = ("1\n" + "x\n" + "20\n").getBytes();
final byte[] block = new byte[512];
System.arraycopy(header, 0, block, 0, header.length);
try (ByteArrayInputStream in = new ByteArrayInputStream(block)) {
@@ -319,9 +290,8 @@ public class TarUtilsTest extends AbstractTest {
public void testParseSparse() {
final long expectedOffset = 0100000;
final long expectedNumbytes = 0111000;
- final byte [] buffer = {
- ' ', ' ', ' ', ' ', ' ', '0', '1', '0', '0', '0', '0', '0', // sparseOffset
- ' ', ' ', ' ', ' ', ' ', '0', '1', '1', '1', '0', '0', '0'};
+ final byte[] buffer = { ' ', ' ', ' ', ' ', ' ', '0', '1', '0', '0', '0', '0', '0', // sparseOffset
+ ' ', ' ', ' ', ' ', ' ', '0', '1', '1', '1', '0', '0', '0' };
final TarArchiveStructSparse sparse = TarUtils.parseSparse(buffer, 0);
assertEquals(sparse.getOffset(), expectedOffset);
assertEquals(sparse.getNumbytes(), expectedNumbytes);
@@ -330,7 +300,7 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testParseTarWithSpecialPaxHeaders() throws IOException {
try (InputStream in = newInputStream("COMPRESS-530.tar");
- TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+ TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
assertThrows(IOException.class, () -> archive.getNextEntry());
// IOUtils.toByteArray(archive);
}
@@ -338,38 +308,29 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testPaxHeaderEntryWithEmptyValueRemovesKey() throws Exception {
- final Map<String, String> headers = TarUtils
- .parsePaxHeaders(new ByteArrayInputStream("11 foo=bar\n7 foo=\n"
- .getBytes(UTF_8)), null, new HashMap<>());
+ final Map<String, String> headers = TarUtils.parsePaxHeaders(new ByteArrayInputStream("11 foo=bar\n7 foo=\n".getBytes(UTF_8)), null, new HashMap<>());
assertEquals(0, headers.size());
}
@Test
public void testReadNegativeBinary12Byte() {
- final byte[] b = {
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xf1, (byte) 0xef,
- };
+ final byte[] b = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xf1, (byte) 0xef, };
assertEquals(-3601L, TarUtils.parseOctalOrBinary(b, 0, 12));
}
@Test
public void testReadNegativeBinary8Byte() {
- final byte[] b = {
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xf1, (byte) 0xef,
- };
+ final byte[] b = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xf1, (byte) 0xef, };
assertEquals(-3601L, TarUtils.parseOctalOrBinary(b, 0, 8));
}
@Test
public void testReadNonAsciiPaxHeader() throws Exception {
final String ae = "\u00e4";
- final String line = "11 path="+ ae + "\n";
+ final String line = "11 path=" + ae + "\n";
assertEquals(11, line.getBytes(UTF_8).length);
- final Map<String, String> headers = TarUtils
- .parsePaxHeaders(new ByteArrayInputStream(line.getBytes(UTF_8)), null, new HashMap<>());
+ final Map<String, String> headers = TarUtils.parsePaxHeaders(new ByteArrayInputStream(line.getBytes(UTF_8)), null, new HashMap<>());
assertEquals(1, headers.size());
assertEquals(ae, headers.get("path"));
}
@@ -378,9 +339,7 @@ public class TarUtilsTest extends AbstractTest {
public void testReadPax00SparseHeader() throws Exception {
final String header = "23 GNU.sparse.offset=0\n26 GNU.sparse.numbytes=10\n";
final List<TarArchiveStructSparse> sparseHeaders = new ArrayList<>();
- TarUtils.parsePaxHeaders(
- new ByteArrayInputStream(header.getBytes(UTF_8)),
- sparseHeaders, Collections.emptyMap());
+ TarUtils.parsePaxHeaders(new ByteArrayInputStream(header.getBytes(UTF_8)), sparseHeaders, Collections.emptyMap());
assertEquals(1, sparseHeaders.size());
assertEquals(0, sparseHeaders.get(0).getOffset());
assertEquals(10, sparseHeaders.get(0).getNumbytes());
@@ -390,9 +349,7 @@ public class TarUtilsTest extends AbstractTest {
public void testReadPax00SparseHeaderMakesNumbytesOptional() throws Exception {
final String header = "23 GNU.sparse.offset=0\n24 GNU.sparse.offset=10\n";
final List<TarArchiveStructSparse> sparseHeaders = new ArrayList<>();
- TarUtils.parsePaxHeaders(
- new ByteArrayInputStream(header.getBytes(UTF_8)),
- sparseHeaders, Collections.emptyMap());
+ TarUtils.parsePaxHeaders(new ByteArrayInputStream(header.getBytes(UTF_8)), sparseHeaders, Collections.emptyMap());
assertEquals(2, sparseHeaders.size());
assertEquals(0, sparseHeaders.get(0).getOffset());
assertEquals(0, sparseHeaders.get(0).getNumbytes());
@@ -403,66 +360,52 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testReadPax00SparseHeaderRejectsNegativeNumbytes() throws Exception {
final String header = "23 GNU.sparse.offset=0\n26 GNU.sparse.numbytes=-1\n";
- assertThrows(IOException.class, () -> TarUtils.parsePaxHeaders(
- new ByteArrayInputStream(header.getBytes(UTF_8)),
- null, Collections.emptyMap()));
+ assertThrows(IOException.class, () -> TarUtils.parsePaxHeaders(new ByteArrayInputStream(header.getBytes(UTF_8)), null, Collections.emptyMap()));
}
@Test
public void testReadPax00SparseHeaderRejectsNegativeOffset() throws Exception {
final String header = "24 GNU.sparse.offset=-1\n26 GNU.sparse.numbytes=10\n";
- assertThrows(IOException.class, () -> TarUtils.parsePaxHeaders(
- new ByteArrayInputStream(header.getBytes(UTF_8)),
- null, Collections.emptyMap()));
+ assertThrows(IOException.class, () -> TarUtils.parsePaxHeaders(new ByteArrayInputStream(header.getBytes(UTF_8)), null, Collections.emptyMap()));
}
@Test
public void testReadPax00SparseHeaderRejectsNonNumericNumbytes() throws Exception {
final String header = "23 GNU.sparse.offset=0\n26 GNU.sparse.numbytes=1a\n";
- assertThrows(IOException.class, () -> TarUtils.parsePaxHeaders(
- new ByteArrayInputStream(header.getBytes(UTF_8)),
- null, Collections.emptyMap()));
+ assertThrows(IOException.class, () -> TarUtils.parsePaxHeaders(new ByteArrayInputStream(header.getBytes(UTF_8)), null, Collections.emptyMap()));
}
@Test
public void testReadPax00SparseHeaderRejectsNonNumericOffset() throws Exception {
final String header = "23 GNU.sparse.offset=a\n26 GNU.sparse.numbytes=10\n";
- assertThrows(IOException.class, () -> TarUtils.parsePaxHeaders(
- new ByteArrayInputStream(header.getBytes(UTF_8)),
- null, Collections.emptyMap()));
+ assertThrows(IOException.class, () -> TarUtils.parsePaxHeaders(new ByteArrayInputStream(header.getBytes(UTF_8)), null, Collections.emptyMap()));
}
@Test
public void testReadPaxHeaderWithEmbeddedNewline() throws Exception {
- final Map<String, String> headers = TarUtils
- .parsePaxHeaders(new ByteArrayInputStream("28 comment=line1\nline2\nand3\n"
- .getBytes(UTF_8)), null, new HashMap<>());
+ final Map<String, String> headers = TarUtils.parsePaxHeaders(new ByteArrayInputStream("28 comment=line1\nline2\nand3\n".getBytes(UTF_8)), null,
+ new HashMap<>());
assertEquals(1, headers.size());
assertEquals("line1\nline2\nand3", headers.get("comment"));
}
@Test
public void testReadPaxHeaderWithoutTrailingNewline() throws Exception {
- assertThrows(IOException.class, () -> TarUtils.parsePaxHeaders(
- new ByteArrayInputStream("30 atime=1321711775.9720594634".getBytes(UTF_8)),
- null, Collections.emptyMap()));
+ assertThrows(IOException.class,
+ () -> TarUtils.parsePaxHeaders(new ByteArrayInputStream("30 atime=1321711775.9720594634".getBytes(UTF_8)), null, Collections.emptyMap()));
}
@Test
public void testReadSimplePaxHeader() throws Exception {
- final Map<String, String> headers = TarUtils.parsePaxHeaders(
- new ByteArrayInputStream("30 atime=1321711775.972059463\n".getBytes(UTF_8)),
- null, new HashMap<>());
+ final Map<String, String> headers = TarUtils.parsePaxHeaders(new ByteArrayInputStream("30 atime=1321711775.972059463\n".getBytes(UTF_8)), null,
+ new HashMap<>());
assertEquals(1, headers.size());
assertEquals("1321711775.972059463", headers.get("atime"));
}
@Test
public void testReadSparseStructsBinary() throws Exception {
- final byte[] header = {
- (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,
- };
+ final byte[] header = { (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, };
assertEquals(24, header.length);
final List<TarArchiveStructSparse> sparse = TarUtils.readSparseStructs(header, 0, 1);
assertEquals(1, sparse.size());
@@ -482,21 +425,15 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testReadSparseStructsRejectsNegativeNumbytes() throws Exception {
- final byte[] header = {
- (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- };
+ final byte[] header = { (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, };
assertThrows(IOException.class, () -> TarUtils.readSparseStructs(header, 0, 1));
}
@Test
public void testReadSparseStructsRejectsNegativeOffset() throws Exception {
- final byte[] header = {
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,
- };
+ final byte[] header = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, };
assertThrows(IOException.class, () -> TarUtils.readSparseStructs(header, 0, 1));
}
@@ -516,14 +453,17 @@ public class TarUtilsTest extends AbstractTest {
public void testRoundEncoding() throws Exception {
// COMPRESS-114
final ZipEncoding enc = ZipEncodingHelper.getZipEncoding(CharsetNames.ISO_8859_1);
- final String s = "0302-0601-3\u00b1\u00b1\u00b1F06\u00b1W220\u00b1ZB\u00b1LALALA\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1CAN\u00b1\u00b1DC\u00b1\u00b1\u00b104\u00b1060302\u00b1MOE.model";
+ // @formatter:off
+ final String s = "0302-0601-3\u00b1\u00b1\u00b1F06\u00b1W220\u00b1ZB\u00b1LALALA\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1CAN"
+ + "\u00b1\u00b1DC\u00b1\u00b1\u00b104\u00b1060302\u00b1MOE.model";
+ // @formatter:on
final byte[] buff = new byte[100];
final int len = TarUtils.formatNameBytes(s, buff, 0, buff.length, enc);
assertEquals(s, TarUtils.parseName(buff, 0, len, enc));
}
@Test
- public void testRoundTripNames(){
+ public void testRoundTripNames() {
checkName("");
checkName("The quick brown fox\n");
checkName("\177");
@@ -573,140 +513,85 @@ public class TarUtilsTest extends AbstractTest {
@Test
public void testSecondEntryWinsWhenPaxHeaderContainsDuplicateKey() throws Exception {
- final Map<String, String> headers = TarUtils.parsePaxHeaders(new ByteArrayInputStream("11 foo=bar\n11 foo=baz\n"
- .getBytes(UTF_8)), null, new HashMap<>());
+ final Map<String, String> headers = TarUtils.parsePaxHeaders(new ByteArrayInputStream("11 foo=bar\n11 foo=baz\n".getBytes(UTF_8)), null,
+ new HashMap<>());
assertEquals(1, headers.size());
assertEquals("baz", headers.get("foo"));
}
+
// Check correct trailing bytes are generated
@Test
public void testTrailers() {
- final byte [] buffer = new byte[12];
+ final byte[] buffer = new byte[12];
TarUtils.formatLongOctalBytes(123, buffer, 0, buffer.length);
- assertEquals(' ', buffer[buffer.length-1]);
- assertEquals('3', buffer[buffer.length-2]); // end of number
+ assertEquals(' ', buffer[buffer.length - 1]);
+ assertEquals('3', buffer[buffer.length - 2]); // end of number
TarUtils.formatOctalBytes(123, buffer, 0, buffer.length);
- assertEquals(0 , buffer[buffer.length-1]);
- assertEquals(' ', buffer[buffer.length-2]);
- assertEquals('3', buffer[buffer.length-3]); // end of number
+ assertEquals(0, buffer[buffer.length - 1]);
+ assertEquals(' ', buffer[buffer.length - 2]);
+ assertEquals('3', buffer[buffer.length - 3]); // end of number
TarUtils.formatCheckSumOctalBytes(123, buffer, 0, buffer.length);
- assertEquals(' ', buffer[buffer.length-1]);
- assertEquals(0 , buffer[buffer.length-2]);
- assertEquals('3', buffer[buffer.length-3]); // end of number
+ assertEquals(' ', buffer[buffer.length - 1]);
+ assertEquals(0, buffer[buffer.length - 2]);
+ assertEquals('3', buffer[buffer.length - 3]); // end of number
}
// https://issues.apache.org/jira/browse/COMPRESS-191
@Test
public void testVerifyHeaderCheckSum() {
final byte[] valid = { // from bla.tar
- 116, 101, 115, 116, 49, 46, 120, 109, 108, 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, 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, 48, 48, 48, 48, 54, 52, 52, 0, 48, 48, 48, 48, 55, 54, 53,
- 0, 48, 48, 48, 48, 55, 54, 53, 0, 48, 48, 48, 48, 48, 48, 48,
- 49, 49, 52, 50, 0, 49, 48, 55, 49, 54, 53, 52, 53, 54, 50, 54,
- 0, 48, 49, 50, 50, 54, 48, 0, 32, 48, 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, 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, 117, 115, 116, 97, 114, 32, 32, 0,
- 116, 99, 117, 114, 100, 116, 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, 116, 99, 117,
- 114, 100, 116, 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, 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, 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, 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, 0,
- 0, 0, 0, 0 };
+ 116, 101, 115, 116, 49, 46, 120, 109, 108, 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, 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, 48, 48, 48, 48, 54, 52, 52, 0, 48, 48, 48, 48, 55, 54, 53, 0, 48, 48, 48, 48, 55, 54, 53, 0, 48, 48, 48, 48, 48, 48,
+ 48, 49, 49, 52, 50, 0, 49, 48, 55, 49, 54, 53, 52, 53, 54, 50, 54, 0, 48, 49, 50, 50, 54, 48, 0, 32, 48, 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, 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, 117, 115, 116, 97, 114, 32,
+ 32, 0, 116, 99, 117, 114, 100, 116, 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, 116, 99, 117, 114, 100, 116,
+ 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, 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, 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, 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, 0, 0, 0, 0, 0 };
assertTrue(TarUtils.verifyCheckSum(valid));
final byte[] compress117 = { // from COMPRESS-117
- (byte) 0x37, (byte) 0x7a, (byte) 0x43, (byte) 0x2e, (byte) 0x74, (byte) 0x78, (byte) 0x74, (byte) 0x00,
- 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, 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, (byte) 0x31, (byte) 0x30, (byte) 0x30, (byte) 0x37,
- (byte) 0x37, (byte) 0x37, (byte) 0x20, (byte) 0x00, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,
- (byte) 0x20, (byte) 0x30, (byte) 0x20, (byte) 0x00, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,
- (byte) 0x20, (byte) 0x30, (byte) 0x20, (byte) 0x00, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20,
- (byte) 0x20, (byte) 0x20, (byte) 0x31, (byte) 0x33, (byte) 0x30, (byte) 0x33, (byte) 0x33, (byte) 0x20,
- (byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x35, (byte) 0x31, (byte) 0x36, (byte) 0x36,
- (byte) 0x30, (byte) 0x31, (byte) 0x36, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x35, (byte) 0x34,
- (byte) 0x31, (byte) 0x37, (byte) 0x20, (byte) 0x00, (byte) 0x30, (byte) 0x00, 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, 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, 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, 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, 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, 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,
- 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,
- };
+ (byte) 0x37, (byte) 0x7a, (byte) 0x43, (byte) 0x2e, (byte) 0x74, (byte) 0x78, (byte) 0x74, (byte) 0x00, 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, 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, (byte) 0x31, (byte) 0x30, (byte) 0x30, (byte) 0x37,
+ (byte) 0x37, (byte) 0x37, (byte) 0x20, (byte) 0x00, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x30, (byte) 0x20,
+ (byte) 0x00, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x30, (byte) 0x20, (byte) 0x00, (byte) 0x20, (byte) 0x20,
+ (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x20, (byte) 0x31, (byte) 0x33, (byte) 0x30, (byte) 0x33, (byte) 0x33, (byte) 0x20, (byte) 0x31,
+ (byte) 0x31, (byte) 0x31, (byte) 0x31, (byte) 0x35, (byte) 0x31, (byte) 0x36, (byte) 0x36, (byte) 0x30, (byte) 0x31, (byte) 0x36, (byte) 0x20,
+ (byte) 0x20, (byte) 0x20, (byte) 0x35, (byte) 0x34, (byte) 0x31, (byte) 0x37, (byte) 0x20, (byte) 0x00, (byte) 0x30, (byte) 0x00, 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, 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, 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, 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, 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, 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, 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, };
assertTrue(TarUtils.verifyCheckSum(compress117));
final byte[] invalid = { // from the testAIFF.aif file in Tika
- 70, 79, 82, 77, 0, 0, 15, 46, 65, 73, 70, 70, 67, 79, 77, 77,
- 0, 0, 0, 18, 0, 2, 0, 0, 3, -64, 0, 16, 64, 14, -84, 68, 0, 0,
- 0, 0, 0, 0, 83, 83, 78, 68, 0, 0, 15, 8, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1,
- 0, 0, 0, 0, 0, 0, -1, -1, 0, 2, -1, -2, 0, 2, -1, -1, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0,
- 0, 0, 0, 1, -1, -1, 0, 1, -1, -2, 0, 1, -1, -1, 0, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0,
- 2, -1, -2, 0, 2, -1, -1, 0, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -2, 0, 2, -1, -2, 0, 1, 0, 0,
- 0, 1, -1, -1, 0, 0, 0, 1, -1, -1, 0, 0, 0, 1, -1, -2, 0, 2,
- -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 1, -1, -1, 0, 2, -1, -2,
- 0, 2, -1, -2, 0, 2, -1, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, -1,
- -2, 0, 2, -1, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- -1, -1, 0, 1, 0, 0, -1, -1, 0, 2, -1, -2, 0, 2, -1, -1, 0, 0,
- 0, 0, 0, 0, -1, -1, 0, 1, -1, -1, 0, 1, -1, -1, 0, 2, -1, -2,
- 0, 1, 0, 0, -1, -1, 0, 2, -1, -2, 0, 2, -1, -2, 0, 1, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 0,
- 0, -1, -1, 0, 1, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -2, 0, 2, -1, -1, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -2, 0, 1, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 0, 0, -1, -1, 0, 2, -1, -2,
- 0, 2, -1, -2, 0, 2, -1, -1, 0, 0, 0, 0, -1, -1, 0, 1, -1, -1,
- 0, 1, -1, -1, 0, 1, -1, -1, 0, 1, -1, -1, 0, 1, 0, 0, 0, 0,
- -1, -1, 0, 2, -1, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 1, -1, -1, 0, 0, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 1 };
+ 70, 79, 82, 77, 0, 0, 15, 46, 65, 73, 70, 70, 67, 79, 77, 77, 0, 0, 0, 18, 0, 2, 0, 0, 3, -64, 0, 16, 64, 14, -84, 68, 0, 0, 0, 0, 0, 0, 83, 83,
+ 78, 68, 0, 0, 15, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, 0, 2, -1, -2,
+ 0, 2, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 1, -1, -2, 0, 1, -1, -1, 0, 1, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 2, -1, -2, 0, 2, -1, -1, 0, 0, 0, 1, -1, -1, 0, 1, -1, -1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 1, -1, -2, 0, 2, -1, -2, 0, 1, 0, 0, 0, 1, -1, -1, 0, 0, 0, 1, -1, -1, 0, 0, 0, 1, -1, -2, 0, 2, -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, 0, 1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 1, -1, -1, 0, 2, -1, -2, 0, 2, -1, -2, 0, 2, -1, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
+ -1, -2, 0, 2, -1, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 1, 0, 0, -1, -1, 0, 2, -1, -2, 0, 2, -1, -1, 0, 0, 0, 0, 0, 0, -1,
+ -1, 0, 1, -1, -1, 0, 1, -1, -1, 0, 2, -1, -2, 0, 1, 0, 0, -1, -1, 0, 2, -1, -2, 0, 2, -1, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 1, -1, -1, 0, 0, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -2, 0, 2, -1, -1,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 0, 0, -1, -1, 0, 2, -1, -2, 0, 2, -1, -2, 0,
+ 2, -1, -1, 0, 0, 0, 0, -1, -1, 0, 1, -1, -1, 0, 1, -1, -1, 0, 1, -1, -1, 0, 1, -1, -1, 0, 1, 0, 0, 0, 0, -1, -1, 0, 2, -1, -2, 0, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, 0, 0, 0, 0, -1, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
assertFalse(TarUtils.verifyCheckSum(invalid));
}
@Test
public void testWriteNegativeBinary8Byte() {
- final byte[] b = {
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff, (byte) 0xf1, (byte) 0xef,
- };
+ final byte[] b = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xf1, (byte) 0xef, };
assertEquals(-3601L, TarUtils.parseOctalOrBinary(b, 0, 8));
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/AsiExtraFieldTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/AsiExtraFieldTest.java
index 035b19356..df2c7324e 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/AsiExtraFieldTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/AsiExtraFieldTest.java
@@ -59,25 +59,25 @@ public class AsiExtraFieldTest implements UnixStat {
byte[] b = a.getLocalFileDataData();
// CRC manually calculated, sorry
- byte[] expect = {(byte) 0xC6, 0x02, 0x78, (byte) 0xB6, // CRC
- 0123, (byte) 0x80, // mode
- 0, 0, 0, 0, // link length
- 5, 0, 6, 0}; // uid, gid
+ byte[] expect = { (byte) 0xC6, 0x02, 0x78, (byte) 0xB6, // CRC
+ 0123, (byte) 0x80, // mode
+ 0, 0, 0, 0, // link length
+ 5, 0, 6, 0 }; // uid, gid
assertEquals(expect.length, b.length, "no link");
- for (int i=0; i<expect.length; i++) {
+ for (int i = 0; i < expect.length; i++) {
assertEquals(expect[i], b[i], "no link, byte " + i);
}
a.setLinkedFile("test");
- expect = new byte[] {0x75, (byte) 0x8E, 0x41, (byte) 0xFD, // CRC
- 0123, (byte) 0xA0, // mode
- 4, 0, 0, 0, // link length
- 5, 0, 6, 0, // uid, gid
- (byte)'t', (byte)'e', (byte)'s', (byte)'t'};
+ expect = new byte[] { 0x75, (byte) 0x8E, 0x41, (byte) 0xFD, // CRC
+ 0123, (byte) 0xA0, // mode
+ 4, 0, 0, 0, // link length
+ 5, 0, 6, 0, // uid, gid
+ (byte) 't', (byte) 'e', (byte) 's', (byte) 't' };
b = a.getLocalFileDataData();
assertEquals(expect.length, b.length, "no link");
- for (int i=0; i<expect.length; i++) {
- assertEquals(expect[i], b[i], "no link, byte "+i);
+ for (int i = 0; i < expect.length; i++) {
+ assertEquals(expect[i], b[i], "no link, byte " + i);
}
}
@@ -102,10 +102,10 @@ public class AsiExtraFieldTest implements UnixStat {
@Test
public void testReparse() throws Exception {
// CRC manually calculated, sorry
- final byte[] data1 = {(byte) 0xC6, 0x02, 0x78, (byte) 0xB6, // CRC
- 0123, (byte) 0x80, // mode
- 0, 0, 0, 0, // link length
- 5, 0, 6, 0}; // uid, gid
+ final byte[] data1 = { (byte) 0xC6, 0x02, 0x78, (byte) 0xB6, // CRC
+ 0123, (byte) 0x80, // mode
+ 0, 0, 0, 0, // link length
+ 5, 0, 6, 0 }; // uid, gid
final AsiExtraField a1 = new AsiExtraField();
a1.parseFromLocalFileData(data1, 0, data1.length);
assertEquals(data1.length, a1.getLocalFileDataLength().getValue(), "length plain file");
@@ -115,11 +115,11 @@ public class AsiExtraFieldTest implements UnixStat {
assertEquals(5, a1.getUserId(), "uid plain file");
assertEquals(6, a1.getGroupId(), "gid plain file");
- final byte[] data2 = {0x75, (byte) 0x8E, 0x41, (byte) 0xFD, // CRC
- 0123, (byte) 0xA0, // mode
- 4, 0, 0, 0, // link length
- 5, 0, 6, 0, // uid, gid
- (byte)'t', (byte)'e', (byte)'s', (byte)'t'};
+ final byte[] data2 = { 0x75, (byte) 0x8E, 0x41, (byte) 0xFD, // CRC
+ 0123, (byte) 0xA0, // mode
+ 4, 0, 0, 0, // link length
+ 5, 0, 6, 0, // uid, gid
+ (byte) 't', (byte) 'e', (byte) 's', (byte) 't' };
final AsiExtraField a2 = new AsiExtraField();
a2.parseFromLocalFileData(data2, 0, data2.length);
assertEquals(data2.length, a2.getLocalFileDataLength().getValue(), "length link");
@@ -130,10 +130,10 @@ public class AsiExtraFieldTest implements UnixStat {
assertEquals(6, a2.getGroupId(), "gid link");
assertEquals("test", a2.getLinkedFile());
- final byte[] data3 = {(byte) 0x8E, 0x01, (byte) 0xBF, (byte) 0x0E, // CRC
- 0123, (byte) 0x40, // mode
- 0, 0, 0, 0, // link
- 5, 0, 6, 0}; // uid, gid
+ final byte[] data3 = { (byte) 0x8E, 0x01, (byte) 0xBF, (byte) 0x0E, // CRC
+ 0123, (byte) 0x40, // mode
+ 0, 0, 0, 0, // link
+ 5, 0, 6, 0 }; // uid, gid
final AsiExtraField a3 = new AsiExtraField();
a3.parseFromLocalFileData(data3, 0, data3.length);
assertEquals(data3.length, a3.getLocalFileDataLength().getValue(), "length dir");
@@ -143,13 +143,12 @@ public class AsiExtraFieldTest implements UnixStat {
assertEquals(5, a3.getUserId(), "uid dir");
assertEquals(6, a3.getGroupId(), "gid dir");
- final byte[] data4 = {0, 0, 0, 0, // bad CRC
- 0123, (byte) 0x40, // mode
- 0, 0, 0, 0, // link
- 5, 0, 6, 0}; // uid, gid
+ final byte[] data4 = { 0, 0, 0, 0, // bad CRC
+ 0123, (byte) 0x40, // mode
+ 0, 0, 0, 0, // link
+ 5, 0, 6, 0 }; // uid, gid
final AsiExtraField a4 = new AsiExtraField();
- final Exception e = assertThrows(Exception.class, () -> a4.parseFromLocalFileData(data4, 0, data4.length),
- "should raise bad CRC exception");
+ final Exception e = assertThrows(Exception.class, () -> a4.parseFromLocalFileData(data4, 0, data4.length), "should raise bad CRC exception");
assertEquals("Bad CRC checksum, expected 0 instead of ebf018e", e.getMessage());
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Crash_f2efd9eaeb86cda597d07b5e3c3d81363633c2da_Test.java b/src/test/java/org/apache/commons/compress/archivers/zip/Crash_f2efd9eaeb86cda597d07b5e3c3d81363633c2da_Test.java
index c317d39c4..059fcbaca 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Crash_f2efd9eaeb86cda597d07b5e3c3d81363633c2da_Test.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Crash_f2efd9eaeb86cda597d07b5e3c3d81363633c2da_Test.java
@@ -37,7 +37,7 @@ public class Crash_f2efd9eaeb86cda597d07b5e3c3d81363633c2da_Test {
@Test
public void test() throws IOException {
final byte[] input = FileUtils
- .readFileToByteArray(new File("src/test/resources/org/apache/commons/compress/fuzz/crash-f2efd9eaeb86cda597d07b5e3c3d81363633c2da"));
+ .readFileToByteArray(new File("src/test/resources/org/apache/commons/compress/fuzz/crash-f2efd9eaeb86cda597d07b5e3c3d81363633c2da"));
try (ZipArchiveInputStream zis = new ZipArchiveInputStream(new ByteArrayInputStream(input))) {
//
// I do not think this is supposed to be recoverable... then... what?
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java
index b3dbfe9d1..f0e48fda5 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java
@@ -33,8 +33,7 @@ import org.junit.jupiter.api.Test;
public class EncryptedArchiveTest {
@Test
- public void testReadPasswordEncryptedEntryViaStream()
- throws IOException {
+ public void testReadPasswordEncryptedEntryViaStream() throws IOException {
final File file = getFile("password-encrypted.zip");
try (ZipArchiveInputStream zin = new ZipArchiveInputStream(Files.newInputStream(file.toPath()))) {
final ZipArchiveEntry zae = zin.getNextZipEntry();
@@ -51,16 +50,14 @@ public class EncryptedArchiveTest {
}
@Test
- public void testReadPasswordEncryptedEntryViaZipFile()
- throws IOException {
+ public void testReadPasswordEncryptedEntryViaZipFile() throws IOException {
final File file = getFile("password-encrypted.zip");
- try (final ZipFile zf = new ZipFile(file)) {
+ try (ZipFile zf = new ZipFile(file)) {
final ZipArchiveEntry zae = zf.getEntry("LICENSE.txt");
assertTrue(zae.getGeneralPurposeBit().usesEncryption());
assertFalse(zae.getGeneralPurposeBit().usesStrongEncryption());
assertFalse(zf.canReadEntryData(zae));
- final UnsupportedZipFeatureException ex = assertThrows(UnsupportedZipFeatureException.class, () -> zf.getInputStream(zae),
- "expected an exception");
+ final UnsupportedZipFeatureException ex = assertThrows(UnsupportedZipFeatureException.class, () -> zf.getInputStream(zae), "expected an exception");
assertSame(UnsupportedZipFeatureException.Feature.ENCRYPTION, ex.getFeature());
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
index 6d9ed6b69..a8ee048c0 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtilsTest.java
@@ -33,10 +33,12 @@ public class ExtraFieldUtilsTest implements UnixStat {
public static class AiobThrowingExtraField implements ZipExtraField {
static final int LENGTH = 4;
+
@Override
public byte[] getCentralDirectoryData() {
return getLocalFileDataData();
}
+
@Override
public ZipShort getCentralDirectoryLength() {
return getLocalFileDataLength();
@@ -71,14 +73,14 @@ public class ExtraFieldUtilsTest implements UnixStat {
/**
* Header-ID of a ZipExtraField not supported by Commons Compress.
*
- * <p>Used to be ZipShort(1) but this is the ID of the Zip64 extra
- * field.</p>
+ * <p>
+ * Used to be ZipShort(1) but this is the ID of the Zip64 extra field.
+ * </p>
*/
static final ZipShort UNRECOGNIZED_HEADER = new ZipShort(0x5555);
/**
- * Header-ID of a ZipExtraField not supported by Commons Compress
- * used for the ArrayIndexOutOfBoundsTest.
+ * Header-ID of a ZipExtraField not supported by Commons Compress used for the ArrayIndexOutOfBoundsTest.
*/
static final ZipShort AIOB_HEADER = new ZipShort(0x1000);
private AsiExtraField a;
@@ -94,8 +96,8 @@ public class ExtraFieldUtilsTest implements UnixStat {
a.setDirectory(true);
dummy = new UnrecognizedExtraField();
dummy.setHeaderId(UNRECOGNIZED_HEADER);
- dummy.setLocalFileDataData(new byte[] {0});
- dummy.setCentralDirectoryData(new byte[] {0});
+ dummy.setLocalFileDataData(new byte[] { 0 });
+ dummy.setCentralDirectoryData(new byte[] { 0 });
aLocal = a.getLocalFileDataData();
final byte[] dummyLocal = dummy.getLocalFileDataData();
@@ -103,12 +105,9 @@ public class ExtraFieldUtilsTest implements UnixStat {
System.arraycopy(a.getHeaderId().getBytes(), 0, data, 0, 2);
System.arraycopy(a.getLocalFileDataLength().getBytes(), 0, data, 2, 2);
System.arraycopy(aLocal, 0, data, 4, aLocal.length);
- System.arraycopy(dummy.getHeaderId().getBytes(), 0, data,
- 4+aLocal.length, 2);
- System.arraycopy(dummy.getLocalFileDataLength().getBytes(), 0, data,
- 4+aLocal.length+2, 2);
- System.arraycopy(dummyLocal, 0, data,
- 4+aLocal.length+4, dummyLocal.length);
+ System.arraycopy(dummy.getHeaderId().getBytes(), 0, data, 4 + aLocal.length, 2);
+ System.arraycopy(dummy.getLocalFileDataLength().getBytes(), 0, data, 4 + aLocal.length + 2, 2);
+ System.arraycopy(dummyLocal, 0, data, 4 + aLocal.length + 4, dummyLocal.length);
}
@@ -117,26 +116,21 @@ public class ExtraFieldUtilsTest implements UnixStat {
*/
@Test
public void testMerge() {
- final byte[] local =
- ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] {a, dummy});
+ final byte[] local = ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] { a, dummy });
assertEquals(data.length, local.length, "local length");
- for (int i=0; i<local.length; i++) {
+ for (int i = 0; i < local.length; i++) {
assertEquals(data[i], local[i], "local byte " + i);
}
final byte[] dummyCentral = dummy.getCentralDirectoryData();
final byte[] data2 = new byte[4 + aLocal.length + 4 + dummyCentral.length];
System.arraycopy(data, 0, data2, 0, 4 + aLocal.length + 2);
- System.arraycopy(dummy.getCentralDirectoryLength().getBytes(), 0,
- data2, 4+aLocal.length+2, 2);
- System.arraycopy(dummyCentral, 0, data2,
- 4+aLocal.length+4, dummyCentral.length);
+ System.arraycopy(dummy.getCentralDirectoryLength().getBytes(), 0, data2, 4 + aLocal.length + 2, 2);
+ System.arraycopy(dummyCentral, 0, data2, 4 + aLocal.length + 4, dummyCentral.length);
-
- final byte[] central =
- ExtraFieldUtils.mergeCentralDirectoryData(new ZipExtraField[] {a, dummy});
+ final byte[] central = ExtraFieldUtils.mergeCentralDirectoryData(new ZipExtraField[] { a, dummy });
assertEquals(data2.length, central.length, "central length");
- for (int i=0; i<central.length; i++) {
+ for (int i = 0; i < central.length; i++) {
assertEquals(data2[i], central[i], "central byte " + i);
}
@@ -146,9 +140,8 @@ public class ExtraFieldUtilsTest implements UnixStat {
public void testMergeWithUnparseableData() throws Exception {
final ZipExtraField d = new UnparseableExtraFieldData();
final byte[] b = UNRECOGNIZED_HEADER.getBytes();
- d.parseFromLocalFileData(new byte[] {b[0], b[1], 1, 0}, 0, 4);
- final byte[] local =
- ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] {a, d});
+ d.parseFromLocalFileData(new byte[] { b[0], b[1], 1, 0 }, 0, 4);
+ final byte[] local = ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] { a, d });
assertEquals(data.length - 1, local.length, "local length");
for (int i = 0; i < local.length; i++) {
assertEquals(data[i], local[i], "local byte " + i);
@@ -157,12 +150,9 @@ public class ExtraFieldUtilsTest implements UnixStat {
final byte[] dCentral = d.getCentralDirectoryData();
final byte[] data2 = new byte[4 + aLocal.length + dCentral.length];
System.arraycopy(data, 0, data2, 0, 4 + aLocal.length + 2);
- System.arraycopy(dCentral, 0, data2,
- 4 + aLocal.length, dCentral.length);
-
+ System.arraycopy(dCentral, 0, data2, 4 + aLocal.length, dCentral.length);
- final byte[] central =
- ExtraFieldUtils.mergeCentralDirectoryData(new ZipExtraField[] {a, d});
+ final byte[] central = ExtraFieldUtils.mergeCentralDirectoryData(new ZipExtraField[] { a, d });
assertEquals(data2.length, central.length, "central length");
for (int i = 0; i < central.length; i++) {
assertEquals(data2[i], central[i], "central byte " + i);
@@ -182,11 +172,11 @@ public class ExtraFieldUtilsTest implements UnixStat {
assertTrue(ze[1] instanceof UnrecognizedExtraField, "type field 2");
assertEquals(1, ze[1].getLocalFileDataLength().getValue(), "data length field 2");
- final byte[] data2 = new byte[data.length-1];
+ final byte[] data2 = new byte[data.length - 1];
System.arraycopy(data, 0, data2, 0, data2.length);
final Exception e = assertThrows(Exception.class, () -> ExtraFieldUtils.parse(data2), "data should be invalid");
- assertEquals("Bad extra field starting at " + (4 + aLocal.length) +
- ". Block length of 1 bytes exceeds remaining data of 0 bytes.", e.getMessage(), "message");
+ assertEquals("Bad extra field starting at " + (4 + aLocal.length) + ". Block length of 1 bytes exceeds remaining data of 0 bytes.", e.getMessage(),
+ "message");
}
@Test
@@ -214,46 +204,38 @@ public class ExtraFieldUtilsTest implements UnixStat {
@Test
public void testParseWithRead() throws Exception {
- ZipExtraField[] ze =
- ExtraFieldUtils.parse(data, true,
- ExtraFieldUtils.UnparseableExtraField.READ);
+ ZipExtraField[] ze = ExtraFieldUtils.parse(data, true, ExtraFieldUtils.UnparseableExtraField.READ);
assertEquals(2, ze.length, "number of fields");
assertTrue(ze[0] instanceof AsiExtraField, "type field 1");
assertEquals(040755, ((AsiExtraField) ze[0]).getMode(), "mode field 1");
assertTrue(ze[1] instanceof UnrecognizedExtraField, "type field 2");
assertEquals(1, ze[1].getLocalFileDataLength().getValue(), "data length field 2");
- final byte[] data2 = new byte[data.length-1];
+ final byte[] data2 = new byte[data.length - 1];
System.arraycopy(data, 0, data2, 0, data2.length);
- ze = ExtraFieldUtils.parse(data2, true,
- ExtraFieldUtils.UnparseableExtraField.READ);
+ ze = ExtraFieldUtils.parse(data2, true, ExtraFieldUtils.UnparseableExtraField.READ);
assertEquals(2, ze.length, "number of fields");
assertTrue(ze[0] instanceof AsiExtraField, "type field 1");
assertEquals(040755, ((AsiExtraField) ze[0]).getMode(), "mode field 1");
assertTrue(ze[1] instanceof UnparseableExtraFieldData, "type field 2");
assertEquals(4, ze[1].getLocalFileDataLength().getValue(), "data length field 2");
for (int i = 0; i < 4; i++) {
- assertEquals(data2[data.length - 5 + i],
- ze[1].getLocalFileDataData()[i],
- "byte number " + i);
+ assertEquals(data2[data.length - 5 + i], ze[1].getLocalFileDataData()[i], "byte number " + i);
}
}
@Test
public void testParseWithSkip() throws Exception {
- ZipExtraField[] ze =
- ExtraFieldUtils.parse(data, true,
- ExtraFieldUtils.UnparseableExtraField.SKIP);
+ ZipExtraField[] ze = ExtraFieldUtils.parse(data, true, ExtraFieldUtils.UnparseableExtraField.SKIP);
assertEquals(2, ze.length, "number of fields");
assertTrue(ze[0] instanceof AsiExtraField, "type field 1");
assertEquals(040755, ((AsiExtraField) ze[0]).getMode(), "mode field 1");
assertTrue(ze[1] instanceof UnrecognizedExtraField, "type field 2");
assertEquals(1, ze[1].getLocalFileDataLength().getValue(), "data length field 2");
- final byte[] data2 = new byte[data.length-1];
+ final byte[] data2 = new byte[data.length - 1];
System.arraycopy(data, 0, data2, 0, data2.length);
- ze = ExtraFieldUtils.parse(data2, true,
- ExtraFieldUtils.UnparseableExtraField.SKIP);
+ ze = ExtraFieldUtils.parse(data2, true, ExtraFieldUtils.UnparseableExtraField.SKIP);
assertEquals(1, ze.length, "number of fields");
assertTrue(ze[0] instanceof AsiExtraField, "type field 1");
assertEquals(040755, ((AsiExtraField) ze[0]).getMode(), "mode field 1");
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBitTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBitTest.java
index 2e85668d9..e72f1b712 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBitTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBitTest.java
@@ -40,7 +40,7 @@ public class GeneralPurposeBitTest {
@Test
public void testDataDescriptor() {
- final byte[] flags = {(byte) 8, (byte) 0};
+ final byte[] flags = { (byte) 8, (byte) 0 };
assertTrue(GeneralPurposeBit.parse(flags, 0).usesDataDescriptor());
final GeneralPurposeBit b = new GeneralPurposeBit();
b.useDataDescriptor(true);
@@ -59,7 +59,7 @@ public class GeneralPurposeBitTest {
@Test
public void testEncryption() {
- final byte[] flags = {(byte) 1, (byte) 0};
+ final byte[] flags = { (byte) 1, (byte) 0 };
assertTrue(GeneralPurposeBit.parse(flags, 0).usesEncryption());
final GeneralPurposeBit b = new GeneralPurposeBit();
b.useEncryption(true);
@@ -68,7 +68,7 @@ public class GeneralPurposeBitTest {
@Test
public void testLanguageEncodingFlag() {
- final byte[] flags = {(byte) 0, (byte) 8};
+ final byte[] flags = { (byte) 0, (byte) 8 };
assertTrue(GeneralPurposeBit.parse(flags, 0).usesUTF8ForNames());
final GeneralPurposeBit b = new GeneralPurposeBit();
b.useUTF8ForNames(true);
@@ -77,38 +77,26 @@ public class GeneralPurposeBitTest {
@Test
public void testParseEdgeCases() {
- assertFalse(GeneralPurposeBit.parse(new byte[2], 0)
- .usesDataDescriptor());
- assertFalse(GeneralPurposeBit.parse(new byte[2], 0)
- .usesUTF8ForNames());
- assertFalse(GeneralPurposeBit.parse(new byte[2], 0)
- .usesEncryption());
- assertFalse(GeneralPurposeBit.parse(new byte[2], 0)
- .usesStrongEncryption());
- assertTrue(GeneralPurposeBit.parse(new byte[] {(byte) 255, (byte) 255},
- 0)
- .usesDataDescriptor());
- assertTrue(GeneralPurposeBit.parse(new byte[] {(byte) 255, (byte) 255},
- 0)
- .usesUTF8ForNames());
- assertTrue(GeneralPurposeBit.parse(new byte[] {(byte) 255, (byte) 255},
- 0)
- .usesEncryption());
- assertTrue(GeneralPurposeBit.parse(new byte[] {(byte) 255, (byte) 255},
- 0)
- .usesStrongEncryption());
+ assertFalse(GeneralPurposeBit.parse(new byte[2], 0).usesDataDescriptor());
+ assertFalse(GeneralPurposeBit.parse(new byte[2], 0).usesUTF8ForNames());
+ assertFalse(GeneralPurposeBit.parse(new byte[2], 0).usesEncryption());
+ assertFalse(GeneralPurposeBit.parse(new byte[2], 0).usesStrongEncryption());
+ assertTrue(GeneralPurposeBit.parse(new byte[] { (byte) 255, (byte) 255 }, 0).usesDataDescriptor());
+ assertTrue(GeneralPurposeBit.parse(new byte[] { (byte) 255, (byte) 255 }, 0).usesUTF8ForNames());
+ assertTrue(GeneralPurposeBit.parse(new byte[] { (byte) 255, (byte) 255 }, 0).usesEncryption());
+ assertTrue(GeneralPurposeBit.parse(new byte[] { (byte) 255, (byte) 255 }, 0).usesStrongEncryption());
}
@Test
public void testStrongEncryption() {
- byte[] flags = {(byte) 65, (byte) 0};
+ byte[] flags = { (byte) 65, (byte) 0 };
assertTrue(GeneralPurposeBit.parse(flags, 0).usesStrongEncryption());
final GeneralPurposeBit b = new GeneralPurposeBit();
b.useStrongEncryption(true);
assertTrue(b.usesEncryption());
assertArrayEquals(flags, b.encode());
- flags = new byte[] {(byte) 64, (byte) 0};
+ flags = new byte[] { (byte) 64, (byte) 0 };
assertFalse(GeneralPurposeBit.parse(flags, 0).usesStrongEncryption());
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Lister.java b/src/test/java/org/apache/commons/compress/archivers/zip/Lister.java
index 85cf3b892..549436691 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Lister.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Lister.java
@@ -29,10 +29,13 @@ import org.apache.commons.compress.archivers.ArchiveEntry;
/**
* Simple command line application that lists the contents of a ZIP archive.
*
- * <p>The name of the archive must be given as a command line argument.</p>
+ * <p>
+ * The name of the archive must be given as a command line argument.
+ * </p>
*
- * <p>Optional command line arguments specify the encoding to assume
- * and whether to use ZipFile or ZipArchiveInputStream.</p>
+ * <p>
+ * Optional command line arguments specify the encoding to assume and whether to use ZipFile or ZipArchiveInputStream.
+ * </p>
*/
public final class Lister {
private static final class CommandLine {
@@ -43,8 +46,7 @@ public final class Lister {
String dir;
}
- private static void extract(final String dir, final ZipArchiveEntry entry,
- final InputStream is) throws IOException {
+ private static void extract(final String dir, final ZipArchiveEntry entry, final InputStream is) throws IOException {
final File f = new File(dir, entry.getName());
if (!f.getParentFile().exists()) {
f.getParentFile().mkdirs();
@@ -65,12 +67,8 @@ public final class Lister {
}
if (cl.useStream) {
try (BufferedInputStream fs = new BufferedInputStream(Files.newInputStream(f.toPath()))) {
- final ZipArchiveInputStream zs =
- new ZipArchiveInputStream(fs, cl.encoding, true,
- cl.allowStoredEntriesWithDataDescriptor);
- for (ArchiveEntry entry = zs.getNextEntry();
- entry != null;
- entry = zs.getNextEntry()) {
+ final ZipArchiveInputStream zs = new ZipArchiveInputStream(fs, cl.encoding, true, cl.allowStoredEntriesWithDataDescriptor);
+ for (ArchiveEntry entry = zs.getNextEntry(); entry != null; entry = zs.getNextEntry()) {
final ZipArchiveEntry ze = (ZipArchiveEntry) entry;
list(ze);
if (cl.dir != null) {
@@ -80,8 +78,7 @@ public final class Lister {
}
} else {
try (ZipFile zf = new ZipFile(f, cl.encoding)) {
- for (final Enumeration<ZipArchiveEntry> entries = zf.getEntries();
- entries.hasMoreElements(); ) {
+ for (final Enumeration<ZipArchiveEntry> entries = zf.getEntries(); entries.hasMoreElements();) {
final ZipArchiveEntry ze = entries.nextElement();
list(ze);
if (cl.dir != null) {
@@ -133,8 +130,7 @@ public final class Lister {
}
private static void usage() {
- System.err.println("lister [-enc encoding] [-stream] [-file]"
- + " [+storeddd] [-extract dir] archive");
+ System.err.println("lister [-enc encoding] [-stream] [-file]" + " [+storeddd] [-extract dir] archive");
System.exit(1);
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java
index 3d2adbb0c..36d87a73b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java
@@ -30,15 +30,11 @@ import org.junit.jupiter.api.Test;
/**
* JUnit test for a multi-volume ZIP file.
*
- * Some tools (like 7-zip) allow users to split a large archives into 'volumes'
- * with a given size to fit them into multiple cds, usb drives, or emails with
- * an attachment size limit. It's basically the same file split into chunks of
- * exactly 65536 bytes length. Concatenating volumes yields exactly the original
- * file. There is no mechanism in the ZIP algorithm to accommodate for this.
- * Before commons-compress used to enter an infinite loop on the last entry for
- * such a file. This test is intended to prove that this error doesn't occur
- * anymore. All entries but the last one are returned correctly, the last entry
- * yields an exception.
+ * Some tools (like 7-zip) allow users to split a large archives into 'volumes' with a given size to fit them into multiple cds, usb drives, or emails with an
+ * attachment size limit. It's basically the same file split into chunks of exactly 65536 bytes length. Concatenating volumes yields exactly the original file.
+ * There is no mechanism in the ZIP algorithm to accommodate for this. Before commons-compress used to enter an infinite loop on the last entry for such a file.
+ * This test is intended to prove that this error doesn't occur anymore. All entries but the last one are returned correctly, the last entry yields an
+ * exception.
*/
public class Maven221MultiVolumeTest extends AbstractTest {
@@ -62,8 +58,7 @@ public class Maven221MultiVolumeTest extends AbstractTest {
// @formatter:on
};
- private static final String LAST_ENTRY_NAME =
- "apache-maven-2.2.1/lib/maven-2.2.1-uber.jar";
+ private static final String LAST_ENTRY_NAME = "apache-maven-2.2.1/lib/maven-2.2.1-uber.jar";
@Test
public void testRead7ZipMultiVolumeArchiveForFile() {
@@ -73,8 +68,8 @@ public class Maven221MultiVolumeTest extends AbstractTest {
@Test
public void testRead7ZipMultiVolumeArchiveForStream() throws IOException {
- try (final InputStream archive = newInputStream("apache-maven-2.2.1.zip.001");
- ZipArchiveInputStream zi = new ZipArchiveInputStream(archive, null, false)) {
+ try (InputStream archive = newInputStream("apache-maven-2.2.1.zip.001");
+ ZipArchiveInputStream zi = new ZipArchiveInputStream(archive, null, false)) {
// these are the entries that are supposed to be processed
// correctly without any problems
@@ -98,14 +93,12 @@ public class Maven221MultiVolumeTest extends AbstractTest {
}, "shouldn't be able to read from truncated entry");
assertEquals("Truncated ZIP file", e1.getMessage());
- final IOException e2 = assertThrows(IOException.class, () -> zi.read(buffer),
- "shouldn't be able to read from truncated entry after exception");
+ final IOException e2 = assertThrows(IOException.class, () -> zi.read(buffer), "shouldn't be able to read from truncated entry after exception");
assertEquals("Truncated ZIP file", e2.getMessage());
// and now we get another entry, which should also yield
// an exception
- assertThrows(IOException.class, zi::getNextEntry,
- "shouldn't be able to read another entry from truncated file");
+ assertThrows(IOException.class, zi::getNextEntry, "shouldn't be able to read another entry from truncated file");
}
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java
index aa8b55e21..4c72b87b6 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreatorTest.java
@@ -111,7 +111,7 @@ public class ParallelScatterZipCreatorTest extends AbstractTempDirTest {
final Enumeration<ZipArchiveEntry> entriesInPhysicalOrder = zf.getEntriesInPhysicalOrder();
while (entriesInPhysicalOrder.hasMoreElements()) {
final ZipArchiveEntry zipArchiveEntry = entriesInPhysicalOrder.nextElement();
- try (final InputStream inputStream = zf.getInputStream(zipArchiveEntry)) {
+ try (InputStream inputStream = zf.getInputStream(zipArchiveEntry)) {
final byte[] actual = IOUtils.toByteArray(inputStream);
final byte[] expected = entries.remove(zipArchiveEntry.getName());
assertArrayEquals(expected, actual, "For " + zipArchiveEntry.getName());
@@ -324,7 +324,7 @@ public class ParallelScatterZipCreatorTest extends AbstractTempDirTest {
final InputStreamSupplier iss = () -> {
try {
return Files.newInputStream(file.toPath());
- } catch (final IOException e) {
+ } catch (IOException e) {
return null;
}
};
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSample.java b/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSample.java
index a785de0a2..dab88ab15 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSample.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSample.java
@@ -34,12 +34,11 @@ public class ScatterSample {
if (zipArchiveEntry.isDirectory() && !zipArchiveEntry.isUnixSymlink()) {
dirs.addArchiveEntry(ZipArchiveEntryRequest.createZipArchiveEntryRequest(zipArchiveEntry, streamSupplier));
} else {
- scatterZipCreator.addArchiveEntry( zipArchiveEntry, streamSupplier);
+ scatterZipCreator.addArchiveEntry(zipArchiveEntry, streamSupplier);
}
}
- public void writeTo(final ZipArchiveOutputStream zipArchiveOutputStream)
- throws IOException, ExecutionException, InterruptedException {
+ public void writeTo(final ZipArchiveOutputStream zipArchiveOutputStream) throws IOException, ExecutionException, InterruptedException {
dirs.writeTo(zipArchiveOutputStream);
dirs.close();
scatterZipCreator.writeTo(zipArchiveOutputStream);
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSampleTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSampleTest.java
index 69fac8d1a..91b3a9c29 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSampleTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ScatterSampleTest.java
@@ -34,10 +34,10 @@ import org.junit.jupiter.api.Test;
public class ScatterSampleTest extends AbstractTempDirTest {
private void checkFile(final File result) throws IOException {
- try (final ZipFile zipFile = new ZipFile(result)) {
+ try (ZipFile zipFile = new ZipFile(result)) {
final ZipArchiveEntry archiveEntry1 = zipFile.getEntries().nextElement();
assertEquals("test1.xml", archiveEntry1.getName());
- try (final InputStream inputStream = zipFile.getInputStream(archiveEntry1)) {
+ try (InputStream inputStream = zipFile.getInputStream(archiveEntry1)) {
final byte[] b = new byte[6];
final int i = IOUtils.readFully(inputStream, b);
assertEquals(5, i);
@@ -55,7 +55,7 @@ public class ScatterSampleTest extends AbstractTempDirTest {
final InputStreamSupplier supp = () -> new ByteArrayInputStream("Hello".getBytes());
scatterSample.addEntry(archiveEntry, supp);
- try (final ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(result)) {
+ try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(result)) {
scatterSample.writeTo(zipArchiveOutputStream);
}
}
@@ -66,4 +66,4 @@ public class ScatterSampleTest extends AbstractTempDirTest {
createFile(result);
checkFile(result);
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
index bfd1a0a38..4d7c62d22 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/X5455_ExtendedTimestampTest.java
@@ -58,12 +58,9 @@ public class X5455_ExtendedTimestampTest {
}
/**
- * InfoZIP seems to adjust the time stored inside the LFH and CD
- * to GMT when writing ZIPs while java.util.zip.ZipEntry thinks it
- * was in local time.
+ * InfoZIP seems to adjust the time stored inside the LFH and CD to GMT when writing ZIPs while java.util.zip.ZipEntry thinks it was in local time.
*
- * The archive read in {@link #testSampleFile} has been created
- * with GMT-8, so we need to adjust for the difference.
+ * The archive read in {@link #testSampleFile} has been created with GMT-8, so we need to adjust for the difference.
*/
private static Date adjustFromGMTToExpectedOffset(final Date from) {
final Calendar cal = Calendar.getInstance();
@@ -76,7 +73,9 @@ public class X5455_ExtendedTimestampTest {
return cal.getTime();
}
- private static boolean isFlagSet(final byte data, final byte flag) { return (data & flag) == flag; }
+ private static boolean isFlagSet(final byte data, final byte flag) {
+ return (data & flag) == flag;
+ }
/**
* The extended field (xf) we are testing.
@@ -91,15 +90,10 @@ public class X5455_ExtendedTimestampTest {
xf = new X5455_ExtendedTimestamp();
}
- private void parseReparse(
- final byte providedFlags,
- final ZipLong time,
- final byte expectedFlags,
- final byte[] expectedLocal,
- final byte[] almostExpectedCentral
- ) throws ZipException {
+ private void parseReparse(final byte providedFlags, final ZipLong time, final byte expectedFlags, final byte[] expectedLocal,
+ final byte[] almostExpectedCentral) throws ZipException {
- // We're responsible for expectedCentral's flags. Too annoying to set in caller.
+ // We're responsible for expectedCentral's flags. Too annoying to set in caller.
final byte[] expectedCentral = new byte[almostExpectedCentral.length];
System.arraycopy(almostExpectedCentral, 0, expectedCentral, 0, almostExpectedCentral.length);
expectedCentral[0] = expectedFlags;
@@ -146,11 +140,7 @@ public class X5455_ExtendedTimestampTest {
}
}
- private void parseReparse(
- final ZipLong time,
- final byte[] expectedLocal,
- final byte[] almostExpectedCentral
- ) throws ZipException {
+ private void parseReparse(final ZipLong time, final byte[] expectedLocal, final byte[] almostExpectedCentral) throws ZipException {
parseReparse(expectedLocal[0], time, expectedLocal[0], expectedLocal, almostExpectedCentral);
}
@@ -319,7 +309,6 @@ public class X5455_ExtendedTimestampTest {
assertNull(xf.getCreateTime());
assertFalse(xf.isBit2_createTimePresent());
-
// initialize for flags
xf.setModifyTime(time);
xf.setAccessTime(time);
@@ -416,27 +405,23 @@ public class X5455_ExtendedTimestampTest {
/*
* Recall the spec:
*
- * 0x5455 Short tag for this extra block type ("UT")
- * TSize Short total data size for this block
- * Flags Byte info bits
- * (ModTime) Long time of last modification (UTC/GMT)
- * (AcTime) Long time of last access (UTC/GMT)
- * (CrTime) Long time of original creation (UTC/GMT)
+ * 0x5455 Short tag for this extra block type ("UT") TSize Short total data size for this block Flags Byte info bits (ModTime) Long time of last
+ * modification (UTC/GMT) (AcTime) Long time of last access (UTC/GMT) (CrTime) Long time of original creation (UTC/GMT)
*/
- final byte[] NULL_FLAGS = {0};
- final byte[] AC_CENTRAL = {2}; // central data only contains the AC flag and no actual data
- final byte[] CR_CENTRAL = {4}; // central data only contains the CR flag and no actual data
-
- final byte[] MOD_ZERO = {1, 0, 0, 0, 0};
- final byte[] MOD_MAX = {1, -1, -1, -1, 0x7f};
- final byte[] AC_ZERO = {2, 0, 0, 0, 0};
- final byte[] AC_MAX = {2, -1, -1, -1, 0x7f};
- final byte[] CR_ZERO = {4, 0, 0, 0, 0};
- final byte[] CR_MAX = {4, -1, -1, -1, 0x7f};
- final byte[] MOD_AC_ZERO = {3, 0, 0, 0, 0, 0, 0, 0, 0};
- final byte[] MOD_AC_MAX = {3, -1, -1, -1, 0x7f, -1, -1, -1, 0x7f};
- final byte[] MOD_AC_CR_ZERO = {7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- final byte[] MOD_AC_CR_MAX = {7, -1, -1, -1, 0x7f, -1, -1, -1, 0x7f, -1, -1, -1, 0x7f};
+ final byte[] NULL_FLAGS = { 0 };
+ final byte[] AC_CENTRAL = { 2 }; // central data only contains the AC flag and no actual data
+ final byte[] CR_CENTRAL = { 4 }; // central data only contains the CR flag and no actual data
+
+ final byte[] MOD_ZERO = { 1, 0, 0, 0, 0 };
+ final byte[] MOD_MAX = { 1, -1, -1, -1, 0x7f };
+ final byte[] AC_ZERO = { 2, 0, 0, 0, 0 };
+ final byte[] AC_MAX = { 2, -1, -1, -1, 0x7f };
+ final byte[] CR_ZERO = { 4, 0, 0, 0, 0 };
+ final byte[] CR_MAX = { 4, -1, -1, -1, 0x7f };
+ final byte[] MOD_AC_ZERO = { 3, 0, 0, 0, 0, 0, 0, 0, 0 };
+ final byte[] MOD_AC_MAX = { 3, -1, -1, -1, 0x7f, -1, -1, -1, 0x7f };
+ final byte[] MOD_AC_CR_ZERO = { 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ final byte[] MOD_AC_CR_MAX = { 7, -1, -1, -1, 0x7f, -1, -1, -1, 0x7f, -1, -1, -1, 0x7f };
parseReparse(null, NULL_FLAGS, NULL_FLAGS);
parseReparse(ZERO_TIME, MOD_ZERO, MOD_ZERO);
@@ -462,9 +447,7 @@ public class X5455_ExtendedTimestampTest {
@Test
public void testResetsFlagsWhenLocalFileArrayIsTooShort() throws Exception {
- final byte[] local = {
- 7
- }; // claims all three time values would be present, but they are not
+ final byte[] local = { 7 }; // claims all three time values would be present, but they are not
xf.parseFromLocalFileData(local, 0, 1);
assertArrayEquals(new byte[1], xf.getLocalFileDataData());
}
@@ -473,36 +456,24 @@ public class X5455_ExtendedTimestampTest {
public void testSampleFile() throws Exception {
/*
- Contains entries with zipTime, accessTime, and modifyTime.
- The file name tells you the year we tried to set the time to
- (Jan 1st, Midnight, UTC).
-
- For example:
-
- COMPRESS-210_unix_time_zip_test/1999
- COMPRESS-210_unix_time_zip_test/2000
- COMPRESS-210_unix_time_zip_test/2108
-
- File's last-modified is 1st second after midnight.
- Zip-time's 2-second granularity rounds that up to 2nd second.
- File's last-access is 3rd second after midnight.
-
- So, from example above:
-
- 1999's zip time: Jan 1st, 1999-01-01/00:00:02
- 1999's mod time: Jan 1st, 1999-01-01/00:00:01
- 1999's acc time: Jan 1st, 1999-01-01/00:00:03
-
- Starting with a patch release of Java8, "zip time" actually
- uses the extended time stamp field itself and should be the
- same as "mod time".
- http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/90df6756406f
-
- Starting with Java9 the parser for extended time stamps has
- been fixed to use signed integers which was detected during
- the triage of COMPRESS-416. Signed integers is the correct
- format and Compress 1.15 has started to use signed integers as
- well.
+ * Contains entries with zipTime, accessTime, and modifyTime. The file name tells you the year we tried to set the time to (Jan 1st, Midnight, UTC).
+ *
+ * For example:
+ *
+ * COMPRESS-210_unix_time_zip_test/1999 COMPRESS-210_unix_time_zip_test/2000 COMPRESS-210_unix_time_zip_test/2108
+ *
+ * File's last-modified is 1st second after midnight. Zip-time's 2-second granularity rounds that up to 2nd second. File's last-access is 3rd second
+ * after midnight.
+ *
+ * So, from example above:
+ *
+ * 1999's zip time: Jan 1st, 1999-01-01/00:00:02 1999's mod time: Jan 1st, 1999-01-01/00:00:01 1999's acc time: Jan 1st, 1999-01-01/00:00:03
+ *
+ * Starting with a patch release of Java8, "zip time" actually uses the extended time stamp field itself and should be the same as "mod time".
+ * http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/90df6756406f
+ *
+ * Starting with Java9 the parser for extended time stamps has been fixed to use signed integers which was detected during the triage of COMPRESS-416.
+ * Signed integers is the correct format and Compress 1.15 has started to use signed integers as well.
*/
final File archive = AbstractTest.getFile("COMPRESS-210_unix_time_zip_test.zip");
@@ -524,7 +495,7 @@ public class X5455_ExtendedTimestampTest {
int year;
try {
year = Integer.parseInt(yearString);
- } catch (final NumberFormatException nfe) {
+ } catch (NumberFormatException nfe) {
// setTime.sh, skip
continue;
}
@@ -534,17 +505,14 @@ public class X5455_ExtendedTimestampTest {
final Date m = xf.getModifyJavaTime();
/*
- We must distinguish three cases:
- - Java has read the extended time field itself and agrees with us (Java9 or Java8 and years prior to
- 2038)
- - Java has read the extended time field but found a year >= 2038 (Java8)
- - Java hasn't read the extended time field at all (Java7- or early Java8)
- */
+ * We must distinguish three cases: - Java has read the extended time field itself and agrees with us (Java9 or Java8 and years prior to 2038) -
+ * Java has read the extended time field but found a year >= 2038 (Java8) - Java hasn't read the extended time field at all (Java7- or early
+ * Java8)
+ */
final boolean zipTimeUsesExtendedTimestampCorrectly = rawZ.equals(m);
final boolean zipTimeUsesExtendedTimestampButUnsigned = year > 2037 && rawZ.getSeconds() == 1;
- final boolean zipTimeUsesExtendedTimestamp = zipTimeUsesExtendedTimestampCorrectly
- || zipTimeUsesExtendedTimestampButUnsigned;
+ final boolean zipTimeUsesExtendedTimestamp = zipTimeUsesExtendedTimestampCorrectly || zipTimeUsesExtendedTimestampButUnsigned;
final Date z = zipTimeUsesExtendedTimestamp ? rawZ : adjustFromGMTToExpectedOffset(rawZ);
final Date a = xf.getAccessJavaTime();
@@ -588,8 +556,8 @@ public class X5455_ExtendedTimestampTest {
instance.clear();
instance.set(1997, 8, 24, 15, 10, 2);
final Date date = instance.getTime();
- try (final OutputStream out = Files.newOutputStream(output.toPath());
- ZipArchiveOutputStream os = new ZipArchiveOutputStream(out)) {
+ try (OutputStream out = Files.newOutputStream(output.toPath());
+ ZipArchiveOutputStream os = new ZipArchiveOutputStream(out)) {
final ZipArchiveEntry ze = new ZipArchiveEntry("foo");
xf.setModifyJavaTime(date);
xf.setFlags((byte) 1);
@@ -598,7 +566,7 @@ public class X5455_ExtendedTimestampTest {
os.closeArchiveEntry();
}
- try (final ZipFile zf = new ZipFile(output)) {
+ try (ZipFile zf = new ZipFile(output)) {
final ZipArchiveEntry ze = zf.getEntry("foo");
final X5455_ExtendedTimestamp ext = (X5455_ExtendedTimestamp) ze.getExtraField(X5455);
assertNotNull(ext);
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java
index 76ed935a0..fbc1f16f7 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java
@@ -37,23 +37,18 @@ public class X7875_NewUnixTest {
private static final ZipShort X7875 = new ZipShort(0x7875);
- private static byte[] trimTest(final byte[] b) { return X7875_NewUnix.trimLeadingZeroesForceMinLength(b); }
+ private static byte[] trimTest(final byte[] b) {
+ return X7875_NewUnix.trimLeadingZeroesForceMinLength(b);
+ }
private X7875_NewUnix xf;
-
@BeforeEach
public void before() {
xf = new X7875_NewUnix();
}
- private void parseReparse(
- final long uid,
- final long gid,
- final byte[] expected,
- final long expectedUID,
- final long expectedGID
- ) throws ZipException {
+ private void parseReparse(final long uid, final long gid, final byte[] expected, final long expectedUID, final long expectedGID) throws ZipException {
// Initial local parse (init with garbage to avoid defaults causing test to pass).
xf.setUID(54321);
@@ -73,17 +68,15 @@ public class X7875_NewUnixTest {
byte[] result = xf.getLocalFileDataData();
if (expected.length < 5) {
// We never emit zero-length entries.
- assertArrayEquals(new byte[]{1, 1, 0, 1, 0}, result);
+ assertArrayEquals(new byte[] { 1, 1, 0, 1, 0 }, result);
} else {
assertArrayEquals(expected, result);
}
-
-
// And now we re-parse:
xf.parseFromLocalFileData(result, 0, result.length);
- // Did uid/gid change from re-parse? They shouldn't!
+ // Did uid/gid change from re-parse? They shouldn't!
assertEquals(expectedUID, xf.getUID());
assertEquals(expectedGID, xf.getGID());
@@ -94,7 +87,7 @@ public class X7875_NewUnixTest {
// And now we re-parse:
xf.parseFromCentralDirectoryData(result, 0, result.length);
- // Did uid/gid change from 2nd re-parse? They shouldn't!
+ // Did uid/gid change from 2nd re-parse? They shouldn't!
assertEquals(expectedUID, xf.getUID());
assertEquals(expectedGID, xf.getGID());
}
@@ -119,28 +112,28 @@ public class X7875_NewUnixTest {
public void testParseReparse() throws ZipException {
// Version=1, Len=0, Len=0.
- final byte[] ZERO_LEN = {1, 0, 0};
+ final byte[] ZERO_LEN = { 1, 0, 0 };
// Version=1, Len=1, zero, Len=1, zero.
- final byte[] ZERO_UID_GID = {1, 1, 0, 1, 0};
+ final byte[] ZERO_UID_GID = { 1, 1, 0, 1, 0 };
// Version=1, Len=1, one, Len=1, one
- final byte[] ONE_UID_GID = {1, 1, 1, 1, 1};
+ final byte[] ONE_UID_GID = { 1, 1, 1, 1, 1 };
// Version=1, Len=2, one thousand, Len=2, one thousand
- final byte[] ONE_THOUSAND_UID_GID = {1, 2, -24, 3, 2, -24, 3};
+ final byte[] ONE_THOUSAND_UID_GID = { 1, 2, -24, 3, 2, -24, 3 };
- // (2^32 - 2). I guess they avoid (2^32 - 1) since it's identical to -1 in
+ // (2^32 - 2). I guess they avoid (2^32 - 1) since it's identical to -1 in
// two's complement, and -1 often has a special meaning.
- final byte[] UNIX_MAX_UID_GID = {1, 4, -2, -1, -1, -1, 4, -2, -1, -1, -1};
+ final byte[] UNIX_MAX_UID_GID = { 1, 4, -2, -1, -1, -1, 4, -2, -1, -1, -1 };
// Version=1, Len=5, 2^32, Len=5, 2^32 + 1
- // Esoteric test: can we handle 40 bit numbers?
- final byte[] LENGTH_5 = {1, 5, 0, 0, 0, 0, 1, 5, 1, 0, 0, 0, 1};
+ // Esoteric test: can we handle 40 bit numbers?
+ final byte[] LENGTH_5 = { 1, 5, 0, 0, 0, 0, 1, 5, 1, 0, 0, 0, 1 };
// Version=1, Len=8, 2^63 - 2, Len=8, 2^63 - 1
- // Esoteric test: can we handle 64-bit numbers?
- final byte[] LENGTH_8 = {1, 8, -2, -1, -1, -1, -1, -1, -1, 127, 8, -1, -1, -1, -1, -1, -1, -1, 127};
+ // Esoteric test: can we handle 64-bit numbers?
+ final byte[] LENGTH_8 = { 1, 8, -2, -1, -1, -1, -1, -1, -1, 127, 8, -1, -1, -1, -1, -1, -1, -1, 127 };
final long TWO_TO_32 = 0x100000000L;
final long MAX = TWO_TO_32 - 2;
@@ -155,16 +148,16 @@ public class X7875_NewUnixTest {
parseReparse(Long.MAX_VALUE - 1, Long.MAX_VALUE, LENGTH_8, Long.MAX_VALUE - 1, Long.MAX_VALUE);
// We never emit this, but we should be able to parse it:
- final byte[] SPURIOUS_ZEROES_1 = {1, 4, -1, 0, 0, 0, 4, -128, 0, 0, 0};
- final byte[] EXPECTED_1 = {1, 1, -1, 1, -128};
+ final byte[] SPURIOUS_ZEROES_1 = { 1, 4, -1, 0, 0, 0, 4, -128, 0, 0, 0 };
+ final byte[] EXPECTED_1 = { 1, 1, -1, 1, -128 };
xf.parseFromLocalFileData(SPURIOUS_ZEROES_1, 0, SPURIOUS_ZEROES_1.length);
assertEquals(255, xf.getUID());
assertEquals(128, xf.getGID());
assertArrayEquals(EXPECTED_1, xf.getLocalFileDataData());
- final byte[] SPURIOUS_ZEROES_2 = {1, 4, -1, -1, 0, 0, 4, 1, 2, 0, 0};
- final byte[] EXPECTED_2 = {1, 2, -1, -1, 2, 1, 2};
+ final byte[] SPURIOUS_ZEROES_2 = { 1, 4, -1, -1, 0, 0, 4, 1, 2, 0, 0 };
+ final byte[] EXPECTED_2 = { 1, 2, -1, -1, 2, 1, 2 };
xf.parseFromLocalFileData(SPURIOUS_ZEROES_2, 0, SPURIOUS_ZEROES_2.length);
assertEquals(65535, xf.getUID());
@@ -210,21 +203,20 @@ public class X7875_NewUnixTest {
}
}
-
@Test
public void testTrimLeadingZeroesForceMinLength4() {
final byte[] NULL = null;
final byte[] EMPTY = ByteUtils.EMPTY_BYTE_ARRAY;
- final byte[] ONE_ZERO = {0};
- final byte[] TWO_ZEROES = {0, 0};
- final byte[] FOUR_ZEROES = {0, 0, 0, 0};
- final byte[] SEQUENCE = {1, 2, 3};
- final byte[] SEQUENCE_LEADING_ZERO = {0, 1, 2, 3};
- final byte[] SEQUENCE_LEADING_ZEROES = {0, 0, 0, 0, 0, 0, 0, 1, 2, 3};
- final byte[] TRAILING_ZERO = {1, 2, 3, 0};
- final byte[] PADDING_ZERO = {0, 1, 2, 3, 0};
- final byte[] SEQUENCE6 = {1, 2, 3, 4, 5, 6};
- final byte[] SEQUENCE6_LEADING_ZERO = {0, 1, 2, 3, 4, 5, 6};
+ final byte[] ONE_ZERO = { 0 };
+ final byte[] TWO_ZEROES = { 0, 0 };
+ final byte[] FOUR_ZEROES = { 0, 0, 0, 0 };
+ final byte[] SEQUENCE = { 1, 2, 3 };
+ final byte[] SEQUENCE_LEADING_ZERO = { 0, 1, 2, 3 };
+ final byte[] SEQUENCE_LEADING_ZEROES = { 0, 0, 0, 0, 0, 0, 0, 1, 2, 3 };
+ final byte[] TRAILING_ZERO = { 1, 2, 3, 0 };
+ final byte[] PADDING_ZERO = { 0, 1, 2, 3, 0 };
+ final byte[] SEQUENCE6 = { 1, 2, 3, 4, 5, 6 };
+ final byte[] SEQUENCE6_LEADING_ZERO = { 0, 1, 2, 3, 4, 5, 6 };
assertSame(NULL, trimTest(NULL));
assertArrayEquals(ONE_ZERO, trimTest(EMPTY));
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java
index 58b5c671e..b093f0a2c 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java
@@ -27,14 +27,9 @@ import org.junit.jupiter.api.Test;
public class Zip64ExtendedInformationExtraFieldTest {
- private static final ZipEightByteInteger SIZE =
- new ZipEightByteInteger(0x12345678);
- private static final ZipEightByteInteger CSIZE =
- new ZipEightByteInteger(0x9ABCDEF);
- private static final ZipEightByteInteger OFF =
- new ZipEightByteInteger(BigInteger.valueOf(0xABCDEF091234567L)
- .shiftLeft(4)
- .setBit(3));
+ private static final ZipEightByteInteger SIZE = new ZipEightByteInteger(0x12345678);
+ private static final ZipEightByteInteger CSIZE = new ZipEightByteInteger(0x9ABCDEF);
+ private static final ZipEightByteInteger OFF = new ZipEightByteInteger(BigInteger.valueOf(0xABCDEF091234567L).shiftLeft(4).setBit(3));
private static final ZipLong DISK = new ZipLong(0x12);
private static void checkDisk(final byte[] b, final int off) {
@@ -76,8 +71,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testReadCDSizesAndOffset() throws ZipException {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField();
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField();
final byte[] b = new byte[24];
System.arraycopy(SIZE.getBytes(), 0, b, 0, 8);
System.arraycopy(CSIZE.getBytes(), 0, b, 8, 8);
@@ -91,8 +85,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testReadCDSizesOffsetAndDisk() throws ZipException {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField();
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField();
final byte[] b = new byte[28];
System.arraycopy(SIZE.getBytes(), 0, b, 0, 8);
System.arraycopy(CSIZE.getBytes(), 0, b, 8, 8);
@@ -107,8 +100,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testReadCDSomethingAndDisk() throws ZipException {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField();
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField();
final byte[] b = new byte[12];
System.arraycopy(SIZE.getBytes(), 0, b, 0, 8);
System.arraycopy(DISK.getBytes(), 0, b, 8, 4);
@@ -121,8 +113,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testReadLFHSizesAndDisk() throws ZipException {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField();
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField();
final byte[] b = new byte[20];
System.arraycopy(SIZE.getBytes(), 0, b, 0, 8);
System.arraycopy(CSIZE.getBytes(), 0, b, 8, 8);
@@ -136,8 +127,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testReadLFHSizesAndOffset() throws ZipException {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField();
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField();
final byte[] b = new byte[24];
System.arraycopy(SIZE.getBytes(), 0, b, 0, 8);
System.arraycopy(CSIZE.getBytes(), 0, b, 8, 8);
@@ -151,8 +141,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testReadLFHSizesOffsetAndDisk() throws ZipException {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField();
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField();
final byte[] b = new byte[28];
System.arraycopy(SIZE.getBytes(), 0, b, 0, 8);
System.arraycopy(CSIZE.getBytes(), 0, b, 8, 8);
@@ -167,8 +156,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testReadLFHSizesOnly() throws ZipException {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField();
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField();
final byte[] b = new byte[16];
System.arraycopy(SIZE.getBytes(), 0, b, 0, 8);
System.arraycopy(CSIZE.getBytes(), 0, b, 8, 8);
@@ -181,8 +169,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testReparseCDSingleEightByteData() throws ZipException {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField();
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField();
final byte[] b = new byte[8];
System.arraycopy(SIZE.getBytes(), 0, b, 0, 8);
f.parseFromCentralDirectoryData(b, 0, b.length);
@@ -207,8 +194,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testWriteCDOnlySizes() {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField(SIZE, CSIZE);
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField(SIZE, CSIZE);
assertEquals(new ZipShort(16), f.getCentralDirectoryLength());
final byte[] b = f.getCentralDirectoryData();
assertEquals(16, b.length);
@@ -217,8 +203,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testWriteCDSizeAndDisk() {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField(SIZE, CSIZE, null, DISK);
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField(SIZE, CSIZE, null, DISK);
assertEquals(new ZipShort(20), f.getCentralDirectoryLength());
final byte[] b = f.getCentralDirectoryData();
assertEquals(20, b.length);
@@ -228,8 +213,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testWriteCDSizeAndOffset() {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField(SIZE, CSIZE, OFF, null);
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField(SIZE, CSIZE, OFF, null);
assertEquals(new ZipShort(24), f.getCentralDirectoryLength());
final byte[] b = f.getCentralDirectoryData();
assertEquals(24, b.length);
@@ -239,8 +223,7 @@ public class Zip64ExtendedInformationExtraFieldTest {
@Test
public void testWriteCDSizeOffsetAndDisk() {
- final Zip64ExtendedInformationExtraField f =
- new Zip64ExtendedInformationExtraField(SIZE, CSIZE, OFF, DISK);
+ final Zip64ExtendedInformationExtraField f = new Zip64ExtendedInformationExtraField(SIZE, CSIZE, OFF, DISK);
assertEquals(new ZipShort(28), f.getCentralDirectoryLength());
final byte[] b = f.getCentralDirectoryData();
assertEquals(28, b.length);
@@ -248,4 +231,4 @@ public class Zip64ExtendedInformationExtraFieldTest {
checkOffset(b, 16);
checkDisk(b, 24);
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java
index 541e4995a..daddfcb01 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java
@@ -47,27 +47,24 @@ public class Zip64SupportIT {
interface ZipOutputTest {
void test(File f, ZipArchiveOutputStream zos) throws IOException;
}
+
private static final long FIVE_BILLION = 5000000000L;
private static final int ONE_MILLION = 1000000;
private static final int ONE_HUNDRED_THOUSAND = 100000;
- private static final ZipOutputTest write100KFilesModeNever =
- (f, zos) -> {
- zos.setUseZip64(Zip64Mode.Never);
- final Zip64RequiredException ex = assertThrows(Zip64RequiredException.class,
- () -> write100KFilesToStream(zos), "expected a Zip64RequiredException");
- assertEquals(Zip64RequiredException.TOO_MANY_ENTRIES_MESSAGE,
- ex.getMessage());
- };
-
- private static final ZipOutputTest write3EntriesCreatingBigArchiveModeNever =
- (f, zos) -> {
- zos.setUseZip64(Zip64Mode.Never);
- final Zip64RequiredException ex = assertThrows(Zip64RequiredException.class,
- () -> write3EntriesCreatingBigArchiveToStream(zos), "expected a Zip64RequiredException");
- assertEquals(Zip64RequiredException.ARCHIVE_TOO_BIG_MESSAGE, ex.getMessage());
- };
+ private static final ZipOutputTest write100KFilesModeNever = (f, zos) -> {
+ zos.setUseZip64(Zip64Mode.Never);
+ final Zip64RequiredException ex = assertThrows(Zip64RequiredException.class, () -> write100KFilesToStream(zos), "expected a Zip64RequiredException");
+ assertEquals(Zip64RequiredException.TOO_MANY_ENTRIES_MESSAGE, ex.getMessage());
+ };
+
+ private static final ZipOutputTest write3EntriesCreatingBigArchiveModeNever = (f, zos) -> {
+ zos.setUseZip64(Zip64Mode.Never);
+ final Zip64RequiredException ex = assertThrows(Zip64RequiredException.class, () -> write3EntriesCreatingBigArchiveToStream(zos),
+ "expected a Zip64RequiredException");
+ assertEquals(Zip64RequiredException.ARCHIVE_TOO_BIG_MESSAGE, ex.getMessage());
+ };
private static File get100KFileFile() throws Throwable {
return getFile("100k_Files.zip");
@@ -113,14 +110,12 @@ public class Zip64SupportIT {
return getFile("5GB_of_Zeros_WinZip.zip");
}
- private static long getLengthAndPositionAtCentralDirectory(final RandomAccessFile a)
- throws IOException {
+ private static long getLengthAndPositionAtCentralDirectory(final RandomAccessFile a) throws IOException {
final long end = a.length();
a.seek(end - 22 - 20);
final byte[] sig = new byte[4];
a.readFully(sig);
- if (sig[0] != (byte) 0x50 || sig[1] != (byte) 0x4b
- || sig[2] != 6 || sig[3] != 7) {
+ if (sig[0] != (byte) 0x50 || sig[1] != (byte) 0x4b || sig[2] != 6 || sig[3] != 7) {
// not a ZIP64 archive
return getLengthAndPositionAtCentralDirectory32(a, end);
}
@@ -134,8 +129,7 @@ public class Zip64SupportIT {
return end;
}
- private static long getLengthAndPositionAtCentralDirectory32(final RandomAccessFile a, final long end)
- throws IOException {
+ private static long getLengthAndPositionAtCentralDirectory32(final RandomAccessFile a, final long end) throws IOException {
a.seek(end - 22 + 16);
final byte[] cdOffset = new byte[4];
a.readFully(cdOffset);
@@ -164,13 +158,12 @@ public class Zip64SupportIT {
}
}
- private static void read100KFilesUsingZipFileImpl(final File f)
- throws IOException {
+ private static void read100KFilesUsingZipFileImpl(final File f) throws IOException {
ZipFile zf = null;
try {
zf = new ZipFile(f);
int files = 0;
- for (final Enumeration<ZipArchiveEntry> e = zf.getEntries(); e.hasMoreElements(); ) {
+ for (final Enumeration<ZipArchiveEntry> e = zf.getEntries(); e.hasMoreElements();) {
final ZipArchiveEntry zae = e.nextElement();
if (!zae.isDirectory()) {
files++;
@@ -183,8 +176,7 @@ public class Zip64SupportIT {
}
}
- private static void read5GBOfZerosImpl(final File f, final String expectedName)
- throws IOException {
+ private static void read5GBOfZerosImpl(final File f, final String expectedName) throws IOException {
try (InputStream fin = Files.newInputStream(f.toPath());
ZipArchiveInputStream zin = new ZipArchiveInputStream(fin)) {
ZipArchiveEntry zae = zin.getNextZipEntry();
@@ -211,9 +203,7 @@ public class Zip64SupportIT {
}
}
- private static void read5GBOfZerosUsingZipFileImpl(final File f,
- final String expectedName)
- throws IOException {
+ private static void read5GBOfZerosUsingZipFileImpl(final File f, final String expectedName) throws IOException {
ZipFile zf = null;
try {
zf = new ZipFile(f);
@@ -247,17 +237,12 @@ public class Zip64SupportIT {
}
}
- private static void withTemporaryArchive(final String testName,
- final ZipOutputTest test,
- final boolean useRandomAccessFile) throws Throwable {
+ private static void withTemporaryArchive(final String testName, final ZipOutputTest test, final boolean useRandomAccessFile) throws Throwable {
withTemporaryArchive(testName, test, useRandomAccessFile, null);
}
- private static void withTemporaryArchive(final String testName,
- final ZipOutputTest test,
- final boolean useRandomAccessFile,
- final Long splitSize)
- throws Throwable {
+ private static void withTemporaryArchive(final String testName, final ZipOutputTest test, final boolean useRandomAccessFile, final Long splitSize)
+ throws Throwable {
File f = getTempFile(testName);
File dir = null;
if (splitSize != null) {
@@ -267,19 +252,16 @@ public class Zip64SupportIT {
f = new File(dir, "commons-compress-" + testName + ".zip");
}
BufferedOutputStream os = null;
- ZipArchiveOutputStream zos = useRandomAccessFile
- ? new ZipArchiveOutputStream(f)
- : new ZipArchiveOutputStream(os = new BufferedOutputStream(Files.newOutputStream(f.toPath())));
+ ZipArchiveOutputStream zos = useRandomAccessFile ? new ZipArchiveOutputStream(f)
+ : new ZipArchiveOutputStream(os = new BufferedOutputStream(Files.newOutputStream(f.toPath())));
if (splitSize != null) {
zos = new ZipArchiveOutputStream(f, splitSize);
}
try {
test.test(f, zos);
- } catch (final IOException ex) {
- System.err.println("Failed to write archive because of: "
- + ex.getMessage()
- + " - likely not enough disk space.");
+ } catch (IOException ex) {
+ System.err.println("Failed to write archive because of: " + ex.getMessage() + " - likely not enough disk space.");
assumeTrue(false);
} finally {
try {
@@ -306,99 +288,84 @@ public class Zip64SupportIT {
private static ZipOutputTest write100KFiles(final Zip64Mode mode) {
return (f, zos) -> {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- write100KFilesToStream(zos);
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- final long end = a.length();
-
- // validate "end of central directory" is at
- // the end of the file and contains the magic
- // value 0xFFFF as "number of entries".
- a.seek(end
- - 22 /* length of EOCD without file comment */);
- final byte[] eocd = new byte[12];
- a.readFully(eocd);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 5, 6,
- // disk numbers
- 0, 0, 0, 0,
- // entries
- (byte) 0xff, (byte) 0xff,
- (byte) 0xff, (byte) 0xff,
- }, eocd);
-
- // validate "Zip64 end of central directory
- // locator" is right in front of the EOCD and
- // the location of the "Zip64 end of central
- // directory record" seems correct
- final long expectedZ64EocdOffset = end - 22 /* eocd.length */
- - 20 /* z64 eocd locator.length */
- - 56 /* z64 eocd without extensible data sector */;
- final byte[] loc =
- ZipEightByteInteger.getBytes(expectedZ64EocdOffset);
- a.seek(end - 22 - 20);
- final byte[] z64EocdLoc = new byte[20];
- a.readFully(z64EocdLoc);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 6, 7,
- // disk numbers
- 0, 0, 0, 0,
- // location of Zip64 EOCD,
- loc[0], loc[1], loc[2], loc[3],
- loc[4], loc[5], loc[6], loc[7],
- // total number of disks
- 1, 0, 0, 0,
- }, z64EocdLoc);
-
- // validate "Zip64 end of central directory
- // record" is where it is supposed to be, the
- // known values are fine and read the location
- // of the central directory from it
- a.seek(expectedZ64EocdOffset);
- final byte[] z64EocdStart = new byte[40];
- a.readFully(z64EocdStart);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 6, 6,
- // size of z64 EOCD
- 44, 0, 0, 0,
- 0, 0, 0, 0,
- // version made by
- 45, 0,
- // version needed to extract
- 45, 0,
- // disk numbers
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- // number of entries 100k = 0x186A0
- (byte) 0xA0, (byte) 0x86, 1, 0,
- 0, 0, 0, 0,
- (byte) 0xA0, (byte) 0x86, 1, 0,
- 0, 0, 0, 0,
- }, z64EocdStart);
- a.seek(expectedZ64EocdOffset + 48 /* skip size */);
- final byte[] cdOffset = new byte[8];
- a.readFully(cdOffset);
- final long cdLoc = ZipEightByteInteger.getLongValue(cdOffset);
-
- // finally verify there really is a central
- // directory entry where the Zip64 EOCD claims
- a.seek(cdLoc);
- final byte[] sig = new byte[4];
- a.readFully(sig);
- assertArrayEquals(new byte[] {
- (byte) 0x50, (byte) 0x4b, 1, 2,
- }, sig);
- }
- };
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
+ }
+ write100KFilesToStream(zos);
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ final long end = a.length();
+
+ // validate "end of central directory" is at
+ // the end of the file and contains the magic
+ // value 0xFFFF as "number of entries".
+ a.seek(end - 22 /* length of EOCD without file comment */);
+ final byte[] eocd = new byte[12];
+ a.readFully(eocd);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 5, 6,
+ // disk numbers
+ 0, 0, 0, 0,
+ // entries
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, }, eocd);
+
+ // validate "Zip64 end of central directory
+ // locator" is right in front of the EOCD and
+ // the location of the "Zip64 end of central
+ // directory record" seems correct
+ final long expectedZ64EocdOffset = end - 22 /* eocd.length */
+ - 20 /* z64 eocd locator.length */
+ - 56 /* z64 eocd without extensible data sector */;
+ final byte[] loc = ZipEightByteInteger.getBytes(expectedZ64EocdOffset);
+ a.seek(end - 22 - 20);
+ final byte[] z64EocdLoc = new byte[20];
+ a.readFully(z64EocdLoc);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 6, 7,
+ // disk numbers
+ 0, 0, 0, 0,
+ // location of Zip64 EOCD,
+ loc[0], loc[1], loc[2], loc[3], loc[4], loc[5], loc[6], loc[7],
+ // total number of disks
+ 1, 0, 0, 0, }, z64EocdLoc);
+
+ // validate "Zip64 end of central directory
+ // record" is where it is supposed to be, the
+ // known values are fine and read the location
+ // of the central directory from it
+ a.seek(expectedZ64EocdOffset);
+ final byte[] z64EocdStart = new byte[40];
+ a.readFully(z64EocdStart);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 6, 6,
+ // size of z64 EOCD
+ 44, 0, 0, 0, 0, 0, 0, 0,
+ // version made by
+ 45, 0,
+ // version needed to extract
+ 45, 0,
+ // disk numbers
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ // number of entries 100k = 0x186A0
+ (byte) 0xA0, (byte) 0x86, 1, 0, 0, 0, 0, 0, (byte) 0xA0, (byte) 0x86, 1, 0, 0, 0, 0, 0, }, z64EocdStart);
+ a.seek(expectedZ64EocdOffset + 48 /* skip size */);
+ final byte[] cdOffset = new byte[8];
+ a.readFully(cdOffset);
+ final long cdLoc = ZipEightByteInteger.getLongValue(cdOffset);
+
+ // finally verify there really is a central
+ // directory entry where the Zip64 EOCD claims
+ a.seek(cdLoc);
+ final byte[] sig = new byte[4];
+ a.readFully(sig);
+ assertArrayEquals(new byte[] { (byte) 0x50, (byte) 0x4b, 1, 2, }, sig);
+ }
+ };
}
- private static void write100KFilesToStream(final ZipArchiveOutputStream zos)
- throws IOException {
+ private static void write100KFilesToStream(final ZipArchiveOutputStream zos) throws IOException {
for (int i = 0; i < ONE_HUNDRED_THOUSAND; i++) {
final ZipArchiveEntry zae = new ZipArchiveEntry(String.valueOf(i));
zae.setSize(0);
@@ -417,122 +384,106 @@ public class Zip64SupportIT {
}
/*
- * Individual sizes don't require ZIP64 but the offset of the
- * third entry is bigger than 0xFFFFFFFF so a ZIP64 extended
- * information is needed inside the central directory.
+ * Individual sizes don't require ZIP64 but the offset of the third entry is bigger than 0xFFFFFFFF so a ZIP64 extended information is needed inside the
+ * central directory.
*
* Creates a temporary archive of approx 5GB in size
*/
- private static ZipOutputTest
- write3EntriesCreatingBigArchive(final Zip64Mode mode, final boolean isSplitArchive) {
+ private static ZipOutputTest write3EntriesCreatingBigArchive(final Zip64Mode mode, final boolean isSplitArchive) {
return (f, zos) -> {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- write3EntriesCreatingBigArchiveToStream(zos);
-
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
- // skip first two entries
- a.skipBytes(2 * 47 /* CD entry of file with
- file name length 1 and no
- extra data */
- + 2 * (mode == Zip64Mode.Always ? 32 : 0)
- /* ZIP64 extra fields if mode is Always */
- );
-
- // grab third entry, verify offset is
- // 0xFFFFFFFF, and it has a ZIP64 extended
- // information extra field
- final byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 45, 0,
- // version needed to extract
- 45, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header, "CDH start");
- // ignore timestamp, CRC, compressed size
- a.skipBytes(12);
- // Original Size
- final byte[] originalSize = new byte[4];
- a.readFully(originalSize);
- if (mode == Zip64Mode.Always) {
- assertArrayEquals(new byte[] {
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- }, originalSize, "CDH original size");
- } else {
- assertArrayEquals(new byte[] {
- 1, 0, 0, 0
- }, originalSize, "CDH original size");
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
}
- final byte[] rest = new byte[19];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // file name length
- 1, 0,
- // extra field length
- (byte) (mode == Zip64Mode.Always? 32 : 12), 0,
- // comment length
- 0, 0,
- // disk number
- (byte) (isSplitArchive? 0xFF : 0), (byte) (isSplitArchive? 0xFF : 0),
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- // offset
- (byte) 0xFF, (byte) 0xFF,
- (byte) 0xFF, (byte) 0xFF,
- // file name
- (byte) '2'
- }, rest, "CDH rest");
- if (mode == Zip64Mode.Always) {
- final byte[] extra1 = new byte[12];
- a.readFully(extra1);
+ write3EntriesCreatingBigArchiveToStream(zos);
+
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
+ // skip first two entries
+ a.skipBytes(2 * 47 /*
+ * CD entry of file with file name length 1 and no extra data
+ */
+ + 2 * (mode == Zip64Mode.Always ? 32 : 0)
+ /* ZIP64 extra fields if mode is Always */
+ );
+
+ // grab third entry, verify offset is
+ // 0xFFFFFFFF, and it has a ZIP64 extended
+ // information extra field
+ final byte[] header = new byte[12];
+ a.readFully(header);
assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size
- 28, 0,
- // Original Size
- 1, 0, 0, 0, 0, 0, 0, 0,
- }, extra1, "CDH extra");
- // skip compressed size
- a.skipBytes(8);
- } else {
- final byte[] extra2 = new byte[4];
- a.readFully(extra2);
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 45, 0,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0 }, header, "CDH start");
+ // ignore timestamp, CRC, compressed size
+ a.skipBytes(12);
+ // Original Size
+ final byte[] originalSize = new byte[4];
+ a.readFully(originalSize);
+ if (mode == Zip64Mode.Always) {
+ assertArrayEquals(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, }, originalSize, "CDH original size");
+ } else {
+ assertArrayEquals(new byte[] { 1, 0, 0, 0 }, originalSize, "CDH original size");
+ }
+ final byte[] rest = new byte[19];
+ a.readFully(rest);
assertArrayEquals(new byte[] {
- // Header-ID
+ // file name length
1, 0,
- // size
- 8, 0,
- }, extra2, "CDH extra");
- }
+ // extra field length
+ (byte) (mode == Zip64Mode.Always ? 32 : 12), 0,
+ // comment length
+ 0, 0,
+ // disk number
+ (byte) (isSplitArchive ? 0xFF : 0), (byte) (isSplitArchive ? 0xFF : 0),
+ // attributes
+ 0, 0, 0, 0, 0, 0,
+ // offset
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name
+ (byte) '2' }, rest, "CDH rest");
+ if (mode == Zip64Mode.Always) {
+ final byte[] extra1 = new byte[12];
+ a.readFully(extra1);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size
+ 28, 0,
+ // Original Size
+ 1, 0, 0, 0, 0, 0, 0, 0, }, extra1, "CDH extra");
+ // skip compressed size
+ a.skipBytes(8);
+ } else {
+ final byte[] extra2 = new byte[4];
+ a.readFully(extra2);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size
+ 8, 0, }, extra2, "CDH extra");
+ }
- // read offset of LFH
- final byte[] offset = new byte[8];
- a.readFully(offset);
- // verify there is an LFH where the CD claims it
- a.seek(ZipEightByteInteger.getLongValue(offset));
- final byte[] sig = new byte[4];
- a.readFully(sig);
- assertArrayEquals(new byte[] {
- (byte) 0x50, (byte) 0x4b, 3, 4,
- }, sig, "LFH signature");
- }
- };
+ // read offset of LFH
+ final byte[] offset = new byte[8];
+ a.readFully(offset);
+ // verify there is an LFH where the CD claims it
+ a.seek(ZipEightByteInteger.getLongValue(offset));
+ final byte[] sig = new byte[4];
+ a.readFully(sig);
+ assertArrayEquals(new byte[] { (byte) 0x50, (byte) 0x4b, 3, 4, }, sig, "LFH signature");
+ }
+ };
}
- private static void
- write3EntriesCreatingBigArchiveToStream(final ZipArchiveOutputStream zos)
- throws IOException {
+ private static void write3EntriesCreatingBigArchiveToStream(final ZipArchiveOutputStream zos) throws IOException {
final byte[] buf = new byte[ONE_MILLION];
ZipArchiveEntry zae;
for (int i = 0; i < 2; i++) {
@@ -541,8 +492,7 @@ public class Zip64SupportIT {
zae.setMethod(ZipEntry.STORED);
zae.setCrc(0x8a408f16L);
zos.putArchiveEntry(zae);
- for (int j = 0; j < FIVE_BILLION / 2 / 1000 / 1000;
- j++) {
+ for (int j = 0; j < FIVE_BILLION / 2 / 1000 / 1000; j++) {
zos.write(buf);
}
zos.closeArchiveEntry();
@@ -573,10 +523,8 @@ public class Zip64SupportIT {
}
zos.closeArchiveEntry();
zos.close();
- } catch (final IOException ex) {
- System.err.println("Failed to write archive because of: "
- + ex.getMessage()
- + " - likely not enough disk space.");
+ } catch (IOException ex) {
+ System.err.println("Failed to write archive because of: " + ex.getMessage() + " - likely not enough disk space.");
assumeTrue(false);
} finally {
zos.destroy();
@@ -584,179 +532,155 @@ public class Zip64SupportIT {
return f;
}
- private static ZipOutputTest
- writeBigDeflatedEntryToFile(final boolean knownSize) {
+ private static ZipOutputTest writeBigDeflatedEntryToFile(final boolean knownSize) {
return writeBigDeflatedEntryToFile(knownSize, Zip64Mode.AsNeeded);
}
/*
- * One entry of length 5 billion bytes, written with
- * compression to a file.
+ * One entry of length 5 billion bytes, written with compression to a file.
*
- * Writing to a file => sizes are stored directly inside the LFH.
- * No Data Descriptor at all.
+ * Writing to a file => sizes are stored directly inside the LFH. No Data Descriptor at all.
*
* Creates a temporary archive of approx 4MB in size
*/
- private static ZipOutputTest
- writeBigDeflatedEntryToFile(final boolean knownSize,
- final Zip64Mode mode) {
+ private static ZipOutputTest writeBigDeflatedEntryToFile(final boolean knownSize, final Zip64Mode mode) {
return (f, zos) -> {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- if (knownSize) {
- zae.setSize(FIVE_BILLION);
- }
- zae.setMethod(ZipEntry.DEFLATED);
- zos.putArchiveEntry(zae);
- for (int j = 0;
- j < FIVE_BILLION / 1000 / 1000;
- j++) {
- zos.write(buf);
- }
- zos.closeArchiveEntry();
- zos.close();
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
+ }
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ if (knownSize) {
+ zae.setSize(FIVE_BILLION);
+ }
+ zae.setMethod(ZipEntry.DEFLATED);
+ zos.putArchiveEntry(zae);
+ for (int j = 0; j < FIVE_BILLION / 1000 / 1000; j++) {
+ zos.write(buf);
+ }
+ zos.closeArchiveEntry();
+ zos.close();
+
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
-
- // grab first entry, verify
- // sizes are 0xFFFFFFFF and
- // it has a ZIP64 extended
- // information extra field
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 45, 0,
- // version needed to extract
- 45, 0,
- // GPB (EFS + *no* Data Descriptor)
- 0, 8,
- // method
- 8, 0,
- }, header, "CDH start");
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[26];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // CRC
- (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- (byte) (mode == Zip64Mode.Always? 32 : 20), 0,
- // comment length
- 0, 0,
- // disk number
- 0, 0,
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- }, rest, "CDH rest");
- byte[] offset = new byte[4];
- a.readFully(offset);
- if (mode == Zip64Mode.Always) {
+ // grab first entry, verify
+ // sizes are 0xFFFFFFFF and
+ // it has a ZIP64 extended
+ // information extra field
+ byte[] header = new byte[12];
+ a.readFully(header);
assertArrayEquals(new byte[] {
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- }, offset, "offset");
- } else {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 45, 0,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS + *no* Data Descriptor)
+ 0, 8,
+ // method
+ 8, 0, }, header, "CDH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[26];
+ a.readFully(rest);
assertArrayEquals(new byte[] {
- 0, 0, 0, 0,
- }, offset, "offset");
- }
- assertEquals('0', a.read());
- byte[] extra = new byte[12];
- a.readFully(extra);
- // 5e9 == 0x12A05F200
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- (byte) (mode == Zip64Mode.Always? 28 : 16), 0,
- // original size
- 0, (byte) 0xF2, 5, (byte) 0x2A,
- 1, 0, 0, 0,
- }, extra, "CDH extra");
- if (mode == Zip64Mode.Always) {
- // skip compressed size
- a.skipBytes(8);
- offset = new byte[8];
+ // CRC
+ (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
+ // Compressed Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ (byte) (mode == Zip64Mode.Always ? 32 : 20), 0,
+ // comment length
+ 0, 0,
+ // disk number
+ 0, 0,
+ // attributes
+ 0, 0, 0, 0, 0, 0, }, rest, "CDH rest");
+ byte[] offset = new byte[4];
a.readFully(offset);
+ if (mode == Zip64Mode.Always) {
+ assertArrayEquals(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, }, offset, "offset");
+ } else {
+ assertArrayEquals(new byte[] { 0, 0, 0, 0, }, offset, "offset");
+ }
+ assertEquals('0', a.read());
+ byte[] extra = new byte[12];
+ a.readFully(extra);
+ // 5e9 == 0x12A05F200
assertArrayEquals(new byte[] {
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, offset, "extra offset");
- }
-
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 45, 0,
- // GPB (EFS bit, no DD)
- 0, 8,
- // method
- 8, 0,
- }, header, "LFH start");
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // CRC
- (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- 20, 0,
- // file name
- (byte) '0'
- }, rest);
- extra = new byte[12];
- a.readFully(extra);
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 16, 0,
- // original size
- 0, (byte) 0xF2, 5, (byte) 0x2A,
- 1, 0, 0, 0,
+ // Header-ID
+ 1, 0,
+ // size of extra
+ (byte) (mode == Zip64Mode.Always ? 28 : 16), 0,
+ // original size
+ 0, (byte) 0xF2, 5, (byte) 0x2A, 1, 0, 0, 0, }, extra, "CDH extra");
+ if (mode == Zip64Mode.Always) {
// skip compressed size
- }, extra);
- }
- };
+ a.skipBytes(8);
+ offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, }, offset, "extra offset");
+ }
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS bit, no DD)
+ 0, 8,
+ // method
+ 8, 0, }, header, "LFH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ assertArrayEquals(new byte[] {
+ // CRC
+ (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
+ // Compressed Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ 20, 0,
+ // file name
+ (byte) '0' }, rest);
+ extra = new byte[12];
+ a.readFully(extra);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 16, 0,
+ // original size
+ 0, (byte) 0xF2, 5, (byte) 0x2A, 1, 0, 0, 0,
+ // skip compressed size
+ }, extra);
+ }
+ };
}
/*
- * One entry of length 5 billion bytes, written with
- * compression to a file.
+ * One entry of length 5 billion bytes, written with compression to a file.
*
- * Writing to a file => sizes are stored directly inside the LFH.
- * No Data Descriptor at all.
+ * Writing to a file => sizes are stored directly inside the LFH. No Data Descriptor at all.
*
* Creates a temporary archive of approx 4MB in size
*/
- private static ZipOutputTest
- writeBigDeflatedEntryToFileModeNever(final boolean knownSize) {
+ private static ZipOutputTest writeBigDeflatedEntryToFileModeNever(final boolean knownSize) {
return (f, zos) -> {
zos.setUseZip64(Zip64Mode.Never);
final Zip64RequiredException ex = assertThrows(Zip64RequiredException.class, () -> {
@@ -777,185 +701,161 @@ public class Zip64SupportIT {
}
/*
- * One entry of length 5 billion bytes, written with
- * compression to a stream.
+ * One entry of length 5 billion bytes, written with compression to a stream.
*
- * Compression + Stream => sizes are set to 0 in LFH and ZIP64
- * entry, real values are inside the data descriptor.
+ * Compression + Stream => sizes are set to 0 in LFH and ZIP64 entry, real values are inside the data descriptor.
*
* Creates a temporary archive of approx 4MB in size
*/
- private static ZipOutputTest
- writeBigDeflatedEntryToStream(final boolean knownSize,
- final Zip64Mode mode) {
+ private static ZipOutputTest writeBigDeflatedEntryToStream(final boolean knownSize, final Zip64Mode mode) {
return (f, zos) -> {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- if (knownSize) {
- zae.setSize(FIVE_BILLION);
- }
- zae.setMethod(ZipEntry.DEFLATED);
- zos.putArchiveEntry(zae);
- for (int j = 0; j < FIVE_BILLION / 1000 / 1000; j++) {
- zos.write(buf);
- }
- zos.closeArchiveEntry();
- zos.close();
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
+ }
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ if (knownSize) {
+ zae.setSize(FIVE_BILLION);
+ }
+ zae.setMethod(ZipEntry.DEFLATED);
+ zos.putArchiveEntry(zae);
+ for (int j = 0; j < FIVE_BILLION / 1000 / 1000; j++) {
+ zos.write(buf);
+ }
+ zos.closeArchiveEntry();
+ zos.close();
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
-
- final long cfhPos = a.getFilePointer();
- // grab first entry, verify
- // sizes are 0xFFFFFFFF and
- // it has a ZIP64 extended
- // information extra field
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 45, 0,
- // version needed to extract
- 45, 0,
- // GPB (EFS + Data Descriptor)
- 8, 8,
- // method
- 8, 0,
- }, header, "CDH start");
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[26];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // CRC
- (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- (byte) (mode == Zip64Mode.Always? 32 : 20), 0,
- // comment length
- 0, 0,
- // disk number
- 0, 0,
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- }, rest, "CDH rest");
- byte[] offset = new byte[4];
- a.readFully(offset);
- if (mode == Zip64Mode.Always) {
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
+
+ final long cfhPos = a.getFilePointer();
+ // grab first entry, verify
+ // sizes are 0xFFFFFFFF and
+ // it has a ZIP64 extended
+ // information extra field
+ byte[] header = new byte[12];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 45, 0,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS + Data Descriptor)
+ 8, 8,
+ // method
+ 8, 0, }, header, "CDH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[26];
+ a.readFully(rest);
assertArrayEquals(new byte[] {
+ // CRC
+ (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
+ // Compressed Size
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- }, offset, "offset");
- } else {
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ (byte) (mode == Zip64Mode.Always ? 32 : 20), 0,
+ // comment length
+ 0, 0,
+ // disk number
+ 0, 0,
+ // attributes
+ 0, 0, 0, 0, 0, 0, }, rest, "CDH rest");
+ byte[] offset = new byte[4];
+ a.readFully(offset);
+ if (mode == Zip64Mode.Always) {
+ assertArrayEquals(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, }, offset, "offset");
+ } else {
+ assertArrayEquals(new byte[] { 0, 0, 0, 0, }, offset, "offset");
+ }
+ assertEquals('0', a.read());
+ byte[] extra = new byte[12];
+ a.readFully(extra);
+ // 5e9 == 0x12A05F200
assertArrayEquals(new byte[] {
- 0, 0, 0, 0,
- }, offset, "offset");
- }
- assertEquals('0', a.read());
- byte[] extra = new byte[12];
- a.readFully(extra);
- // 5e9 == 0x12A05F200
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- (byte) (mode == Zip64Mode.Always? 28 : 16), 0,
- // original size
- 0, (byte) 0xF2, 5, (byte) 0x2A,
- 1, 0, 0, 0,
- }, extra, "CDH extra");
- if (mode == Zip64Mode.Always) {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ (byte) (mode == Zip64Mode.Always ? 28 : 16), 0,
+ // original size
+ 0, (byte) 0xF2, 5, (byte) 0x2A, 1, 0, 0, 0, }, extra, "CDH extra");
+ if (mode == Zip64Mode.Always) {
+ // skip compressed size
+ a.skipBytes(8);
+ offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, }, offset, "extra offset");
+ }
+
+ // validate data descriptor
+ a.seek(cfhPos - 24);
+ byte[] dd = new byte[8];
+ a.readFully(dd);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 7, 8,
+ // CRC
+ (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c, }, dd, "DD");
// skip compressed size
a.skipBytes(8);
- offset = new byte[8];
- a.readFully(offset);
+ dd = new byte[8];
+ a.readFully(dd);
+ assertArrayEquals(new byte[] {
+ // original size
+ 0, (byte) 0xF2, 5, (byte) 0x2A, 1, 0, 0, 0, }, dd, "DD sizes");
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS + Data Descriptor)
+ 8, 8,
+ // method
+ 8, 0, }, header, "LFH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ assertArrayEquals(new byte[] {
+ // CRC
+ 0, 0, 0, 0,
+ // Compressed Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ 20, 0,
+ // file name
+ (byte) '0' }, rest, "LFH rest");
+ extra = new byte[20];
+ a.readFully(extra);
assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 16, 0,
+ // original size
0, 0, 0, 0, 0, 0, 0, 0,
- }, offset, "extra offset");
+ // compressed size
+ 0, 0, 0, 0, 0, 0, 0, 0, }, extra, "LFH extra");
}
-
- // validate data descriptor
- a.seek(cfhPos - 24);
- byte[] dd = new byte[8];
- a.readFully(dd);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 7, 8,
- // CRC
- (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
- }, dd, "DD");
- // skip compressed size
- a.skipBytes(8);
- dd = new byte[8];
- a.readFully(dd);
- assertArrayEquals(new byte[] {
- // original size
- 0, (byte) 0xF2, 5, (byte) 0x2A,
- 1, 0, 0, 0,
- }, dd, "DD sizes");
-
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 45, 0,
- // GPB (EFS + Data Descriptor)
- 8, 8,
- // method
- 8, 0,
- }, header, "LFH start");
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // CRC
- 0, 0, 0, 0,
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- 20, 0,
- // file name
- (byte) '0'
- }, rest, "LFH rest");
- extra = new byte[20];
- a.readFully(extra);
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 16, 0,
- // original size
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- // compressed size
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- }, extra, "LFH extra");
- }
- };
+ };
}
- private static ZipOutputTest
- writeBigDeflatedEntryUnknownSizeToStream(final Zip64Mode mode) {
+ private static ZipOutputTest writeBigDeflatedEntryUnknownSizeToStream(final Zip64Mode mode) {
return (f, zos) -> {
final Zip64RequiredException ex = assertThrows(Zip64RequiredException.class, () -> {
if (mode != Zip64Mode.AsNeeded) {
@@ -979,164 +879,143 @@ public class Zip64SupportIT {
}
/*
- * One entry of length 5 billion bytes, written without
- * compression.
+ * One entry of length 5 billion bytes, written without compression.
*
- * No Compression => sizes are stored directly inside the LFH. No
- * Data Descriptor at all.
+ * No Compression => sizes are stored directly inside the LFH. No Data Descriptor at all.
*
* Creates a temporary archive of approx 5GB in size
*/
- private static ZipOutputTest writeBigStoredEntry(final boolean knownSize,
- final Zip64Mode mode) {
+ private static ZipOutputTest writeBigStoredEntry(final boolean knownSize, final Zip64Mode mode) {
return (f, zos) -> {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- if (knownSize) {
- zae.setSize(FIVE_BILLION);
- zae.setCrc(0x5c316f50L);
- }
- zae.setMethod(ZipEntry.STORED);
- zos.putArchiveEntry(zae);
- for (int j = 0; j < FIVE_BILLION / 1000 / 1000; j++) {
- zos.write(buf);
- }
- zos.closeArchiveEntry();
- zos.close();
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
+ }
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ if (knownSize) {
+ zae.setSize(FIVE_BILLION);
+ zae.setCrc(0x5c316f50L);
+ }
+ zae.setMethod(ZipEntry.STORED);
+ zos.putArchiveEntry(zae);
+ for (int j = 0; j < FIVE_BILLION / 1000 / 1000; j++) {
+ zos.write(buf);
+ }
+ zos.closeArchiveEntry();
+ zos.close();
+
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
-
- // grab first entry, verify sizes are 0xFFFFFFFF
- // and it has a ZIP64 extended information extra
- // field
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 45, 0,
- // version needed to extract
- 45, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header, "CDH start");
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[26];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // CRC
- (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- (byte) (mode == Zip64Mode.Always? 32 : 20), 0,
- // comment length
- 0, 0,
- // disk number
- 0, 0,
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- }, rest, "CDH rest");
- byte[] offset = new byte[4];
- a.readFully(offset);
- if (mode == Zip64Mode.Always) {
+ // grab first entry, verify sizes are 0xFFFFFFFF
+ // and it has a ZIP64 extended information extra
+ // field
+ byte[] header = new byte[12];
+ a.readFully(header);
assertArrayEquals(new byte[] {
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- }, offset, "offset");
- } else {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 45, 0,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0 }, header, "CDH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[26];
+ a.readFully(rest);
assertArrayEquals(new byte[] {
- 0, 0, 0, 0,
- }, offset, "offset");
- }
- assertEquals('0', a.read());
- final byte[] extra = new byte[20];
- a.readFully(extra);
- // 5e9 == 0x12A05F200
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- (byte) (mode == Zip64Mode.Always? 28 : 16), 0,
- // original size
- 0, (byte) 0xF2, 5, (byte) 0x2A,
- 1, 0, 0, 0,
- // compressed size
- 0, (byte) 0xF2, 5, (byte) 0x2A,
- 1, 0, 0, 0,
- }, extra, "CDH extra");
- if (mode == Zip64Mode.Always) {
- offset = new byte[8];
+ // CRC
+ (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
+ // Compressed Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ (byte) (mode == Zip64Mode.Always ? 32 : 20), 0,
+ // comment length
+ 0, 0,
+ // disk number
+ 0, 0,
+ // attributes
+ 0, 0, 0, 0, 0, 0, }, rest, "CDH rest");
+ byte[] offset = new byte[4];
a.readFully(offset);
+ if (mode == Zip64Mode.Always) {
+ assertArrayEquals(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, }, offset, "offset");
+ } else {
+ assertArrayEquals(new byte[] { 0, 0, 0, 0, }, offset, "offset");
+ }
+ assertEquals('0', a.read());
+ final byte[] extra = new byte[20];
+ a.readFully(extra);
+ // 5e9 == 0x12A05F200
assertArrayEquals(new byte[] {
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, offset, "extra offset");
- }
+ // Header-ID
+ 1, 0,
+ // size of extra
+ (byte) (mode == Zip64Mode.Always ? 28 : 16), 0,
+ // original size
+ 0, (byte) 0xF2, 5, (byte) 0x2A, 1, 0, 0, 0,
+ // compressed size
+ 0, (byte) 0xF2, 5, (byte) 0x2A, 1, 0, 0, 0, }, extra, "CDH extra");
+ if (mode == Zip64Mode.Always) {
+ offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, }, offset, "extra offset");
+ }
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 45, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header, "LFH start");
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // CRC
- (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- 20, 0,
- // file name
- (byte) '0'
- }, rest, "LFH rest");
- a.readFully(extra);
- // 5e9 == 0x12A05F200
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 16, 0,
- // original size
- 0, (byte) 0xF2, 5, (byte) 0x2A,
- 1, 0, 0, 0,
- // compressed size
- 0, (byte) 0xF2, 5, (byte) 0x2A,
- 1, 0, 0, 0,
- }, extra, "LFH extra");
- }
- };
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0 }, header, "LFH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ assertArrayEquals(new byte[] {
+ // CRC
+ (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
+ // Compressed Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ 20, 0,
+ // file name
+ (byte) '0' }, rest, "LFH rest");
+ a.readFully(extra);
+ // 5e9 == 0x12A05F200
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 16, 0,
+ // original size
+ 0, (byte) 0xF2, 5, (byte) 0x2A, 1, 0, 0, 0,
+ // compressed size
+ 0, (byte) 0xF2, 5, (byte) 0x2A, 1, 0, 0, 0, }, extra, "LFH extra");
+ }
+ };
}
- private static ZipOutputTest
- writeBigStoredEntryModeNever(final boolean knownSize) {
+ private static ZipOutputTest writeBigStoredEntryModeNever(final boolean knownSize) {
return (f, zos) -> {
zos.setUseZip64(Zip64Mode.Never);
final Zip64RequiredException ex = assertThrows(Zip64RequiredException.class, () -> {
@@ -1162,590 +1041,517 @@ public class Zip64SupportIT {
}
/*
- * One entry of length 1 million bytes, written with compression
- * to a file.
+ * One entry of length 1 million bytes, written with compression to a file.
*
- * Writing to a file => sizes are stored directly inside the LFH.
- * No Data Descriptor at all. Shouldn't contain any ZIP64 extra
- * field if size was known.
+ * Writing to a file => sizes are stored directly inside the LFH. No Data Descriptor at all. Shouldn't contain any ZIP64 extra field if size was known.
*/
- private static ZipOutputTest
- writeSmallDeflatedEntryToFile(final boolean knownSize,
- final Zip64Mode mode) {
+ private static ZipOutputTest writeSmallDeflatedEntryToFile(final boolean knownSize, final Zip64Mode mode) {
return (f, zos) -> {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- if (knownSize) {
- zae.setSize(ONE_MILLION);
- }
- zae.setMethod(ZipEntry.DEFLATED);
- zos.putArchiveEntry(zae);
- zos.write(buf);
- zos.closeArchiveEntry();
- zos.close();
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
+ }
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ if (knownSize) {
+ zae.setSize(ONE_MILLION);
+ }
+ zae.setMethod(ZipEntry.DEFLATED);
+ zos.putArchiveEntry(zae);
+ zos.write(buf);
+ zos.closeArchiveEntry();
+ zos.close();
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
-
- // grab first CD entry, verify sizes are not
- // 0xFFFFFFFF and it has a no ZIP64 extended
- // information extra field
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 20, 0,
- // version needed to extract
- 20, 0,
- // GPB (EFS + *no* Data Descriptor)
- 0, 8,
- // method
- 8, 0,
- }, header);
- // ignore timestamp
- a.skipBytes(4);
- byte[] crc = new byte[4];
- a.readFully(crc);
- assertArrayEquals(new byte[] {
- (byte) 0x9E, (byte) 0xCB,
- (byte) 0x79, (byte) 0x12,
- }, crc);
- // skip compressed size
- a.skipBytes(4);
- byte[] rest = new byte[23];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // Original Size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- // file name length
- 1, 0,
- // extra field length
- 0, 0,
- // comment length
- 0, 0,
- // disk number
- 0, 0,
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- // offset
- 0, 0, 0, 0,
- // file name
- (byte) '0'
- }, rest);
-
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 20, 0,
- // GPB (EFS bit, no DD)
- 0, 8,
- // method
- 8, 0,
- }, header);
- // ignore timestamp
- a.skipBytes(4);
- crc = new byte[4];
- a.readFully(crc);
- assertArrayEquals(new byte[] {
- (byte) 0x9E, (byte) 0xCB,
- (byte) 0x79, (byte) 0x12,
- }, crc);
- // skip compressed size
- a.skipBytes(4);
- rest = new byte[9];
- a.readFully(rest);
-
- final boolean hasExtra =
- mode == Zip64Mode.AsNeeded && !knownSize;
-
- assertArrayEquals(new byte[] {
- // Original Size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- // file name length
- 1, 0,
- // extra field length
- (byte) (!hasExtra ? 0 : 20), 0,
- // file name
- (byte) '0'
- }, rest);
- if (hasExtra) {
- final byte[] extra = new byte[12];
- a.readFully(extra);
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
+
+ // grab first CD entry, verify sizes are not
+ // 0xFFFFFFFF and it has a no ZIP64 extended
+ // information extra field
+ byte[] header = new byte[12];
+ a.readFully(header);
assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 16, 0,
- // original size
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 20, 0,
+ // version needed to extract
+ 20, 0,
+ // GPB (EFS + *no* Data Descriptor)
+ 0, 8,
+ // method
+ 8, 0, }, header);
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] crc = new byte[4];
+ a.readFully(crc);
+ assertArrayEquals(new byte[] { (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12, }, crc);
+ // skip compressed size
+ a.skipBytes(4);
+ byte[] rest = new byte[23];
+ a.readFully(rest);
+ assertArrayEquals(new byte[] {
+ // Original Size
(byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
+ // file name length
+ 1, 0,
+ // extra field length
+ 0, 0,
+ // comment length
+ 0, 0,
+ // disk number
+ 0, 0,
+ // attributes
+ 0, 0, 0, 0, 0, 0,
+ // offset
0, 0, 0, 0,
- // don't know the
- // compressed size,
- // don't want to
- // hard-code it
- }, extra);
+ // file name
+ (byte) '0' }, rest);
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 20, 0,
+ // GPB (EFS bit, no DD)
+ 0, 8,
+ // method
+ 8, 0, }, header);
+ // ignore timestamp
+ a.skipBytes(4);
+ crc = new byte[4];
+ a.readFully(crc);
+ assertArrayEquals(new byte[] { (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12, }, crc);
+ // skip compressed size
+ a.skipBytes(4);
+ rest = new byte[9];
+ a.readFully(rest);
+
+ final boolean hasExtra = mode == Zip64Mode.AsNeeded && !knownSize;
+
+ assertArrayEquals(new byte[] {
+ // Original Size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
+ // file name length
+ 1, 0,
+ // extra field length
+ (byte) (!hasExtra ? 0 : 20), 0,
+ // file name
+ (byte) '0' }, rest);
+ if (hasExtra) {
+ final byte[] extra = new byte[12];
+ a.readFully(extra);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 16, 0,
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0,
+ // don't know the
+ // compressed size,
+ // don't want to
+ // hard-code it
+ }, extra);
+ }
}
- }
- };
+ };
}
/*
- * One entry of length 1 million bytes, written with compression
- * to a file.
+ * One entry of length 1 million bytes, written with compression to a file.
*
- * Writing to a file => sizes are stored directly inside the LFH.
- * No Data Descriptor at all. Must contain ZIP64 extra field as
- * mode is Always.
+ * Writing to a file => sizes are stored directly inside the LFH. No Data Descriptor at all. Must contain ZIP64 extra field as mode is Always.
*/
- private static ZipOutputTest
- writeSmallDeflatedEntryToFileModeAlways(final boolean knownSize) {
+ private static ZipOutputTest writeSmallDeflatedEntryToFileModeAlways(final boolean knownSize) {
return (f, zos) -> {
- zos.setUseZip64(Zip64Mode.Always);
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- if (knownSize) {
- zae.setSize(ONE_MILLION);
- }
- zae.setMethod(ZipEntry.DEFLATED);
- zos.putArchiveEntry(zae);
- zos.write(buf);
- zos.closeArchiveEntry();
- zos.close();
-
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
-
- // grab first CD entry, verify sizes are not
- // 0xFFFFFFFF, and it has an empty ZIP64 extended
- // information extra field
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 45, 0,
- // version needed to extract
- 45, 0,
- // GPB (EFS + *no* Data Descriptor)
- 0, 8,
- // method
- 8, 0,
- }, header, "CDH start");
- // ignore timestamp
- a.skipBytes(4);
- byte[] crc = new byte[4];
- a.readFully(crc);
- assertArrayEquals(new byte[] {
- (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
- }, crc, "CDH CRC");
- // skip compressed size
- a.skipBytes(4);
- byte[] rest = new byte[23];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // Original Size
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- // file name length
- 1, 0,
- // extra field length
- 32, 0,
- // comment length
- 0, 0,
- // disk number
- 0, 0,
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- // offset
- (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
- // file name
- (byte) '0'
- }, rest, "CDH rest");
- byte[] extra = new byte[12];
- a.readFully(extra);
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 28, 0,
- // original size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0,
- }, extra, "CDH extra");
- // skip compressed size
- a.skipBytes(8);
- final byte[] offset = new byte[8];
- a.readFully(offset);
- assertArrayEquals(new byte[] {
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, offset, "extra offset");
-
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 45, 0,
- // GPB (EFS bit, no DD)
- 0, 8,
- // method
- 8, 0,
- }, header, "LFH start");
- // ignore timestamp
- a.skipBytes(4);
- crc = new byte[4];
- a.readFully(crc);
- assertArrayEquals(new byte[] {
- (byte) 0x9E, (byte) 0xCB,
- (byte) 0x79, (byte) 0x12,
- }, crc, "LFH CRC");
- rest = new byte[13];
- a.readFully(rest);
-
- assertArrayEquals(new byte[] {
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- 20, 0,
- // file name
- (byte) '0'
- }, rest, "LFH rest");
-
- extra = new byte[12];
- a.readFully(extra);
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 16, 0,
- // original size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0,
- // don't know the
- // compressed size,
- // don't want to
- // hard-code it
- }, extra, "LFH extra");
- }
- };
- }
-
+ zos.setUseZip64(Zip64Mode.Always);
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ if (knownSize) {
+ zae.setSize(ONE_MILLION);
+ }
+ zae.setMethod(ZipEntry.DEFLATED);
+ zos.putArchiveEntry(zae);
+ zos.write(buf);
+ zos.closeArchiveEntry();
+ zos.close();
+
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
+
+ // grab first CD entry, verify sizes are not
+ // 0xFFFFFFFF, and it has an empty ZIP64 extended
+ // information extra field
+ byte[] header = new byte[12];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 45, 0,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS + *no* Data Descriptor)
+ 0, 8,
+ // method
+ 8, 0, }, header, "CDH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] crc = new byte[4];
+ a.readFully(crc);
+ assertArrayEquals(new byte[] { (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12, }, crc, "CDH CRC");
+ // skip compressed size
+ a.skipBytes(4);
+ byte[] rest = new byte[23];
+ a.readFully(rest);
+ assertArrayEquals(new byte[] {
+ // Original Size
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ // file name length
+ 1, 0,
+ // extra field length
+ 32, 0,
+ // comment length
+ 0, 0,
+ // disk number
+ 0, 0,
+ // attributes
+ 0, 0, 0, 0, 0, 0,
+ // offset
+ (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
+ // file name
+ (byte) '0' }, rest, "CDH rest");
+ byte[] extra = new byte[12];
+ a.readFully(extra);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 28, 0,
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0, }, extra, "CDH extra");
+ // skip compressed size
+ a.skipBytes(8);
+ final byte[] offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, }, offset, "extra offset");
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS bit, no DD)
+ 0, 8,
+ // method
+ 8, 0, }, header, "LFH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ crc = new byte[4];
+ a.readFully(crc);
+ assertArrayEquals(new byte[] { (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12, }, crc, "LFH CRC");
+ rest = new byte[13];
+ a.readFully(rest);
+
+ assertArrayEquals(new byte[] {
+ // Compressed Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ 20, 0,
+ // file name
+ (byte) '0' }, rest, "LFH rest");
+
+ extra = new byte[12];
+ a.readFully(extra);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 16, 0,
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0,
+ // don't know the
+ // compressed size,
+ // don't want to
+ // hard-code it
+ }, extra, "LFH extra");
+ }
+ };
+ }
+
/*
- * One entry of length 1 million bytes, written with compression
- * to a stream.
+ * One entry of length 1 million bytes, written with compression to a stream.
*
- * Compression + Stream => sizes are set to 0 in LFH, real values
- * are inside the data descriptor. No ZIP64 extra field at all.
+ * Compression + Stream => sizes are set to 0 in LFH, real values are inside the data descriptor. No ZIP64 extra field at all.
*/
- private static ZipOutputTest
- writeSmallDeflatedEntryToStream(final boolean knownSize,
- final Zip64Mode mode) {
+ private static ZipOutputTest writeSmallDeflatedEntryToStream(final boolean knownSize, final Zip64Mode mode) {
return (f, zos) -> {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- if (knownSize) {
- zae.setSize(ONE_MILLION);
- }
- zae.setMethod(ZipEntry.DEFLATED);
- zos.putArchiveEntry(zae);
- zos.write(buf);
- zos.closeArchiveEntry();
- zos.close();
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
+ }
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ if (knownSize) {
+ zae.setSize(ONE_MILLION);
+ }
+ zae.setMethod(ZipEntry.DEFLATED);
+ zos.putArchiveEntry(zae);
+ zos.write(buf);
+ zos.closeArchiveEntry();
+ zos.close();
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
-
- final long cfhPos = a.getFilePointer();
- // grab first entry, verify sizes are not
- // 0xFFFFFFF and it has no ZIP64 extended
- // information extra field
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 20, 0,
- // version needed to extract
- 20, 0,
- // GPB (EFS + Data Descriptor)
- 8, 8,
- // method
- 8, 0,
- }, header);
- // ignore timestamp
- a.skipBytes(4);
- final byte[] crc = new byte[4];
- a.readFully(crc);
- assertArrayEquals(new byte[] {
- (byte) 0x9E, (byte) 0xCB,
- (byte) 0x79, (byte) 0x12,
- }, crc);
- // skip compressed size
- a.skipBytes(4);
- byte[] rest = new byte[23];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // Original Size
- (byte) 0x40, (byte) 0x42,
- (byte) 0x0F, 0,
- // file name length
- 1, 0,
- // extra field length
- 0, 0,
- // comment length
- 0, 0,
- // disk number
- 0, 0,
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- // offset
- 0, 0, 0, 0,
- // file name
- (byte) '0'
- }, rest);
-
- // validate data descriptor
- a.seek(cfhPos - 16);
- byte[] dd = new byte[8];
- a.readFully(dd);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 7, 8,
- // CRC
- (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
- }, dd);
- // skip uncompressed size
- a.skipBytes(4);
- dd = new byte[4];
- a.readFully(dd);
- assertArrayEquals(new byte[] {
- // original size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- }, dd);
-
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 20, 0,
- // GPB (EFS + Data Descriptor)
- 8, 8,
- // method
- 8, 0,
- }, header);
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // CRC
- 0, 0, 0, 0,
- // Compressed Size
- 0, 0, 0, 0,
- // Original Size
- 0, 0, 0, 0,
- // file name length
- 1, 0,
- // extra field length
- 0, 0,
- // file name
- (byte) '0'
- }, rest);
- }
- };
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
+
+ final long cfhPos = a.getFilePointer();
+ // grab first entry, verify sizes are not
+ // 0xFFFFFFF and it has no ZIP64 extended
+ // information extra field
+ byte[] header = new byte[12];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 20, 0,
+ // version needed to extract
+ 20, 0,
+ // GPB (EFS + Data Descriptor)
+ 8, 8,
+ // method
+ 8, 0, }, header);
+ // ignore timestamp
+ a.skipBytes(4);
+ final byte[] crc = new byte[4];
+ a.readFully(crc);
+ assertArrayEquals(new byte[] { (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12, }, crc);
+ // skip compressed size
+ a.skipBytes(4);
+ byte[] rest = new byte[23];
+ a.readFully(rest);
+ assertArrayEquals(new byte[] {
+ // Original Size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
+ // file name length
+ 1, 0,
+ // extra field length
+ 0, 0,
+ // comment length
+ 0, 0,
+ // disk number
+ 0, 0,
+ // attributes
+ 0, 0, 0, 0, 0, 0,
+ // offset
+ 0, 0, 0, 0,
+ // file name
+ (byte) '0' }, rest);
+
+ // validate data descriptor
+ a.seek(cfhPos - 16);
+ byte[] dd = new byte[8];
+ a.readFully(dd);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 7, 8,
+ // CRC
+ (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12, }, dd);
+ // skip uncompressed size
+ a.skipBytes(4);
+ dd = new byte[4];
+ a.readFully(dd);
+ assertArrayEquals(new byte[] {
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, }, dd);
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 20, 0,
+ // GPB (EFS + Data Descriptor)
+ 8, 8,
+ // method
+ 8, 0, }, header);
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ assertArrayEquals(new byte[] {
+ // CRC
+ 0, 0, 0, 0,
+ // Compressed Size
+ 0, 0, 0, 0,
+ // Original Size
+ 0, 0, 0, 0,
+ // file name length
+ 1, 0,
+ // extra field length
+ 0, 0,
+ // file name
+ (byte) '0' }, rest);
+ }
+ };
}
/*
- * One entry of length 1 million bytes, written with compression
- * to a stream.
+ * One entry of length 1 million bytes, written with compression to a stream.
*
- * Compression + Stream => sizes are set to 0 in LFH, real values
- * are inside the data descriptor. ZIP64 extra field as mode is Always.
+ * Compression + Stream => sizes are set to 0 in LFH, real values are inside the data descriptor. ZIP64 extra field as mode is Always.
*/
- private static ZipOutputTest
- writeSmallDeflatedEntryToStreamModeAlways(final boolean knownSize) {
+ private static ZipOutputTest writeSmallDeflatedEntryToStreamModeAlways(final boolean knownSize) {
return (f, zos) -> {
- zos.setUseZip64(Zip64Mode.Always);
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- if (knownSize) {
- zae.setSize(ONE_MILLION);
- }
- zae.setMethod(ZipEntry.DEFLATED);
- zos.putArchiveEntry(zae);
- zos.write(buf);
- zos.closeArchiveEntry();
- zos.close();
+ zos.setUseZip64(Zip64Mode.Always);
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ if (knownSize) {
+ zae.setSize(ONE_MILLION);
+ }
+ zae.setMethod(ZipEntry.DEFLATED);
+ zos.putArchiveEntry(zae);
+ zos.write(buf);
+ zos.closeArchiveEntry();
+ zos.close();
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
-
- final long cfhPos = a.getFilePointer();
- // grab first entry, verify sizes are not
- // 0xFFFFFFF and it has an empty ZIP64 extended
- // information extra field
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 45, 0,
- // version needed to extract
- 45, 0,
- // GPB (EFS + Data Descriptor)
- 8, 8,
- // method
- 8, 0,
- }, header, "CDH start");
- // ignore timestamp
- a.skipBytes(4);
- final byte[] crc = new byte[4];
- a.readFully(crc);
- assertArrayEquals(new byte[] {
- (byte) 0x9E, (byte) 0xCB,
- (byte) 0x79, (byte) 0x12,
- }, crc);
- // skip compressed size
- a.skipBytes(4);
- byte[] rest = new byte[23];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- 32, 0,
- // comment length
- 0, 0,
- // disk number
- 0, 0,
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- // offset
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name
- (byte) '0'
- }, rest, "CDH rest");
- byte[] extra = new byte[12];
- a.readFully(extra);
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 28, 0,
- // original size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0,
- }, extra, "CDH extra");
- // skip compressed size
- a.skipBytes(8);
- final byte[] offset = new byte[8];
- a.readFully(offset);
- assertArrayEquals(new byte[] {
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, offset, "extra offset");
-
- // validate data descriptor
- a.seek(cfhPos - 24);
- byte[] dd = new byte[8];
- a.readFully(dd);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 7, 8,
- // CRC
- (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
- }, dd, "DD");
- // skip compressed size
- a.skipBytes(8);
- dd = new byte[8];
- a.readFully(dd);
- assertArrayEquals(new byte[] {
- // original size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0
- }, dd, "DD size");
-
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 45, 0,
- // GPB (EFS + Data Descriptor)
- 8, 8,
- // method
- 8, 0,
- }, header, "LFH start");
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- assertArrayEquals(new byte[] {
- // CRC
- 0, 0, 0, 0,
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- 20, 0,
- // file name
- (byte) '0'
- }, rest, "LFH rest");
-
- extra = new byte[20];
- a.readFully(extra);
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 16, 0,
- // original size
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- // compressed size
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- }, extra, "LFH extra");
- }
- };
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
+
+ final long cfhPos = a.getFilePointer();
+ // grab first entry, verify sizes are not
+ // 0xFFFFFFF and it has an empty ZIP64 extended
+ // information extra field
+ byte[] header = new byte[12];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 45, 0,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS + Data Descriptor)
+ 8, 8,
+ // method
+ 8, 0, }, header, "CDH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ final byte[] crc = new byte[4];
+ a.readFully(crc);
+ assertArrayEquals(new byte[] { (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12, }, crc);
+ // skip compressed size
+ a.skipBytes(4);
+ byte[] rest = new byte[23];
+ a.readFully(rest);
+ assertArrayEquals(new byte[] {
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ 32, 0,
+ // comment length
+ 0, 0,
+ // disk number
+ 0, 0,
+ // attributes
+ 0, 0, 0, 0, 0, 0,
+ // offset
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name
+ (byte) '0' }, rest, "CDH rest");
+ byte[] extra = new byte[12];
+ a.readFully(extra);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 28, 0,
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0, }, extra, "CDH extra");
+ // skip compressed size
+ a.skipBytes(8);
+ final byte[] offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, }, offset, "extra offset");
+
+ // validate data descriptor
+ a.seek(cfhPos - 24);
+ byte[] dd = new byte[8];
+ a.readFully(dd);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 7, 8,
+ // CRC
+ (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12, }, dd, "DD");
+ // skip compressed size
+ a.skipBytes(8);
+ dd = new byte[8];
+ a.readFully(dd);
+ assertArrayEquals(new byte[] {
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0 }, dd, "DD size");
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS + Data Descriptor)
+ 8, 8,
+ // method
+ 8, 0, }, header, "LFH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ assertArrayEquals(new byte[] {
+ // CRC
+ 0, 0, 0, 0,
+ // Compressed Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ 20, 0,
+ // file name
+ (byte) '0' }, rest, "LFH rest");
+
+ extra = new byte[20];
+ a.readFully(extra);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 16, 0,
+ // original size
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ // compressed size
+ 0, 0, 0, 0, 0, 0, 0, 0, }, extra, "LFH extra");
+ }
+ };
}
@@ -1756,284 +1562,257 @@ public class Zip64SupportIT {
/*
* One entry of length 1 million bytes, written without compression.
*
- * No Compression => sizes are stored directly inside the LFH. No
- * Data Descriptor at all. Shouldn't contain any ZIP64 extra
- * field if size was known.
+ * No Compression => sizes are stored directly inside the LFH. No Data Descriptor at all. Shouldn't contain any ZIP64 extra field if size was known.
*
* Creates a temporary archive of approx 1MB in size
*/
- private static ZipOutputTest writeSmallStoredEntry(final boolean knownSize,
- final Zip64Mode mode) {
+ private static ZipOutputTest writeSmallStoredEntry(final boolean knownSize, final Zip64Mode mode) {
return (f, zos) -> {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- if (knownSize) {
- zae.setSize(ONE_MILLION);
- zae.setCrc(0x1279CB9EL);
- }
- zae.setMethod(ZipEntry.STORED);
- zos.putArchiveEntry(zae);
- zos.write(buf);
- zos.closeArchiveEntry();
- zos.close();
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
+ }
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ if (knownSize) {
+ zae.setSize(ONE_MILLION);
+ zae.setCrc(0x1279CB9EL);
+ }
+ zae.setMethod(ZipEntry.STORED);
+ zos.putArchiveEntry(zae);
+ zos.write(buf);
+ zos.closeArchiveEntry();
+ zos.close();
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
-
- // grab first CF entry, verify sizes are 1e6 and it
- // has no ZIP64 extended information extra field
- // at all
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 20, 0,
- // version needed to extract
- 10, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header, "CDH start");
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[31];
- a.readFully(rest);
- // 1e6 == 0xF4240
- assertArrayEquals(new byte[] {
- // CRC
- (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
- // Compressed Size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- // Original Size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- // file name length
- 1, 0,
- // extra field length
- 0, 0,
- // comment length
- 0, 0,
- // disk number
- 0, 0,
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- // offset
- 0, 0, 0, 0,
- // file name
- (byte) '0'
- }, rest, "CDH rest");
-
- // and now validate local file header: this one
- // has a ZIP64 extra field if and only if size was
- // unknown and mode was not Never or the mode was
- // Always (regardless of size)
- final boolean hasExtra = mode == Zip64Mode.Always
- || mode == Zip64Mode.AsNeeded && !knownSize;
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 10, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header, "LFH start");
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- // 1e6 == 0xF4240
- assertArrayEquals(new byte[] {
- // CRC
- (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
- // Compressed Size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- // Original Size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- // file name length
- 1, 0,
- // extra field length
- (byte) (!hasExtra ? 0 : 20), 0,
- // file name
- (byte) '0'
- }, rest, "LFH rest");
- if (hasExtra) {
- final byte[] extra = new byte[20];
- a.readFully(extra);
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
+
+ // grab first CF entry, verify sizes are 1e6 and it
+ // has no ZIP64 extended information extra field
+ // at all
+ byte[] header = new byte[12];
+ a.readFully(header);
assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 16, 0,
- // original size
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 20, 0,
+ // version needed to extract
+ 10, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0 }, header, "CDH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[31];
+ a.readFully(rest);
+ // 1e6 == 0xF4240
+ assertArrayEquals(new byte[] {
+ // CRC
+ (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
+ // Compressed Size
(byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0,
- // compressed size
+ // Original Size
(byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
+ // file name length
+ 1, 0,
+ // extra field length
+ 0, 0,
+ // comment length
+ 0, 0,
+ // disk number
+ 0, 0,
+ // attributes
+ 0, 0, 0, 0, 0, 0,
+ // offset
0, 0, 0, 0,
- }, extra, "ZIP64 extra field");
+ // file name
+ (byte) '0' }, rest, "CDH rest");
+
+ // and now validate local file header: this one
+ // has a ZIP64 extra field if and only if size was
+ // unknown and mode was not Never or the mode was
+ // Always (regardless of size)
+ final boolean hasExtra = mode == Zip64Mode.Always || mode == Zip64Mode.AsNeeded && !knownSize;
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 10, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0 }, header, "LFH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ // 1e6 == 0xF4240
+ assertArrayEquals(new byte[] {
+ // CRC
+ (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
+ // Compressed Size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
+ // Original Size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
+ // file name length
+ 1, 0,
+ // extra field length
+ (byte) (!hasExtra ? 0 : 20), 0,
+ // file name
+ (byte) '0' }, rest, "LFH rest");
+ if (hasExtra) {
+ final byte[] extra = new byte[20];
+ a.readFully(extra);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 16, 0,
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0,
+ // compressed size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0, }, extra, "ZIP64 extra field");
+ }
}
- }
- };
+ };
}
/*
* One entry of length 1 million bytes, written without compression.
*
- * No Compression => sizes are stored directly inside the LFH. No
- * Data Descriptor at all. Contains ZIP64 extra fields because
- * mode is Always
+ * No Compression => sizes are stored directly inside the LFH. No Data Descriptor at all. Contains ZIP64 extra fields because mode is Always
*
* Creates a temporary archive of approx 1MB in size
*/
- private static ZipOutputTest
- writeSmallStoredEntryModeAlways(final boolean knownSize) {
+ private static ZipOutputTest writeSmallStoredEntryModeAlways(final boolean knownSize) {
return (f, zos) -> {
- zos.setUseZip64(Zip64Mode.Always);
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- if (knownSize) {
- zae.setSize(ONE_MILLION);
- zae.setCrc(0x1279CB9EL);
- }
- zae.setMethod(ZipEntry.STORED);
- zos.putArchiveEntry(zae);
- zos.write(buf);
- zos.closeArchiveEntry();
- zos.close();
+ zos.setUseZip64(Zip64Mode.Always);
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ if (knownSize) {
+ zae.setSize(ONE_MILLION);
+ zae.setCrc(0x1279CB9EL);
+ }
+ zae.setMethod(ZipEntry.STORED);
+ zos.putArchiveEntry(zae);
+ zos.write(buf);
+ zos.closeArchiveEntry();
+ zos.close();
- try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
- getLengthAndPositionAtCentralDirectory(a);
-
- // grab first CF entry, verify sizes are 1e6, and it
- // has an empty ZIP64 extended information extra field
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 1, 2,
- // version made by
- 45, 0,
- // version needed to extract
- 45, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header, "CDH start");
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[31];
- a.readFully(rest);
- // 1e6 == 0xF4240
- assertArrayEquals(new byte[] {
- // CRC
- (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- 32, 0,
- // comment length
- 0, 0,
- // disk number
- 0, 0,
- // attributes
- 0, 0,
- 0, 0, 0, 0,
- // offset
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name
- (byte) '0'
- }, rest, "CDH rest");
-
- byte[] extra = new byte[28];
- a.readFully(extra);
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 28, 0,
- // original size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0,
- // compressed size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, extra, "CDH extra");
-
- // and now validate local file header: this one
- // has a ZIP64 extra field as the mode was
- // Always
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals(new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 45, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header, "LFH start");
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- // 1e6 == 0xF4240
- assertArrayEquals(new byte[] {
- // CRC
- (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
- // Compressed Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // Original Size
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- // file name length
- 1, 0,
- // extra field length
- 20, 0,
- // file name
- (byte) '0'
- }, rest, "LFH rest");
-
- extra = new byte[20];
- a.readFully(extra);
- assertArrayEquals(new byte[] {
- // Header-ID
- 1, 0,
- // size of extra
- 16, 0,
- // original size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0,
- // compressed size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0,
- }, extra, "LFH extra");
- }
- };
+ try (RandomAccessFile a = RandomAccessFileMode.READ_ONLY.create(f)) {
+ getLengthAndPositionAtCentralDirectory(a);
+
+ // grab first CF entry, verify sizes are 1e6, and it
+ // has an empty ZIP64 extended information extra field
+ byte[] header = new byte[12];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 1, 2,
+ // version made by
+ 45, 0,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0 }, header, "CDH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[31];
+ a.readFully(rest);
+ // 1e6 == 0xF4240
+ assertArrayEquals(new byte[] {
+ // CRC
+ (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
+ // Compressed Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ 32, 0,
+ // comment length
+ 0, 0,
+ // disk number
+ 0, 0,
+ // attributes
+ 0, 0, 0, 0, 0, 0,
+ // offset
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name
+ (byte) '0' }, rest, "CDH rest");
+
+ byte[] extra = new byte[28];
+ a.readFully(extra);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 28, 0,
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0,
+ // compressed size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, extra, "CDH extra");
+
+ // and now validate local file header: this one
+ // has a ZIP64 extra field as the mode was
+ // Always
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals(new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0 }, header, "LFH start");
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ // 1e6 == 0xF4240
+ assertArrayEquals(new byte[] {
+ // CRC
+ (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
+ // Compressed Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // Original Size
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ // file name length
+ 1, 0,
+ // extra field length
+ 20, 0,
+ // file name
+ (byte) '0' }, rest, "LFH rest");
+
+ extra = new byte[20];
+ a.readFully(extra);
+ assertArrayEquals(new byte[] {
+ // Header-ID
+ 1, 0,
+ // size of extra
+ 16, 0,
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0,
+ // compressed size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0, 0, 0, 0, 0, }, extra, "LFH extra");
+ }
+ };
}
private File buildZipWithZip64Mode(final String fileName, final Zip64Mode zip64Mode, final File inputFile) throws Throwable {
final File outputFile = getTempFile(fileName);
outputFile.createNewFile();
- try(ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)))) {
+ try (ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)))) {
zipArchiveOutputStream.setUseZip64(zip64Mode);
zipArchiveOutputStream.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS);
@@ -2047,247 +1826,224 @@ public class Zip64SupportIT {
return outputFile;
}
- @Test public void testRead100KFilesGeneratedBy7ZIPUsingInputStream()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedBy7ZIPUsingInputStream() throws Throwable {
read100KFilesImpl(get100KFileFileGeneratedBy7ZIP());
}
- @Test public void testRead100KFilesGeneratedBy7ZIPUsingZipFile()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedBy7ZIPUsingZipFile() throws Throwable {
read100KFilesUsingZipFileImpl(get100KFileFileGeneratedBy7ZIP());
}
- @Test public void testRead100KFilesGeneratedByJava7JarUsingInputStream()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedByJava7JarUsingInputStream() throws Throwable {
read100KFilesImpl(get100KFileFileGeneratedByJava7Jar());
}
- @Test public void testRead100KFilesGeneratedByJava7JarUsingZipFile()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedByJava7JarUsingZipFile() throws Throwable {
read100KFilesUsingZipFileImpl(get100KFileFileGeneratedByJava7Jar());
}
- @Test public void testRead100KFilesGeneratedByPKZipUsingInputStream()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedByPKZipUsingInputStream() throws Throwable {
read100KFilesImpl(get100KFileFileGeneratedByPKZip());
}
- @Test public void testRead100KFilesGeneratedByPKZipUsingZipFile()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedByPKZipUsingZipFile() throws Throwable {
read100KFilesUsingZipFileImpl(get100KFileFileGeneratedByPKZip());
}
- @Test public void testRead100KFilesGeneratedByWinCFUsingInputStream()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedByWinCFUsingInputStream() throws Throwable {
read100KFilesImpl(get100KFileFileGeneratedByWinCF());
}
- @Test public void testRead100KFilesGeneratedByWinCFUsingZipFile()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedByWinCFUsingZipFile() throws Throwable {
read100KFilesUsingZipFileImpl(get100KFileFileGeneratedByWinCF());
}
- @Test public void testRead100KFilesGeneratedByWinZIPUsingInputStream()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedByWinZIPUsingInputStream() throws Throwable {
read100KFilesImpl(get100KFileFileGeneratedByWinZIP());
}
- @Test public void testRead100KFilesGeneratedByWinZIPUsingZipFile()
- throws Throwable {
+ @Test
+ public void testRead100KFilesGeneratedByWinZIPUsingZipFile() throws Throwable {
read100KFilesUsingZipFileImpl(get100KFileFileGeneratedByWinZIP());
}
- @Test public void testRead100KFilesUsingInputStream() throws Throwable {
+ @Test
+ public void testRead100KFilesUsingInputStream() throws Throwable {
read100KFilesImpl(get100KFileFile());
}
- @Test public void testRead100KFilesUsingZipFile() throws Throwable {
+ @Test
+ public void testRead100KFilesUsingZipFile() throws Throwable {
read100KFilesUsingZipFileImpl(get100KFileFile());
}
- @Test public void testRead3EntriesCreatingBigArchiveFileUsingZipFile()
- throws Throwable {
- withTemporaryArchive("read3EntriesCreatingBigArchiveFileUsingZipFile",
- (f, zos) -> {
- write3EntriesCreatingBigArchiveToStream(zos);
- ZipFile zf = null;
- try {
- zf = new ZipFile(f);
- int idx = 0;
- for (final Enumeration<ZipArchiveEntry> e =
- zf.getEntriesInPhysicalOrder();
- e.hasMoreElements(); ) {
- final ZipArchiveEntry zae = e.nextElement();
- assertEquals(String.valueOf(idx),
- zae.getName());
- if (idx++ < 2) {
- assertEquals(FIVE_BILLION / 2,
- zae.getSize());
- } else {
- assertEquals(1,
- zae.getSize());
- try (InputStream i = zf.getInputStream(zae)) {
- assertNotNull(i);
- assertEquals(42, i.read());
- }
- }
- }
- } finally {
- ZipFile.closeQuietly(zf);
- }
- },
- true);
- }
-
- @Test public void testRead5GBOfZerosGeneratedBy7ZIPUsingInputStream()
- throws Throwable {
+ @Test
+ public void testRead3EntriesCreatingBigArchiveFileUsingZipFile() throws Throwable {
+ withTemporaryArchive("read3EntriesCreatingBigArchiveFileUsingZipFile", (f, zos) -> {
+ write3EntriesCreatingBigArchiveToStream(zos);
+ ZipFile zf = null;
+ try {
+ zf = new ZipFile(f);
+ int idx = 0;
+ for (final Enumeration<ZipArchiveEntry> e = zf.getEntriesInPhysicalOrder(); e.hasMoreElements();) {
+ final ZipArchiveEntry zae = e.nextElement();
+ assertEquals(String.valueOf(idx), zae.getName());
+ if (idx++ < 2) {
+ assertEquals(FIVE_BILLION / 2, zae.getSize());
+ } else {
+ assertEquals(1, zae.getSize());
+ try (InputStream i = zf.getInputStream(zae)) {
+ assertNotNull(i);
+ assertEquals(42, i.read());
+ }
+ }
+ }
+ } finally {
+ ZipFile.closeQuietly(zf);
+ }
+ }, true);
+ }
+
+ @Test
+ public void testRead5GBOfZerosGeneratedBy7ZIPUsingInputStream() throws Throwable {
read5GBOfZerosImpl(get5GBZerosFileGeneratedBy7ZIP(), "5GB_of_Zeros");
}
- @Test public void testRead5GBOfZerosGeneratedBy7ZIPUsingZipFile()
- throws Throwable {
- read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedBy7ZIP(),
- "5GB_of_Zeros");
+ @Test
+ public void testRead5GBOfZerosGeneratedBy7ZIPUsingZipFile() throws Throwable {
+ read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedBy7ZIP(), "5GB_of_Zeros");
}
- @Test public void testRead5GBOfZerosGeneratedByJava7JarUsingInputStream()
- throws Throwable {
+ @Test
+ public void testRead5GBOfZerosGeneratedByJava7JarUsingInputStream() throws Throwable {
read5GBOfZerosImpl(get5GBZerosFileGeneratedByJava7Jar(), "5GB_of_Zeros");
}
- @Test public void testRead5GBOfZerosGeneratedByJava7JarUsingZipFile()
- throws Throwable {
- read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedByJava7Jar(),
- "5GB_of_Zeros");
+ @Test
+ public void testRead5GBOfZerosGeneratedByJava7JarUsingZipFile() throws Throwable {
+ read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedByJava7Jar(), "5GB_of_Zeros");
}
- @Test public void testRead5GBOfZerosGeneratedByPKZipUsingInputStream()
- throws Throwable {
- read5GBOfZerosImpl(get5GBZerosFileGeneratedByPKZip(),
- "zip6/5GB_of_Zeros");
+ @Test
+ public void testRead5GBOfZerosGeneratedByPKZipUsingInputStream() throws Throwable {
+ read5GBOfZerosImpl(get5GBZerosFileGeneratedByPKZip(), "zip6/5GB_of_Zeros");
}
- @Test public void testRead5GBOfZerosGeneratedByPKZipUsingZipFile()
- throws Throwable {
- read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedByPKZip(),
- "zip6/5GB_of_Zeros");
+ @Test
+ public void testRead5GBOfZerosGeneratedByPKZipUsingZipFile() throws Throwable {
+ read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedByPKZip(), "zip6/5GB_of_Zeros");
}
- @Test public void testRead5GBOfZerosGeneratedByWinZIPUsingInputStream()
- throws Throwable {
+ @Test
+ public void testRead5GBOfZerosGeneratedByWinZIPUsingInputStream() throws Throwable {
read5GBOfZerosImpl(get5GBZerosFileGeneratedByWinZIP(), "5GB_of_Zeros");
}
- @Test public void testRead5GBOfZerosGeneratedByWinZIPUsingZipFile()
- throws Throwable {
- read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedByWinZIP(),
- "5GB_of_Zeros");
+ @Test
+ public void testRead5GBOfZerosGeneratedByWinZIPUsingZipFile() throws Throwable {
+ read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedByWinZIP(), "5GB_of_Zeros");
}
- @Test public void testRead5GBOfZerosUsingInputStream() throws Throwable {
+ @Test
+ public void testRead5GBOfZerosUsingInputStream() throws Throwable {
read5GBOfZerosImpl(get5GBZerosFile(), "5GB_of_Zeros");
}
- @Test public void testRead5GBOfZerosUsingZipFile() throws Throwable {
+ @Test
+ public void testRead5GBOfZerosUsingZipFile() throws Throwable {
read5GBOfZerosUsingZipFileImpl(get5GBZerosFile(), "5GB_of_Zeros");
}
- @Test public void testReadSelfGenerated100KFilesUsingZipFile()
- throws Throwable {
- withTemporaryArchive("readSelfGenerated100KFilesUsingZipFile()",
- (f, zos) -> {
- write100KFilesToStream(zos);
- read100KFilesUsingZipFileImpl(f);
- },
- true);
+ @Test
+ public void testReadSelfGenerated100KFilesUsingZipFile() throws Throwable {
+ withTemporaryArchive("readSelfGenerated100KFilesUsingZipFile()", (f, zos) -> {
+ write100KFilesToStream(zos);
+ read100KFilesUsingZipFileImpl(f);
+ }, true);
}
- @Test public void testWrite100KFilesFile() throws Throwable {
+ @Test
+ public void testWrite100KFilesFile() throws Throwable {
withTemporaryArchive("write100KFilesFile", write100KFiles(), true);
}
- @Test public void testWrite100KFilesFileModeAlways() throws Throwable {
- withTemporaryArchive("write100KFilesFileModeAlways",
- write100KFiles(Zip64Mode.Always), true);
+ @Test
+ public void testWrite100KFilesFileModeAlways() throws Throwable {
+ withTemporaryArchive("write100KFilesFileModeAlways", write100KFiles(Zip64Mode.Always), true);
}
- @Test public void testWrite100KFilesFileModeNever() throws Throwable {
- withTemporaryArchive("write100KFilesFileModeNever",
- write100KFilesModeNever, true);
+ @Test
+ public void testWrite100KFilesFileModeNever() throws Throwable {
+ withTemporaryArchive("write100KFilesFileModeNever", write100KFilesModeNever, true);
}
- @Test public void testWrite100KFilesStream() throws Throwable {
+ @Test
+ public void testWrite100KFilesStream() throws Throwable {
withTemporaryArchive("write100KFilesStream", write100KFiles(), false);
}
- @Test public void testWrite100KFilesStreamModeAlways() throws Throwable {
- withTemporaryArchive("write100KFilesStreamModeAlways",
- write100KFiles(Zip64Mode.Always), false);
+ @Test
+ public void testWrite100KFilesStreamModeAlways() throws Throwable {
+ withTemporaryArchive("write100KFilesStreamModeAlways", write100KFiles(Zip64Mode.Always), false);
}
- @Test public void testWrite100KFilesStreamModeNever() throws Throwable {
- withTemporaryArchive("write100KFilesStreamModeNever",
- write100KFilesModeNever, false);
+ @Test
+ public void testWrite100KFilesStreamModeNever() throws Throwable {
+ withTemporaryArchive("write100KFilesStreamModeNever", write100KFilesModeNever, false);
}
- @Test public void testWrite3EntriesCreatingBigArchiveFile() throws Throwable {
- withTemporaryArchive("write3EntriesCreatingBigArchiveFile",
- write3EntriesCreatingBigArchive(),
- true);
+ @Test
+ public void testWrite3EntriesCreatingBigArchiveFile() throws Throwable {
+ withTemporaryArchive("write3EntriesCreatingBigArchiveFile", write3EntriesCreatingBigArchive(), true);
}
- @Test public void testWrite3EntriesCreatingBigArchiveFileModeAlways()
- throws Throwable {
- withTemporaryArchive("write3EntriesCreatingBigArchiveFileModeAlways",
- write3EntriesCreatingBigArchive(Zip64Mode.Always),
- true);
+ @Test
+ public void testWrite3EntriesCreatingBigArchiveFileModeAlways() throws Throwable {
+ withTemporaryArchive("write3EntriesCreatingBigArchiveFileModeAlways", write3EntriesCreatingBigArchive(Zip64Mode.Always), true);
}
- @Test public void testWrite3EntriesCreatingBigArchiveFileModeNever()
- throws Throwable {
- withTemporaryArchive("write3EntriesCreatingBigArchiveFileModeNever",
- write3EntriesCreatingBigArchiveModeNever,
- true);
+ @Test
+ public void testWrite3EntriesCreatingBigArchiveFileModeNever() throws Throwable {
+ withTemporaryArchive("write3EntriesCreatingBigArchiveFileModeNever", write3EntriesCreatingBigArchiveModeNever, true);
}
- @Test public void testWrite3EntriesCreatingBigArchiveStream() throws Throwable {
- withTemporaryArchive("write3EntriesCreatingBigArchiveStream",
- write3EntriesCreatingBigArchive(),
- false);
+ @Test
+ public void testWrite3EntriesCreatingBigArchiveStream() throws Throwable {
+ withTemporaryArchive("write3EntriesCreatingBigArchiveStream", write3EntriesCreatingBigArchive(), false);
}
- @Test public void testWrite3EntriesCreatingBigArchiveStreamModeAlways()
- throws Throwable {
- withTemporaryArchive("write3EntriesCreatingBigArchiveStreamModeAlways",
- write3EntriesCreatingBigArchive(Zip64Mode.Always),
- false);
+ @Test
+ public void testWrite3EntriesCreatingBigArchiveStreamModeAlways() throws Throwable {
+ withTemporaryArchive("write3EntriesCreatingBigArchiveStreamModeAlways", write3EntriesCreatingBigArchive(Zip64Mode.Always), false);
}
- @Test public void testWrite3EntriesCreatingBigArchiveStreamModeNever()
- throws Throwable {
- withTemporaryArchive("write3EntriesCreatingBigArchiveStreamModeNever",
- write3EntriesCreatingBigArchiveModeNever,
- false);
+ @Test
+ public void testWrite3EntriesCreatingBigArchiveStreamModeNever() throws Throwable {
+ withTemporaryArchive("write3EntriesCreatingBigArchiveStreamModeNever", write3EntriesCreatingBigArchiveModeNever, false);
}
@Test
- public void testWrite3EntriesCreatingManySplitArchiveFileModeAlways()
- throws Throwable {
+ public void testWrite3EntriesCreatingManySplitArchiveFileModeAlways() throws Throwable {
// about 76,293 ZIP split segments will be created
- withTemporaryArchive("write3EntriesCreatingManySplitArchiveFileModeAlways",
- write3EntriesCreatingBigArchive(Zip64Mode.Always, true),
- true, 65536L);
+ withTemporaryArchive("write3EntriesCreatingManySplitArchiveFileModeAlways", write3EntriesCreatingBigArchive(Zip64Mode.Always, true), true, 65536L);
}
@Test
- public void testWrite3EntriesCreatingManySplitArchiveFileModeNever()
- throws Throwable {
- withTemporaryArchive("write3EntriesCreatingManySplitArchiveFileModeNever",
- write3EntriesCreatingBigArchiveModeNever,
- true, 65536L);
+ public void testWrite3EntriesCreatingManySplitArchiveFileModeNever() throws Throwable {
+ withTemporaryArchive("write3EntriesCreatingManySplitArchiveFileModeNever", write3EntriesCreatingBigArchiveModeNever, true, 65536L);
}
- @Test public void testWriteAndRead5GBOfZerosUsingZipFile() throws Throwable {
+ @Test
+ public void testWriteAndRead5GBOfZerosUsingZipFile() throws Throwable {
File f = null;
try {
f = write5GBZerosFile("writeAndRead5GBOfZerosUsingZipFile");
@@ -2299,314 +2055,226 @@ public class Zip64SupportIT {
}
}
- @Test public void testWriteBigDeflatedEntryKnownSizeToFile()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryKnownSizeToFile",
- writeBigDeflatedEntryToFile(true),
- true);
+ @Test
+ public void testWriteBigDeflatedEntryKnownSizeToFile() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryKnownSizeToFile", writeBigDeflatedEntryToFile(true), true);
}
- @Test public void testWriteBigDeflatedEntryKnownSizeToFileModeAlways()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryKnownSizeToFileModeAlways",
- writeBigDeflatedEntryToFile(true, Zip64Mode.Always),
- true);
+ @Test
+ public void testWriteBigDeflatedEntryKnownSizeToFileModeAlways() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryKnownSizeToFileModeAlways", writeBigDeflatedEntryToFile(true, Zip64Mode.Always), true);
}
- @Test public void testWriteBigDeflatedEntryKnownSizeToFileModeNever()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryKnownSizeToFileModeNever",
- writeBigDeflatedEntryToFileModeNever(true),
- true);
+ @Test
+ public void testWriteBigDeflatedEntryKnownSizeToFileModeNever() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryKnownSizeToFileModeNever", writeBigDeflatedEntryToFileModeNever(true), true);
}
- @Test public void testWriteBigDeflatedEntryKnownSizeToStream()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryKnownSizeToStream",
- writeBigDeflatedEntryToStream(true,
- Zip64Mode.AsNeeded),
- false);
+ @Test
+ public void testWriteBigDeflatedEntryKnownSizeToStream() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryKnownSizeToStream", writeBigDeflatedEntryToStream(true, Zip64Mode.AsNeeded), false);
}
- @Test public void testWriteBigDeflatedEntryKnownSizeToStreamModeAlways()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryKnownSizeToStreamModeAlways",
- writeBigDeflatedEntryToStream(true,
- Zip64Mode.Always),
- false);
+ @Test
+ public void testWriteBigDeflatedEntryKnownSizeToStreamModeAlways() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryKnownSizeToStreamModeAlways", writeBigDeflatedEntryToStream(true, Zip64Mode.Always), false);
}
- @Test public void testWriteBigDeflatedEntryKnownSizeToStreamModeNever()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryKnownSizeToStreamModeNever",
- (f, zos) -> {
- zos.setUseZip64(Zip64Mode.Never);
- final Zip64RequiredException ex = assertThrows(Zip64RequiredException.class, () -> {
- final ZipArchiveEntry zae =
- new ZipArchiveEntry("0");
- zae.setSize(FIVE_BILLION);
- zae.setMethod(ZipEntry.DEFLATED);
- zos.putArchiveEntry(zae);
- }, "expected a Zip64RequiredException");
- assertTrue(ex.getMessage().startsWith("0's size"));
- }, false);
+ @Test
+ public void testWriteBigDeflatedEntryKnownSizeToStreamModeNever() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryKnownSizeToStreamModeNever", (f, zos) -> {
+ zos.setUseZip64(Zip64Mode.Never);
+ final Zip64RequiredException ex = assertThrows(Zip64RequiredException.class, () -> {
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ zae.setSize(FIVE_BILLION);
+ zae.setMethod(ZipEntry.DEFLATED);
+ zos.putArchiveEntry(zae);
+ }, "expected a Zip64RequiredException");
+ assertTrue(ex.getMessage().startsWith("0's size"));
+ }, false);
}
- @Test public void testWriteBigDeflatedEntryUnknownSizeToFile()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToFile",
- writeBigDeflatedEntryToFile(false),
- true);
+ @Test
+ public void testWriteBigDeflatedEntryUnknownSizeToFile() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToFile", writeBigDeflatedEntryToFile(false), true);
}
- @Test public void testWriteBigDeflatedEntryUnknownSizeToFileModeAlways()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToFileModeAlways",
- writeBigDeflatedEntryToFile(false,
- Zip64Mode.Always),
- true);
+ @Test
+ public void testWriteBigDeflatedEntryUnknownSizeToFileModeAlways() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToFileModeAlways", writeBigDeflatedEntryToFile(false, Zip64Mode.Always), true);
}
- @Test public void testWriteBigDeflatedEntryUnknownSizeToFileModeNever()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToFileModeNever",
- writeBigDeflatedEntryToFileModeNever(false),
- true);
+ @Test
+ public void testWriteBigDeflatedEntryUnknownSizeToFileModeNever() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToFileModeNever", writeBigDeflatedEntryToFileModeNever(false), true);
}
- @Test public void testWriteBigDeflatedEntryUnknownSizeToStream()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToStream",
- writeBigDeflatedEntryUnknownSizeToStream(Zip64Mode
- .AsNeeded),
- false);
+ @Test
+ public void testWriteBigDeflatedEntryUnknownSizeToStream() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToStream", writeBigDeflatedEntryUnknownSizeToStream(Zip64Mode.AsNeeded), false);
}
- @Test public void testWriteBigDeflatedEntryUnknownSizeToStreamModeAlways()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToStreamModeAlways",
- writeBigDeflatedEntryToStream(false,
- Zip64Mode.Always),
- false);
+ @Test
+ public void testWriteBigDeflatedEntryUnknownSizeToStreamModeAlways() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToStreamModeAlways", writeBigDeflatedEntryToStream(false, Zip64Mode.Always), false);
}
- @Test public void testWriteBigDeflatedEntryUnknownSizeToStreamModeNever()
- throws Throwable {
- withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToStreamModeNever",
- writeBigDeflatedEntryUnknownSizeToStream(Zip64Mode
- .Never),
- false);
+ @Test
+ public void testWriteBigDeflatedEntryUnknownSizeToStreamModeNever() throws Throwable {
+ withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToStreamModeNever", writeBigDeflatedEntryUnknownSizeToStream(Zip64Mode.Never), false);
}
- @Test public void testWriteBigStoredEntryKnownSizeToFile() throws Throwable {
- withTemporaryArchive("writeBigStoredEntryKnownSizeToFile",
- writeBigStoredEntry(true),
- true);
+ @Test
+ public void testWriteBigStoredEntryKnownSizeToFile() throws Throwable {
+ withTemporaryArchive("writeBigStoredEntryKnownSizeToFile", writeBigStoredEntry(true), true);
}
- @Test public void testWriteBigStoredEntryKnownSizeToFileModeAlways()
- throws Throwable {
- withTemporaryArchive("writeBigStoredEntryKnownSizeToFileModeAlways",
- writeBigStoredEntry(true, Zip64Mode.Always),
- true);
+ @Test
+ public void testWriteBigStoredEntryKnownSizeToFileModeAlways() throws Throwable {
+ withTemporaryArchive("writeBigStoredEntryKnownSizeToFileModeAlways", writeBigStoredEntry(true, Zip64Mode.Always), true);
}
- @Test public void testWriteBigStoredEntryKnownSizeToFileModeNever()
- throws Throwable {
- withTemporaryArchive("writeBigStoredEntryKnownSizeToFileModeNever",
- writeBigStoredEntryModeNever(true),
- true);
+ @Test
+ public void testWriteBigStoredEntryKnownSizeToFileModeNever() throws Throwable {
+ withTemporaryArchive("writeBigStoredEntryKnownSizeToFileModeNever", writeBigStoredEntryModeNever(true), true);
}
/*
- * No Compression + Stream => sizes must be known before data is
- * written.
+ * No Compression + Stream => sizes must be known before data is written.
*/
- @Test public void testWriteBigStoredEntryToStream() throws Throwable {
- withTemporaryArchive("writeBigStoredEntryToStream",
- writeBigStoredEntry(true),
- false);
+ @Test
+ public void testWriteBigStoredEntryToStream() throws Throwable {
+ withTemporaryArchive("writeBigStoredEntryToStream", writeBigStoredEntry(true), false);
}
- @Test public void testWriteBigStoredEntryToStreamModeAlways() throws Throwable {
- withTemporaryArchive("writeBigStoredEntryToStreamModeAlways",
- writeBigStoredEntry(true, Zip64Mode.Always),
- false);
+ @Test
+ public void testWriteBigStoredEntryToStreamModeAlways() throws Throwable {
+ withTemporaryArchive("writeBigStoredEntryToStreamModeAlways", writeBigStoredEntry(true, Zip64Mode.Always), false);
}
- @Test public void testWriteBigStoredEntryToStreamModeNever() throws Throwable {
- withTemporaryArchive("writeBigStoredEntryToStreamModeNever",
- writeBigStoredEntryModeNever(true),
- false);
+ @Test
+ public void testWriteBigStoredEntryToStreamModeNever() throws Throwable {
+ withTemporaryArchive("writeBigStoredEntryToStreamModeNever", writeBigStoredEntryModeNever(true), false);
}
- @Test public void testWriteBigStoredEntryUnknownSizeToFile() throws Throwable {
- withTemporaryArchive("writeBigStoredEntryUnknownSizeToFile",
- writeBigStoredEntry(false),
- true);
+ @Test
+ public void testWriteBigStoredEntryUnknownSizeToFile() throws Throwable {
+ withTemporaryArchive("writeBigStoredEntryUnknownSizeToFile", writeBigStoredEntry(false), true);
}
- @Test public void testWriteBigStoredEntryUnknownSizeToFileModeAlways()
- throws Throwable {
- withTemporaryArchive("writeBigStoredEntryUnknownSizeToFileModeAlways",
- writeBigStoredEntry(false, Zip64Mode.Always),
- true);
+ @Test
+ public void testWriteBigStoredEntryUnknownSizeToFileModeAlways() throws Throwable {
+ withTemporaryArchive("writeBigStoredEntryUnknownSizeToFileModeAlways", writeBigStoredEntry(false, Zip64Mode.Always), true);
}
- @Test public void testWriteBigStoredEntryUnknownSizeToFileModeNever()
- throws Throwable {
- withTemporaryArchive("writeBigStoredEntryUnknownSizeToFileModeNever",
- writeBigStoredEntryModeNever(false),
- true);
+ @Test
+ public void testWriteBigStoredEntryUnknownSizeToFileModeNever() throws Throwable {
+ withTemporaryArchive("writeBigStoredEntryUnknownSizeToFileModeNever", writeBigStoredEntryModeNever(false), true);
}
- @Test public void testWriteSmallDeflatedEntryKnownSizeToFile()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToFile",
- writeSmallDeflatedEntryToFile(true),
- true);
+ @Test
+ public void testWriteSmallDeflatedEntryKnownSizeToFile() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToFile", writeSmallDeflatedEntryToFile(true), true);
}
- @Test public void testWriteSmallDeflatedEntryKnownSizeToFileModeAlways()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToFileModeAlways",
- writeSmallDeflatedEntryToFileModeAlways(true),
- true);
+ @Test
+ public void testWriteSmallDeflatedEntryKnownSizeToFileModeAlways() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToFileModeAlways", writeSmallDeflatedEntryToFileModeAlways(true), true);
}
- @Test public void testWriteSmallDeflatedEntryKnownSizeToFileModeNever()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToFileModeNever",
- writeSmallDeflatedEntryToFile(true,
- Zip64Mode.Never),
- true);
+ @Test
+ public void testWriteSmallDeflatedEntryKnownSizeToFileModeNever() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToFileModeNever", writeSmallDeflatedEntryToFile(true, Zip64Mode.Never), true);
}
- @Test public void testWriteSmallDeflatedEntryKnownSizeToStream()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToStream",
- writeSmallDeflatedEntryToStream(true,
- Zip64Mode.AsNeeded),
- false);
+ @Test
+ public void testWriteSmallDeflatedEntryKnownSizeToStream() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToStream", writeSmallDeflatedEntryToStream(true, Zip64Mode.AsNeeded), false);
}
- @Test public void testWriteSmallDeflatedEntryKnownSizeToStreamModeAlways()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToStreamModeAlways",
- writeSmallDeflatedEntryToStreamModeAlways(true),
- false);
+ @Test
+ public void testWriteSmallDeflatedEntryKnownSizeToStreamModeAlways() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToStreamModeAlways", writeSmallDeflatedEntryToStreamModeAlways(true), false);
}
- @Test public void testWriteSmallDeflatedEntryKnownSizeToStreamModeNever()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToStreamModeNever",
- writeSmallDeflatedEntryToStream(true,
- Zip64Mode.Never),
- false);
+ @Test
+ public void testWriteSmallDeflatedEntryKnownSizeToStreamModeNever() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryKnownSizeToStreamModeNever", writeSmallDeflatedEntryToStream(true, Zip64Mode.Never), false);
}
- @Test public void testWriteSmallDeflatedEntryUnknownSizeToFile()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToFile",
- writeSmallDeflatedEntryToFile(false),
- true);
+ @Test
+ public void testWriteSmallDeflatedEntryUnknownSizeToFile() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToFile", writeSmallDeflatedEntryToFile(false), true);
}
- @Test public void testWriteSmallDeflatedEntryUnknownSizeToFileModeAlways()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToFileModeAlways",
- writeSmallDeflatedEntryToFileModeAlways(false),
- true);
+ @Test
+ public void testWriteSmallDeflatedEntryUnknownSizeToFileModeAlways() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToFileModeAlways", writeSmallDeflatedEntryToFileModeAlways(false), true);
}
- @Test public void testWriteSmallDeflatedEntryUnknownSizeToFileModeNever()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToFileModeNever",
- writeSmallDeflatedEntryToFile(false,
- Zip64Mode.Never),
- true);
+ @Test
+ public void testWriteSmallDeflatedEntryUnknownSizeToFileModeNever() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToFileModeNever", writeSmallDeflatedEntryToFile(false, Zip64Mode.Never), true);
}
- @Test public void testWriteSmallDeflatedEntryUnknownSizeToStream()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToStream",
- writeSmallDeflatedEntryToStream(false,
- Zip64Mode.AsNeeded),
- false);
+ @Test
+ public void testWriteSmallDeflatedEntryUnknownSizeToStream() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToStream", writeSmallDeflatedEntryToStream(false, Zip64Mode.AsNeeded), false);
}
- @Test public void testWriteSmallDeflatedEntryUnknownSizeToStreamModeAlways()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToStreamModeAlways",
- writeSmallDeflatedEntryToStreamModeAlways(false),
- false);
+ @Test
+ public void testWriteSmallDeflatedEntryUnknownSizeToStreamModeAlways() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToStreamModeAlways", writeSmallDeflatedEntryToStreamModeAlways(false), false);
}
- @Test public void testWriteSmallDeflatedEntryUnknownSizeToStreamModeNever()
- throws Throwable {
- withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToStreamModeNever",
- writeSmallDeflatedEntryToStream(false,
- Zip64Mode.Never),
- false);
+ @Test
+ public void testWriteSmallDeflatedEntryUnknownSizeToStreamModeNever() throws Throwable {
+ withTemporaryArchive("writeSmallDeflatedEntryUnknownSizeToStreamModeNever", writeSmallDeflatedEntryToStream(false, Zip64Mode.Never), false);
}
- @Test public void testWriteSmallStoredEntryKnownSizeToFile() throws Throwable {
- withTemporaryArchive("writeSmallStoredEntryKnownSizeToFile",
- writeSmallStoredEntry(true),
- true);
+ @Test
+ public void testWriteSmallStoredEntryKnownSizeToFile() throws Throwable {
+ withTemporaryArchive("writeSmallStoredEntryKnownSizeToFile", writeSmallStoredEntry(true), true);
}
- @Test public void testWriteSmallStoredEntryKnownSizeToFileModeAlways()
- throws Throwable {
- withTemporaryArchive("writeSmallStoredEntryKnownSizeToFileModeAlways",
- writeSmallStoredEntryModeAlways(true),
- true);
+ @Test
+ public void testWriteSmallStoredEntryKnownSizeToFileModeAlways() throws Throwable {
+ withTemporaryArchive("writeSmallStoredEntryKnownSizeToFileModeAlways", writeSmallStoredEntryModeAlways(true), true);
}
- @Test public void testWriteSmallStoredEntryKnownSizeToFileModeNever()
- throws Throwable {
- withTemporaryArchive("writeSmallStoredEntryKnownSizeToFileModeNever",
- writeSmallStoredEntry(true, Zip64Mode.Never),
- true);
+ @Test
+ public void testWriteSmallStoredEntryKnownSizeToFileModeNever() throws Throwable {
+ withTemporaryArchive("writeSmallStoredEntryKnownSizeToFileModeNever", writeSmallStoredEntry(true, Zip64Mode.Never), true);
}
- @Test public void testWriteSmallStoredEntryToStream() throws Throwable {
- withTemporaryArchive("writeSmallStoredEntryToStream",
- writeSmallStoredEntry(true),
- false);
+ @Test
+ public void testWriteSmallStoredEntryToStream() throws Throwable {
+ withTemporaryArchive("writeSmallStoredEntryToStream", writeSmallStoredEntry(true), false);
}
- @Test public void testWriteSmallStoredEntryToStreamModeAlways()
- throws Throwable {
- withTemporaryArchive("writeSmallStoredEntryToStreamModeAlways",
- writeSmallStoredEntryModeAlways(true),
- false);
+ @Test
+ public void testWriteSmallStoredEntryToStreamModeAlways() throws Throwable {
+ withTemporaryArchive("writeSmallStoredEntryToStreamModeAlways", writeSmallStoredEntryModeAlways(true), false);
}
- @Test public void testWriteSmallStoredEntryToStreamModeNever() throws Throwable {
- withTemporaryArchive("writeSmallStoredEntryToStreamModeNever",
- writeSmallStoredEntry(true, Zip64Mode.Never),
- false);
+ @Test
+ public void testWriteSmallStoredEntryToStreamModeNever() throws Throwable {
+ withTemporaryArchive("writeSmallStoredEntryToStreamModeNever", writeSmallStoredEntry(true, Zip64Mode.Never), false);
}
- @Test public void testWriteSmallStoredEntryUnknownSizeToFile() throws Throwable {
- withTemporaryArchive("writeSmallStoredEntryUnknownSizeToFile",
- writeSmallStoredEntry(false),
- true);
+ @Test
+ public void testWriteSmallStoredEntryUnknownSizeToFile() throws Throwable {
+ withTemporaryArchive("writeSmallStoredEntryUnknownSizeToFile", writeSmallStoredEntry(false), true);
}
- @Test public void testWriteSmallStoredEntryUnknownSizeToFileModeAlways()
- throws Throwable {
- withTemporaryArchive("writeSmallStoredEntryUnknownSizeToFileModeAlways",
- writeSmallStoredEntryModeAlways(false),
- true);
+ @Test
+ public void testWriteSmallStoredEntryUnknownSizeToFileModeAlways() throws Throwable {
+ withTemporaryArchive("writeSmallStoredEntryUnknownSizeToFileModeAlways", writeSmallStoredEntryModeAlways(false), true);
}
- @Test public void testWriteSmallStoredEntryUnknownSizeToFileModeNever()
- throws Throwable {
- withTemporaryArchive("writeSmallStoredEntryUnknownSizeToFileModeNever",
- writeSmallStoredEntry(false, Zip64Mode.Never),
- true);
+ @Test
+ public void testWriteSmallStoredEntryUnknownSizeToFileModeNever() throws Throwable {
+ withTemporaryArchive("writeSmallStoredEntryUnknownSizeToFileModeNever", writeSmallStoredEntry(false, Zip64Mode.Never), true);
}
@Test
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
index f61dcd95d..650dfaaa8 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
@@ -60,9 +60,7 @@ public class ZipArchiveEntryTest {
u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
u.setLocalFileDataData(ByteUtils.EMPTY_BYTE_ARRAY);
final UnparseableExtraFieldData x = new UnparseableExtraFieldData();
- final byte[] unparseable = {
- 0, 0, (byte) 0xff, (byte) 0xff, 0, 0, 0
- };
+ final byte[] unparseable = { 0, 0, (byte) 0xff, (byte) 0xff, 0, 0, 0 };
x.parseFromLocalFileData(unparseable, 0, unparseable.length);
return new ZipExtraField[] { a, u, x };
}
@@ -80,12 +78,12 @@ public class ZipArchiveEntryTest {
u.setLocalFileDataData(ByteUtils.EMPTY_BYTE_ARRAY);
final ZipArchiveEntry ze = new ZipArchiveEntry("test/");
- ze.setExtraFields(new ZipExtraField[] {a, u});
+ ze.setExtraFields(new ZipExtraField[] { a, u });
final byte[] data1 = ze.getExtra();
final UnrecognizedExtraField u2 = new UnrecognizedExtraField();
u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
- u2.setLocalFileDataData(new byte[] {1});
+ u2.setLocalFileDataData(new byte[] { 1 });
ze.addAsFirstExtraField(u2);
final byte[] data2 = ze.getExtra();
@@ -97,7 +95,7 @@ public class ZipArchiveEntryTest {
final UnrecognizedExtraField u3 = new UnrecognizedExtraField();
u3.setHeaderId(new ZipShort(2));
- u3.setLocalFileDataData(new byte[] {1});
+ u3.setLocalFileDataData(new byte[] { 1 });
ze.addAsFirstExtraField(u3);
result = ze.getExtraFields();
assertEquals(3, result.length, "third pass");
@@ -107,9 +105,7 @@ public class ZipArchiveEntryTest {
}
/**
- * Test case for
- * <a href="https://issues.apache.org/jira/browse/COMPRESS-93"
- * >COMPRESS-93</a>.
+ * Test case for <a href="https://issues.apache.org/jira/browse/COMPRESS-93" >COMPRESS-93</a>.
*/
@Test
public void testCompressionMethod() throws Exception {
@@ -164,31 +160,30 @@ public class ZipArchiveEntryTest {
u.setLocalFileDataData(ByteUtils.EMPTY_BYTE_ARRAY);
final ZipArchiveEntry ze = new ZipArchiveEntry("test/");
- ze.setExtraFields(new ZipExtraField[] {a, u});
+ ze.setExtraFields(new ZipExtraField[] { a, u });
// merge
// Header-ID 1 + length 1 + one byte of data
final byte[] b = ExtraFieldUtilsTest.UNRECOGNIZED_HEADER.getBytes();
- ze.setCentralDirectoryExtra(new byte[] {b[0], b[1], 1, 0, 127});
+ ze.setCentralDirectoryExtra(new byte[] { b[0], b[1], 1, 0, 127 });
ZipExtraField[] result = ze.getExtraFields();
assertEquals(2, result.length, "first pass");
assertSame(a, result[0]);
- assertEquals(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER,
- result[1].getHeaderId());
+ assertEquals(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER, result[1].getHeaderId());
assertEquals(new ZipShort(0), result[1].getLocalFileDataLength());
assertEquals(new ZipShort(1), result[1].getCentralDirectoryLength());
// add new
// Header-ID 2 + length 0
- ze.setCentralDirectoryExtra(new byte[] {2, 0, 0, 0});
+ ze.setCentralDirectoryExtra(new byte[] { 2, 0, 0, 0 });
result = ze.getExtraFields();
assertEquals(3, result.length, "second pass");
// merge
// Header-ID 2 + length 1 + one byte of data
- ze.setExtra(new byte[] {2, 0, 1, 0, 127});
+ ze.setExtra(new byte[] { 2, 0, 1, 0, 127 });
result = ze.getExtraFields();
assertEquals(3, result.length, "third pass");
@@ -211,7 +206,7 @@ public class ZipArchiveEntryTest {
u.setLocalFileDataData(ByteUtils.EMPTY_BYTE_ARRAY);
final ZipArchiveEntry ze = new ZipArchiveEntry("test/");
- ze.setExtraFields(new ZipExtraField[] {a, u});
+ ze.setExtraFields(new ZipExtraField[] { a, u });
final byte[] data1 = ze.getExtra();
ZipExtraField[] result = ze.getExtraFields();
assertEquals(2, result.length, "first pass");
@@ -220,7 +215,7 @@ public class ZipArchiveEntryTest {
final UnrecognizedExtraField u2 = new UnrecognizedExtraField();
u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
- u2.setLocalFileDataData(new byte[] {1});
+ u2.setLocalFileDataData(new byte[] { 1 });
ze.addExtraField(u2);
final byte[] data2 = ze.getExtra();
@@ -232,7 +227,7 @@ public class ZipArchiveEntryTest {
final UnrecognizedExtraField u3 = new UnrecognizedExtraField();
u3.setHeaderId(new ZipShort(2));
- u3.setLocalFileDataData(new byte[] {1});
+ u3.setLocalFileDataData(new byte[] { 1 });
ze.addExtraField(u3);
result = ze.getExtraFields();
assertEquals(3, result.length, "third pass");
@@ -245,8 +240,7 @@ public class ZipArchiveEntryTest {
assertSame(u3, result[1]);
assertEquals(data2.length, data3.length, "length fourth pass");
- assertThrows(NoSuchElementException.class, () -> ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER),
- "should be no such element");
+ assertThrows(NoSuchElementException.class, () -> ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER), "should be no such element");
}
@Test
@@ -270,9 +264,7 @@ public class ZipArchiveEntryTest {
}
/**
- * Test case for
- * <a href="https://issues.apache.org/jira/browse/COMPRESS-94"
- * >COMPRESS-94</a>.
+ * Test case for <a href="https://issues.apache.org/jira/browse/COMPRESS-94" >COMPRESS-94</a>.
*/
@Test
public void testNotEquals() {
@@ -283,6 +275,7 @@ public class ZipArchiveEntryTest {
/**
* Tests comment's influence on equals comparisons.
+ *
* @see "https://issues.apache.org/jira/browse/COMPRESS-187"
*/
@Test
@@ -317,8 +310,7 @@ public class ZipArchiveEntryTest {
}
@Test
- public void testReparsingUnicodeExtraWithUnsupportedversionThrowsInStrictMode()
- throws Exception {
+ public void testReparsingUnicodeExtraWithUnsupportedversionThrowsInStrictMode() throws Exception {
try (ZipFile zf = new ZipFile(getFile("COMPRESS-479.zip"))) {
final ZipArchiveEntry ze = zf.getEntry("%U20AC_for_Dollar.txt");
assertThrows(ZipException.class, () -> ze.getExtraFields(ZipArchiveEntry.ExtraFieldParsingMode.STRICT_FOR_KNOW_EXTRA_FIELDS));
@@ -496,29 +488,25 @@ public class ZipArchiveEntryTest {
assertEquals(0, ze.getPlatform());
ze.setUnixMode(0755);
assertEquals(3, ze.getPlatform());
- assertEquals(0755,
- ze.getExternalAttributes() >> 16 & 0xFFFF);
- assertEquals(0, ze.getExternalAttributes() & 0xFFFF);
+ assertEquals(0755, ze.getExternalAttributes() >> 16 & 0xFFFF);
+ assertEquals(0, ze.getExternalAttributes() & 0xFFFF);
ze.setUnixMode(0444);
assertEquals(3, ze.getPlatform());
- assertEquals(0444,
- ze.getExternalAttributes() >> 16 & 0xFFFF);
- assertEquals(1, ze.getExternalAttributes() & 0xFFFF);
+ assertEquals(0444, ze.getExternalAttributes() >> 16 & 0xFFFF);
+ assertEquals(1, ze.getExternalAttributes() & 0xFFFF);
ze = new ZipArchiveEntry("foo/");
assertEquals(0, ze.getPlatform());
ze.setUnixMode(0777);
assertEquals(3, ze.getPlatform());
- assertEquals(0777,
- ze.getExternalAttributes() >> 16 & 0xFFFF);
- assertEquals(0x10, ze.getExternalAttributes() & 0xFFFF);
+ assertEquals(0777, ze.getExternalAttributes() >> 16 & 0xFFFF);
+ assertEquals(0x10, ze.getExternalAttributes() & 0xFFFF);
ze.setUnixMode(0577);
assertEquals(3, ze.getPlatform());
- assertEquals(0577,
- ze.getExternalAttributes() >> 16 & 0xFFFF);
- assertEquals(0x11, ze.getExternalAttributes() & 0xFFFF);
+ assertEquals(0577, ze.getExternalAttributes() >> 16 & 0xFFFF);
+ assertEquals(0x11, ze.getExternalAttributes() & 0xFFFF);
}
@Test
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
index d182fe3b9..0d81227f3 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
@@ -97,8 +97,8 @@ public class ZipArchiveInputStreamTest extends AbstractTest {
* @throws IOException there are problems
*/
private InputStream forgeZipInputStream() throws IOException {
- try (final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- final ZipArchiveOutputStream zo = new ZipArchiveOutputStream(byteArrayOutputStream)) {
+ try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ ZipArchiveOutputStream zo = new ZipArchiveOutputStream(byteArrayOutputStream)) {
final ZipArchiveEntry entryA = new ZipArchiveEntry("foo");
entryA.setMethod(ZipEntry.STORED);
@@ -490,8 +490,8 @@ public class ZipArchiveInputStreamTest extends AbstractTest {
ZipArchiveInputStream splitInputStream = new ZipArchiveInputStream(inputStream, CharsetNames.UTF_8, true, false, true)) {
final File fileToCompare = getFile("COMPRESS-477/split_zip_created_by_winrar/zip_to_compare_created_by_winrar.zip");
- try (ZipArchiveInputStream inputStreamToCompare = new ZipArchiveInputStream(Files.newInputStream(fileToCompare.toPath()), CharsetNames.UTF_8,
- true, false, true)) {
+ try (ZipArchiveInputStream inputStreamToCompare = new ZipArchiveInputStream(Files.newInputStream(fileToCompare.toPath()), CharsetNames.UTF_8, true,
+ false, true)) {
ArchiveEntry entry;
while ((entry = splitInputStream.getNextEntry()) != null && inputStreamToCompare.getNextEntry() != null) {
@@ -512,8 +512,8 @@ public class ZipArchiveInputStreamTest extends AbstractTest {
ZipArchiveInputStream splitInputStream = new ZipArchiveInputStream(inputStream, CharsetNames.UTF_8, true, false, true)) {
final Path fileToCompare = getPath("COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip.zip");
- try (ZipArchiveInputStream inputStreamToCompare = new ZipArchiveInputStream(Files.newInputStream(fileToCompare), CharsetNames.UTF_8,
- true, false, true)) {
+ try (ZipArchiveInputStream inputStreamToCompare = new ZipArchiveInputStream(Files.newInputStream(fileToCompare), CharsetNames.UTF_8, true, false,
+ true)) {
ArchiveEntry entry;
while ((entry = splitInputStream.getNextEntry()) != null && inputStreamToCompare.getNextEntry() != null) {
@@ -534,8 +534,8 @@ public class ZipArchiveInputStreamTest extends AbstractTest {
ZipArchiveInputStream splitInputStream = new ZipArchiveInputStream(inputStream, CharsetNames.UTF_8, true, false, true)) {
final Path fileToCompare = getPath("COMPRESS-477/split_zip_created_by_zip/zip_to_compare_created_by_zip_zip64.zip");
- try (ZipArchiveInputStream inputStreamToCompare = new ZipArchiveInputStream(Files.newInputStream(fileToCompare), CharsetNames.UTF_8,
- true, false, true)) {
+ try (ZipArchiveInputStream inputStreamToCompare = new ZipArchiveInputStream(Files.newInputStream(fileToCompare), CharsetNames.UTF_8, true, false,
+ true)) {
ArchiveEntry entry;
while ((entry = splitInputStream.getNextEntry()) != null && inputStreamToCompare.getNextEntry() != null) {
@@ -568,7 +568,7 @@ public class ZipArchiveInputStreamTest extends AbstractTest {
*/
@Test
public void testThrowOnInvalidEntry() throws Exception {
- try (final ZipArchiveInputStream zip = new ZipArchiveInputStream(ZipArchiveInputStreamTest.class.getResourceAsStream("/invalid-zip.zip"))) {
+ try (ZipArchiveInputStream zip = new ZipArchiveInputStream(ZipArchiveInputStreamTest.class.getResourceAsStream("/invalid-zip.zip"))) {
final ZipException expected = assertThrows(ZipException.class, zip::getNextZipEntry, "IOException expected");
assertTrue(expected.getMessage().contains("Unexpected record signature"));
}
@@ -683,7 +683,7 @@ public class ZipArchiveInputStreamTest extends AbstractTest {
public void testWithBytesAfterData() throws Exception {
final int expectedNumEntries = 2;
try (InputStream is = ZipArchiveInputStreamTest.class.getResourceAsStream("/archive_with_bytes_after_data.zip");
- final ZipArchiveInputStream zip = new ZipArchiveInputStream(is)) {
+ ZipArchiveInputStream zip = new ZipArchiveInputStream(is)) {
int actualNumEntries = 0;
ZipArchiveEntry zae = zip.getNextZipEntry();
while (zae != null) {
@@ -714,9 +714,8 @@ public class ZipArchiveInputStreamTest extends AbstractTest {
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void zipInputStream(final boolean allowStoredEntriesWithDataDescriptor) {
- try (ZipArchiveInputStream zIn = new ZipArchiveInputStream(
- Files.newInputStream(Paths.get("src/test/resources/COMPRESS-647/test.zip")), CharsetNames.UTF_8, false,
- allowStoredEntriesWithDataDescriptor)) {
+ try (ZipArchiveInputStream zIn = new ZipArchiveInputStream(Files.newInputStream(Paths.get("src/test/resources/COMPRESS-647/test.zip")),
+ CharsetNames.UTF_8, false, allowStoredEntriesWithDataDescriptor)) {
ZipArchiveEntry zae = zIn.getNextEntry();
while (zae != null) {
zae = zIn.getNextEntry();
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipClassCoverageTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipClassCoverageTest.java
index 1ada20f83..dc9d722a5 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipClassCoverageTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipClassCoverageTest.java
@@ -32,8 +32,7 @@ import org.junit.jupiter.api.Test;
public class ZipClassCoverageTest {
@Test
- public void testConstantConstructor()
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
+ public void testConstantConstructor() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
final Class<ZipConstants> clazz = ZipConstants.class;
final Constructor<ZipConstants> constructor = clazz.getDeclaredConstructor();
assertFalse(constructor.isAccessible());
@@ -43,6 +42,7 @@ public class ZipClassCoverageTest {
constructor.setAccessible(false);
}
+
@Test
public void testConstructZip64RequiredException() {
final Zip64RequiredException e = new Zip64RequiredException("critique of pure");
@@ -53,8 +53,7 @@ public class ZipClassCoverageTest {
public void testMessageException() {
final ZipArchiveEntry ze = new ZipArchiveEntry("hello");
final String entryTooBigMessage = Zip64RequiredException.getEntryTooBigMessage(ze);
- assertEquals("hello's size exceeds the limit of 4GByte.",
- entryTooBigMessage);
+ assertEquals("hello's size exceeds the limit of 4GByte.", entryTooBigMessage);
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
index f14d65e37..7c742c68b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
@@ -34,11 +34,9 @@ public class ZipEightByteIntegerTest {
*/
@Test
public void testBIFromBytes() {
- final byte[] val = {(byte) 0xFE, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
+ final byte[] val = { (byte) 0xFE, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
final ZipEightByteInteger zl = new ZipEightByteInteger(val);
- assertEquals(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1),
- zl.getValue(),
- "value from bytes");
+ assertEquals(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1), zl.getValue(), "value from bytes");
}
/**
@@ -46,9 +44,7 @@ public class ZipEightByteIntegerTest {
*/
@Test
public void testBIToBytes() {
- final ZipEightByteInteger zl =
- new ZipEightByteInteger(BigInteger.valueOf(Long.MAX_VALUE)
- .shiftLeft(1));
+ final ZipEightByteInteger zl = new ZipEightByteInteger(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1));
final byte[] result = zl.getBytes();
assertEquals(8, result.length, "length getBytes");
assertEquals((byte) 0xFE, result[0], "first byte getBytes");
@@ -86,7 +82,7 @@ public class ZipEightByteIntegerTest {
*/
@Test
public void testLongFromBytes() {
- final byte[] val = {0x78, 0x56, 0x34, 0x12, (byte) 0xAB, 0x00, 0x00, 0x00};
+ final byte[] val = { 0x78, 0x56, 0x34, 0x12, (byte) 0xAB, 0x00, 0x00, 0x00 };
final ZipEightByteInteger zl = new ZipEightByteInteger(val);
assertEquals(0xAB12345678L, zl.getLongValue(), "longValue from bytes");
}
@@ -114,8 +110,8 @@ public class ZipEightByteIntegerTest {
*/
@Test
public void testSign() {
- final ZipEightByteInteger zl = new ZipEightByteInteger(new byte[] {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF});
- assertEquals(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1).setBit(0),
- zl.getValue());
+ final ZipEightByteInteger zl = new ZipEightByteInteger(
+ new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF });
+ assertEquals(BigInteger.valueOf(Long.MAX_VALUE).shiftLeft(1).setBit(0), zl.getValue());
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEncodingTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEncodingTest.java
index df1156a2a..a4697ce1f 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEncodingTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEncodingTest.java
@@ -41,11 +41,9 @@ public class ZipEncodingTest {
private static final String UNENC_STRING = "\u2016";
// stress test for internal grow method.
- private static final String BAD_STRING =
- "\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016";
+ private static final String BAD_STRING = "\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016";
- private static final String BAD_STRING_ENC =
- "%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016";
+ private static final String BAD_STRING_ENC = "%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016";
private static void assertEquals(final byte[] expected, final ByteBuffer actual) {
@@ -67,8 +65,7 @@ public class ZipEncodingTest {
doSimpleEncodingTest("ibm" + n, null);
}
- private void doSimpleEncodingTest(final String name, byte[] testBytes)
- throws IOException {
+ private void doSimpleEncodingTest(final String name, byte[] testBytes) throws IOException {
final ZipEncoding enc = ZipEncodingHelper.getZipEncoding(name);
assertThat(enc, IsInstanceOf.instanceOf(NioZipEncoding.class));
@@ -112,66 +109,34 @@ public class ZipEncodingTest {
@Test
public void testIsUTF8() {
- assertTrue(ZipEncodingHelper.isUTF8(CharsetNames.UTF_8));
- assertTrue(ZipEncodingHelper.isUTF8("UTF8"));
- Assertions.assertEquals(Charset.defaultCharset().name().equals(CharsetNames.UTF_8), ZipEncodingHelper.isUTF8(null));
+ assertTrue(ZipEncodingHelper.isUTF8(CharsetNames.UTF_8));
+ assertTrue(ZipEncodingHelper.isUTF8("UTF8"));
+ Assertions.assertEquals(Charset.defaultCharset().name().equals(CharsetNames.UTF_8), ZipEncodingHelper.isUTF8(null));
}
-
@Test
public void testNioCp1252Encoding() throws IOException {
// CP1252 has some undefined code points, these are
// the defined ones
// retrieved by
- // awk '/^0x/ && NF>2 {print $1;}' CP1252.TXT
- final byte[] b =
- { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
- 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
- 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
- 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
- 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
- 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
- 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
- 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
- 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
- (byte) 0x80, (byte) 0x82, (byte) 0x83, (byte) 0x84,
- (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88,
- (byte) 0x89, (byte) 0x8A, (byte) 0x8B, (byte) 0x8C,
- (byte) 0x8E, (byte) 0x91, (byte) 0x92, (byte) 0x93,
- (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97,
- (byte) 0x98, (byte) 0x99, (byte) 0x9A, (byte) 0x9B,
- (byte) 0x9C, (byte) 0x9E, (byte) 0x9F, (byte) 0xA0,
- (byte) 0xA1, (byte) 0xA2, (byte) 0xA3, (byte) 0xA4,
- (byte) 0xA5, (byte) 0xA6, (byte) 0xA7, (byte) 0xA8,
- (byte) 0xA9, (byte) 0xAA, (byte) 0xAB, (byte) 0xAC,
- (byte) 0xAD, (byte) 0xAE, (byte) 0xAF, (byte) 0xB0,
- (byte) 0xB1, (byte) 0xB2, (byte) 0xB3, (byte) 0xB4,
- (byte) 0xB5, (byte) 0xB6, (byte) 0xB7, (byte) 0xB8,
- (byte) 0xB9, (byte) 0xBA, (byte) 0xBB, (byte) 0xBC,
- (byte) 0xBD, (byte) 0xBE, (byte) 0xBF, (byte) 0xC0,
- (byte) 0xC1, (byte) 0xC2, (byte) 0xC3, (byte) 0xC4,
- (byte) 0xC5, (byte) 0xC6, (byte) 0xC7, (byte) 0xC8,
- (byte) 0xC9, (byte) 0xCA, (byte) 0xCB, (byte) 0xCC,
- (byte) 0xCD, (byte) 0xCE, (byte) 0xCF, (byte) 0xD0,
- (byte) 0xD1, (byte) 0xD2, (byte) 0xD3, (byte) 0xD4,
- (byte) 0xD5, (byte) 0xD6, (byte) 0xD7, (byte) 0xD8,
- (byte) 0xD9, (byte) 0xDA, (byte) 0xDB, (byte) 0xDC,
- (byte) 0xDD, (byte) 0xDE, (byte) 0xDF, (byte) 0xE0,
- (byte) 0xE1, (byte) 0xE2, (byte) 0xE3, (byte) 0xE4,
- (byte) 0xE5, (byte) 0xE6, (byte) 0xE7, (byte) 0xE8,
- (byte) 0xE9, (byte) 0xEA, (byte) 0xEB, (byte) 0xEC,
- (byte) 0xED, (byte) 0xEE, (byte) 0xEF, (byte) 0xF0,
- (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4,
- (byte) 0xF5, (byte) 0xF6, (byte) 0xF7, (byte) 0xF8,
- (byte) 0xF9, (byte) 0xFA, (byte) 0xFB, (byte) 0xFC,
- (byte) 0xFD, (byte) 0xFE, (byte) 0xFF };
+ // awk '/^0x/ && NF>2 {print $1;}' CP1252.TXT
+ final byte[] b = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
+ 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
+ 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
+ 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D,
+ 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,
+ 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, (byte) 0x80, (byte) 0x82, (byte) 0x83, (byte) 0x84, (byte) 0x85, (byte) 0x86,
+ (byte) 0x87, (byte) 0x88, (byte) 0x89, (byte) 0x8A, (byte) 0x8B, (byte) 0x8C, (byte) 0x8E, (byte) 0x91, (byte) 0x92, (byte) 0x93, (byte) 0x94,
+ (byte) 0x95, (byte) 0x96, (byte) 0x97, (byte) 0x98, (byte) 0x99, (byte) 0x9A, (byte) 0x9B, (byte) 0x9C, (byte) 0x9E, (byte) 0x9F, (byte) 0xA0,
+ (byte) 0xA1, (byte) 0xA2, (byte) 0xA3, (byte) 0xA4, (byte) 0xA5, (byte) 0xA6, (byte) 0xA7, (byte) 0xA8, (byte) 0xA9, (byte) 0xAA, (byte) 0xAB,
+ (byte) 0xAC, (byte) 0xAD, (byte) 0xAE, (byte) 0xAF, (byte) 0xB0, (byte) 0xB1, (byte) 0xB2, (byte) 0xB3, (byte) 0xB4, (byte) 0xB5, (byte) 0xB6,
+ (byte) 0xB7, (byte) 0xB8, (byte) 0xB9, (byte) 0xBA, (byte) 0xBB, (byte) 0xBC, (byte) 0xBD, (byte) 0xBE, (byte) 0xBF, (byte) 0xC0, (byte) 0xC1,
+ (byte) 0xC2, (byte) 0xC3, (byte) 0xC4, (byte) 0xC5, (byte) 0xC6, (byte) 0xC7, (byte) 0xC8, (byte) 0xC9, (byte) 0xCA, (byte) 0xCB, (byte) 0xCC,
+ (byte) 0xCD, (byte) 0xCE, (byte) 0xCF, (byte) 0xD0, (byte) 0xD1, (byte) 0xD2, (byte) 0xD3, (byte) 0xD4, (byte) 0xD5, (byte) 0xD6, (byte) 0xD7,
+ (byte) 0xD8, (byte) 0xD9, (byte) 0xDA, (byte) 0xDB, (byte) 0xDC, (byte) 0xDD, (byte) 0xDE, (byte) 0xDF, (byte) 0xE0, (byte) 0xE1, (byte) 0xE2,
+ (byte) 0xE3, (byte) 0xE4, (byte) 0xE5, (byte) 0xE6, (byte) 0xE7, (byte) 0xE8, (byte) 0xE9, (byte) 0xEA, (byte) 0xEB, (byte) 0xEC, (byte) 0xED,
+ (byte) 0xEE, (byte) 0xEF, (byte) 0xF0, (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4, (byte) 0xF5, (byte) 0xF6, (byte) 0xF7, (byte) 0xF8,
+ (byte) 0xF9, (byte) 0xFA, (byte) 0xFB, (byte) 0xFC, (byte) 0xFD, (byte) 0xFE, (byte) 0xFF };
doSimpleEncodingTest("Cp1252", b);
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileIgnoringLocalFileHeaderTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileIgnoringLocalFileHeaderTest.java
index d567e91f6..84fb8d885 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileIgnoringLocalFileHeaderTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileIgnoringLocalFileHeaderTest.java
@@ -42,7 +42,7 @@ public class ZipFileIgnoringLocalFileHeaderTest {
@Test
public void testDuplicateEntry() throws Exception {
- try (final ZipFile zf = openZipWithoutLFH("COMPRESS-227.zip")) {
+ try (ZipFile zf = openZipWithoutLFH("COMPRESS-227.zip")) {
int numberOfEntries = 0;
for (final ZipArchiveEntry entry : zf.getEntries("test1.txt")) {
numberOfEntries++;
@@ -56,7 +56,7 @@ public class ZipFileIgnoringLocalFileHeaderTest {
@Test
public void testGetEntryWorks() throws IOException {
- try (final ZipFile zf = openZipWithoutLFH("bla.zip")) {
+ try (ZipFile zf = openZipWithoutLFH("bla.zip")) {
final ZipArchiveEntry ze = zf.getEntry("test1.xml");
assertEquals(610, ze.getSize());
}
@@ -64,7 +64,7 @@ public class ZipFileIgnoringLocalFileHeaderTest {
@Test
public void testGetRawInputStreamReturnsNotNull() throws IOException {
- try (final ZipFile zf = openZipWithoutLFH("bla.zip")) {
+ try (ZipFile zf = openZipWithoutLFH("bla.zip")) {
final ZipArchiveEntry ze = zf.getEntry("test1.xml");
try (InputStream rawInputStream = zf.getRawInputStream(ze)) {
assertNotNull(rawInputStream);
@@ -74,7 +74,7 @@ public class ZipFileIgnoringLocalFileHeaderTest {
@Test
public void testPhysicalOrder() throws IOException {
- try (final ZipFile zf = openZipWithoutLFH("ordertest.zip")) {
+ try (ZipFile zf = openZipWithoutLFH("ordertest.zip")) {
final Enumeration<ZipArchiveEntry> e = zf.getEntriesInPhysicalOrder();
ZipArchiveEntry ze;
do {
@@ -86,11 +86,12 @@ public class ZipFileIgnoringLocalFileHeaderTest {
/**
* Simple unarchive test. Asserts nothing.
+ *
* @throws Exception
*/
@Test
public void testZipUnarchive() throws Exception {
- try (final ZipFile zf = openZipWithoutLFH("bla.zip")) {
+ try (ZipFile zf = openZipWithoutLFH("bla.zip")) {
for (final Enumeration<ZipArchiveEntry> e = zf.getEntries(); e.hasMoreElements();) {
final ZipArchiveEntry entry = e.nextElement();
try (InputStream inputStream = zf.getInputStream(entry)) {
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
index 5a7cd66f3..85fd1af44 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
@@ -142,8 +142,8 @@ public class ZipFileTest extends AbstractTest {
private void assertFileEqualsToEntry(final File fileToCompare, final ZipArchiveEntry entry, final ZipFile zipFile) throws IOException {
final byte[] buffer = new byte[10240];
final File tempFile = createTempFile("temp", "txt");
- try (final OutputStream outputStream = Files.newOutputStream(tempFile.toPath());
- final InputStream inputStream = zipFile.getInputStream(entry)) {
+ try (OutputStream outputStream = Files.newOutputStream(tempFile.toPath());
+ InputStream inputStream = zipFile.getInputStream(entry)) {
int readLen;
while ((readLen = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, readLen);
@@ -280,7 +280,7 @@ public class ZipFileTest extends AbstractTest {
final Map<String, byte[]> content = new HashMap<>();
for (final ZipArchiveEntry entry : Collections.list(zf.getEntries())) {
- try (final InputStream inputStream = zf.getInputStream(entry)) {
+ try (InputStream inputStream = zf.getInputStream(entry)) {
content.put(entry.getName(), IOUtils.toByteArray(inputStream));
}
}
@@ -308,7 +308,7 @@ public class ZipFileTest extends AbstractTest {
try (InputStream fis = newInputStream("mixed.zip")) {
data = IOUtils.toByteArray(fis);
}
- try (final SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(data)) {
+ try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(data)) {
zf = new ZipFile(channel, CharsetNames.UTF_8);
final Map<String, byte[]> content = new HashMap<>();
@@ -525,7 +525,7 @@ public class ZipFileTest extends AbstractTest {
@Test
public void testExtractFileLiesAcrossSplitZipSegmentsCreatedByWinrar() throws Exception {
final File lastFile = getFile("COMPRESS-477/split_zip_created_by_winrar/split_zip_created_by_winrar.zip");
- try (final SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile)) {
+ try (SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile)) {
zf = new ZipFile(channel);
// the compressed content of ZipArchiveInputStream.java lies between .z01 and .z02
@@ -538,7 +538,7 @@ public class ZipFileTest extends AbstractTest {
@Test
public void testExtractFileLiesAcrossSplitZipSegmentsCreatedByZip() throws Exception {
final File lastFile = getFile("COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip.zip");
- try (final SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile)) {
+ try (SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile)) {
zf = new ZipFile(channel);
// the compressed content of UnsupportedCompressionAlgorithmException.java lies between .z01 and .z02
@@ -557,7 +557,7 @@ public class ZipFileTest extends AbstractTest {
@Test
public void testExtractFileLiesAcrossSplitZipSegmentsCreatedByZipOfZip64() throws Exception {
final File lastFile = getFile("COMPRESS-477/split_zip_created_by_zip/split_zip_created_by_zip_zip64.zip");
- try (final SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile)) {
+ try (SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile)) {
zf = new ZipFile(channel);
// the compressed content of UnsupportedCompressionAlgorithmException.java lies between .z01 and .z02
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
index 04c61e697..f991f36c8 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipLongTest.java
@@ -62,7 +62,7 @@ public class ZipLongTest {
*/
@Test
public void testFromBytes() {
- final byte[] val = {0x78, 0x56, 0x34, 0x12};
+ final byte[] val = { 0x78, 0x56, 0x34, 0x12 };
final ZipLong zl = new ZipLong(val);
assertEquals(0x12345678, zl.getValue(), "value from bytes");
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipMemoryFileSystemTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipMemoryFileSystemTest.java
index bb6d9eddd..c561e5047 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipMemoryFileSystemTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipMemoryFileSystemTest.java
@@ -83,7 +83,7 @@ public class ZipMemoryFileSystemTest {
walk.sorted(Comparator.reverseOrder()).peek(path -> println("Deleting: " + path.toAbsolutePath())).forEach(path -> {
try {
Files.deleteIfExists(path);
- } catch (final IOException ignore) {
+ } catch (IOException ignore) {
}
});
}
@@ -213,8 +213,7 @@ public class ZipMemoryFileSystemTest {
}
}
- try (final ZipFile zf = new ZipFile(Files.newByteChannel(target, StandardOpenOption.READ), target.getFileName().toString(), CharsetNames.UTF_8,
- true)) {
+ try (ZipFile zf = new ZipFile(Files.newByteChannel(target, StandardOpenOption.READ), target.getFileName().toString(), CharsetNames.UTF_8, true)) {
final ZipArchiveEntry b_entry = zf.getEntries("b.txt").iterator().next();
assertEquals(8, b_entry.getSize());
try (InputStream inputStream = zf.getInputStream(b_entry)) {
@@ -295,7 +294,7 @@ public class ZipMemoryFileSystemTest {
}
}
- try (final ZipFile zf = new ZipFile(target)) {
+ try (ZipFile zf = new ZipFile(target)) {
final ZipArchiveEntry b_entry = zf.getEntries("b.txt").iterator().next();
assertEquals(8, b_entry.getSize());
try (InputStream inputStream = zf.getInputStream(b_entry)) {
@@ -320,7 +319,7 @@ public class ZipMemoryFileSystemTest {
Files.write(textFileInMemSys, bytes);
final Path zipInLocalSys = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
- try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys.toFile())) {
+ try (ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys.toFile())) {
final ZipArchiveEntry entry = new ZipArchiveEntry(textFileInMemSys, textFileInMemSys.getFileName().toString());
entry.setSize(Files.size(textFileInMemSys));
zipOut.putArchiveEntry(entry);
@@ -340,8 +339,8 @@ public class ZipMemoryFileSystemTest {
Files.write(p, "Test".getBytes(UTF_8));
final Path f = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
- try (final OutputStream out = Files.newOutputStream(f);
- final ArchiveOutputStream<ZipArchiveEntry> zipOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.ZIP, out)) {
+ try (OutputStream out = Files.newOutputStream(f);
+ ArchiveOutputStream<ZipArchiveEntry> zipOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.ZIP, out)) {
final ZipArchiveEntry entry = new ZipArchiveEntry(p, p.getFileName().toString());
entry.setSize(Files.size(p));
zipOut.putArchiveEntry(entry);
@@ -362,7 +361,7 @@ public class ZipMemoryFileSystemTest {
Files.write(textFileInMemSys, bytes);
final Path zipInLocalSys = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
- try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys)) {
+ try (ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys)) {
final ZipArchiveEntry entry = new ZipArchiveEntry(textFileInMemSys, textFileInMemSys.getFileName().toString());
entry.setSize(Files.size(textFileInMemSys));
zipOut.putArchiveEntry(entry);
@@ -384,9 +383,9 @@ public class ZipMemoryFileSystemTest {
Files.write(textFileInMemSys, bytes);
final Path zipInLocalSys = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
- try (final SeekableByteChannel byteChannel = Files.newByteChannel(zipInLocalSys,
+ try (SeekableByteChannel byteChannel = Files.newByteChannel(zipInLocalSys,
EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING));
- final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(byteChannel)) {
+ ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(byteChannel)) {
final ZipArchiveEntry entry = new ZipArchiveEntry(textFileInMemSys, textFileInMemSys.getFileName().toString());
entry.setSize(Files.size(textFileInMemSys));
zipOut.putArchiveEntry(entry);
@@ -408,7 +407,7 @@ public class ZipMemoryFileSystemTest {
Files.write(textFileInMemSys, bytes);
final Path zipInLocalSys = Files.createTempFile(dir, "commons-compress-memoryfs", ".zip");
- try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys.toFile(), 64 * 1024L)) {
+ try (ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInLocalSys.toFile(), 64 * 1024L)) {
final ZipArchiveEntry entry = new ZipArchiveEntry(textFileInMemSys, textFileInMemSys.getFileName().toString());
entry.setSize(Files.size(textFileInMemSys));
zipOut.putArchiveEntry(entry);
@@ -432,8 +431,8 @@ public class ZipMemoryFileSystemTest {
try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) {
final Path p = fileSystem.getPath("target.zip");
- try (final OutputStream out = Files.newOutputStream(p);
- final ArchiveOutputStream<ZipArchiveEntry> zipOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.ZIP, out)) {
+ try (OutputStream out = Files.newOutputStream(p);
+ ArchiveOutputStream<ZipArchiveEntry> zipOut = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream(ArchiveStreamFactory.ZIP, out)) {
final String content = "Test";
final ZipArchiveEntry entry = new ZipArchiveEntry("test.txt");
entry.setSize(content.length());
@@ -453,7 +452,7 @@ public class ZipMemoryFileSystemTest {
try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) {
final Path zipInMemSys = fileSystem.getPath("target.zip");
- try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInMemSys)) {
+ try (ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInMemSys)) {
final String content = "Test";
final ZipArchiveEntry entry = new ZipArchiveEntry("test.txt");
entry.setSize(content.length());
@@ -473,9 +472,9 @@ public class ZipMemoryFileSystemTest {
try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) {
final Path zipInMemSys = fileSystem.getPath("target.zip");
- try (final SeekableByteChannel byteChannel = Files.newByteChannel(zipInMemSys,
+ try (SeekableByteChannel byteChannel = Files.newByteChannel(zipInMemSys,
EnumSet.of(StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE_NEW));
- final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(byteChannel)) {
+ ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(byteChannel)) {
final String content = "Test";
final ZipArchiveEntry entry = new ZipArchiveEntry("test.txt");
entry.setSize(content.length());
@@ -497,7 +496,7 @@ public class ZipMemoryFileSystemTest {
final byte[] bytes = new byte[100 * 1024];
SecureRandom.getInstanceStrong().nextBytes(bytes);
- try (final ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInMemSys, 64 * 1024L)) {
+ try (ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(zipInMemSys, 64 * 1024L)) {
final ZipArchiveEntry entry = new ZipArchiveEntry("test.txt");
entry.setSize(bytes.length);
zipOut.putArchiveEntry(entry);
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipShortTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipShortTest.java
index 2fe9a9abe..d291705f7 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipShortTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipShortTest.java
@@ -37,7 +37,6 @@ public class ZipShortTest {
assertEquals(s1.getValue(), s2.getValue());
}
-
/**
* Test the contract of the equals method.
*/
@@ -58,13 +57,12 @@ public class ZipShortTest {
assertNotEquals(zs, Integer.valueOf(0x1234), "non ZipShort handling");
}
-
/**
* Test conversion from bytes.
*/
@Test
public void testFromBytes() {
- final byte[] val = {0x34, 0x12};
+ final byte[] val = { 0x34, 0x12 };
final ZipShort zs = new ZipShort(val);
assertEquals(0x1234, zs.getValue(), "value from bytes");
}
@@ -85,7 +83,7 @@ public class ZipShortTest {
*/
@Test
public void testSign() {
- final ZipShort zs = new ZipShort(new byte[] {(byte) 0xFF, (byte) 0xFF});
+ final ZipShort zs = new ZipShort(new byte[] { (byte) 0xFF, (byte) 0xFF });
assertEquals(0x0000FFFF, zs.getValue());
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java
index e59c9a1bf..2a521f7f2 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java
@@ -36,14 +36,7 @@ import org.junit.jupiter.api.Test;
public class ZipUtilTest {
- static void assertDosDate(
- final long value,
- final int year,
- final int month,
- final int day,
- final int hour,
- final int minute,
- final int second) {
+ static void assertDosDate(final long value, final int year, final int month, final int day, final int hour, final int minute, final int second) {
int pos = 0;
assertEquals(year - 1980, (int) (value << pos) >>> 32 - 7);
assertEquals(month, (int) (value << (pos += 7)) >>> 32 - 4);
@@ -52,6 +45,7 @@ public class ZipUtilTest {
assertEquals(minute, (int) (value << (pos += 5)) >>> 32 - 6);
assertEquals(second, (int) (value << pos + 6) >>> 32 - 5 << 1); // DOS dates only store even seconds
}
+
static Instant toLocalInstant(final String date) {
return LocalDateTime.parse(date).atZone(ZoneId.systemDefault()).toInstant();
}
@@ -86,12 +80,9 @@ public class ZipUtilTest {
@Test
public void testAdjustToLong() {
- assertEquals(Integer.MAX_VALUE,
- ZipUtil.adjustToLong(Integer.MAX_VALUE));
- assertEquals((long) Integer.MAX_VALUE + 1,
- ZipUtil.adjustToLong(Integer.MAX_VALUE + 1));
- assertEquals(2 * (long) Integer.MAX_VALUE,
- ZipUtil.adjustToLong(2 * Integer.MAX_VALUE));
+ assertEquals(Integer.MAX_VALUE, ZipUtil.adjustToLong(Integer.MAX_VALUE));
+ assertEquals((long) Integer.MAX_VALUE + 1, ZipUtil.adjustToLong(Integer.MAX_VALUE + 1));
+ assertEquals(2 * (long) Integer.MAX_VALUE, ZipUtil.adjustToLong(2 * Integer.MAX_VALUE));
}
@Test
@@ -105,8 +96,7 @@ public class ZipUtilTest {
assertEquals(Long.MIN_VALUE, ZipUtil.bigToLong(big3));
final BigInteger big4 = big2.add(big1);
- assertThrows(IllegalArgumentException.class, () -> ZipUtil.bigToLong(big4),
- "Should have thrown IllegalArgumentException");
+ assertThrows(IllegalArgumentException.class, () -> ZipUtil.bigToLong(big4), "Should have thrown IllegalArgumentException");
final BigInteger big5 = big3.subtract(big1);
assertThrows(IllegalArgumentException.class, () -> ZipUtil.bigToLong(big5),
@@ -134,7 +124,7 @@ public class ZipUtilTest {
}
@Test
- public void testInsideCalendar(){
+ public void testInsideCalendar() {
final long date = toLocalInstant("1985-02-01T09:00:00").toEpochMilli();
final byte[] b1 = ZipUtil.toDosTime(date);
assertEquals(0, b1[0]);
@@ -142,29 +132,30 @@ public class ZipUtilTest {
assertEquals(65, b1[2]);
assertEquals(10, b1[3]);
}
+
@Test
- public void testInsideCalendar_bigValue(){
+ public void testInsideCalendar_bigValue() {
final long date = toLocalInstant("2097-11-27T23:59:59").toEpochMilli();
final long value = ZipLong.getValue(ZipUtil.toDosTime(date));
assertDosDate(value, 2097, 11, 27, 23, 59, 58); // DOS dates only store even seconds
}
@Test
- public void testInsideCalendar_long(){
+ public void testInsideCalendar_long() {
final long date = toLocalInstant("1985-02-01T09:00:00").toEpochMilli();
final long value = ZipLong.getValue(ZipUtil.toDosTime(date));
assertDosDate(value, 1985, 2, 1, 9, 0, 0);
}
@Test
- public void testInsideCalendar_modernDate(){
+ public void testInsideCalendar_modernDate() {
final long date = toLocalInstant("2022-12-27T16:18:23").toEpochMilli();
final long value = ZipLong.getValue(ZipUtil.toDosTime(date));
assertDosDate(value, 2022, 12, 27, 16, 18, 22); // DOS dates only store even seconds
}
@Test
- public void testIsDosTime(){
+ public void testIsDosTime() {
assertFalse(ZipUtil.isDosTime(toLocalInstant("1975-01-31T23:00:00").toEpochMilli()));
assertTrue(ZipUtil.isDosTime(toLocalInstant("1980-01-03T00:00:00").toEpochMilli()));
assertTrue(ZipUtil.isDosTime(toLocalInstant("2097-11-27T00:00:00").toEpochMilli()));
@@ -192,8 +183,7 @@ public class ZipUtilTest {
assertEquals(0x80000000L, big3.longValue());
assertEquals(Long.MAX_VALUE, big4.longValue());
- assertThrows(IllegalArgumentException.class, () -> ZipUtil.longToBig(l5),
- "ZipUtil.longToBig(long) should have thrown IllegalArgumentException");
+ assertThrows(IllegalArgumentException.class, () -> ZipUtil.longToBig(l5), "ZipUtil.longToBig(long) should have thrown IllegalArgumentException");
}
@Test
@@ -206,7 +196,7 @@ public class ZipUtilTest {
}
@Test
- public void testOutsideCalendar(){
+ public void testOutsideCalendar() {
final long date = toLocalInstant("1975-01-31T23:00:00").toEpochMilli();
final byte[] b1 = ZipUtil.toDosTime(date);
assertEquals(0, b1[0]);
@@ -216,7 +206,7 @@ public class ZipUtilTest {
}
@Test
- public void testOutsideCalendar_long(){
+ public void testOutsideCalendar_long() {
final long date = toLocalInstant("1975-01-31T23:00:00").toEpochMilli();
final long value = ZipLong.getValue(ZipUtil.toDosTime(date));
assertDosDate(value, 1980, 1, 1, 0, 0, 0);
@@ -225,20 +215,20 @@ public class ZipUtilTest {
@Test
public void testReverse() {
final byte[][] bTest = new byte[6][];
- bTest[0] = new byte[]{};
- bTest[1] = new byte[]{1};
- bTest[2] = new byte[]{1, 2};
- bTest[3] = new byte[]{1, 2, 3};
- bTest[4] = new byte[]{1, 2, 3, 4};
- bTest[5] = new byte[]{1, 2, 3, 4, 5};
+ bTest[0] = new byte[] {};
+ bTest[1] = new byte[] { 1 };
+ bTest[2] = new byte[] { 1, 2 };
+ bTest[3] = new byte[] { 1, 2, 3 };
+ bTest[4] = new byte[] { 1, 2, 3, 4 };
+ bTest[5] = new byte[] { 1, 2, 3, 4, 5 };
final byte[][] rTest = new byte[6][];
- rTest[0] = new byte[]{};
- rTest[1] = new byte[]{1};
- rTest[2] = new byte[]{2, 1};
- rTest[3] = new byte[]{3, 2, 1};
- rTest[4] = new byte[]{4, 3, 2, 1};
- rTest[5] = new byte[]{5, 4, 3, 2, 1};
+ rTest[0] = new byte[] {};
+ rTest[1] = new byte[] { 1 };
+ rTest[2] = new byte[] { 2, 1 };
+ rTest[3] = new byte[] { 3, 2, 1 };
+ rTest[4] = new byte[] { 4, 3, 2, 1 };
+ rTest[5] = new byte[] { 5, 4, 3, 2, 1 };
assertEquals(bTest.length, rTest.length, "test and result arrays are same length");
diff --git a/src/test/java/org/apache/commons/compress/changes/ChangeSetRawTypesTest.java b/src/test/java/org/apache/commons/compress/changes/ChangeSetRawTypesTest.java
index 6a6a76936..daf7a83e7 100644
--- a/src/test/java/org/apache/commons/compress/changes/ChangeSetRawTypesTest.java
+++ b/src/test/java/org/apache/commons/compress/changes/ChangeSetRawTypesTest.java
@@ -108,7 +108,7 @@ public final class ChangeSetRawTypesTest extends AbstractTest {
public void testAddAlreadyExistingWithReplaceTrue(final String archiverName) throws Exception {
final Path inputPath = createArchive(archiverName);
final Path result = Files.createTempFile("test", "." + archiverName);
- try (final InputStream inputStream = Files.newInputStream(inputPath);
+ try (InputStream inputStream = Files.newInputStream(inputPath);
ArchiveInputStream archiveInputStream = factory.createArchiveInputStream(archiverName, inputStream);
OutputStream newOutputStream = Files.newOutputStream(result);
ArchiveOutputStream archiveOutputStream = factory.createArchiveOutputStream(archiverName, newOutputStream);
@@ -515,7 +515,7 @@ public final class ChangeSetRawTypesTest extends AbstractTest {
public void testDeleteFile2(final String archiverName) throws Exception {
final Path inputPath = createArchive(archiverName);
final Path result = Files.createTempFile("test", "." + archiverName);
- try (final InputStream inputStream = Files.newInputStream(inputPath);
+ try (InputStream inputStream = Files.newInputStream(inputPath);
ArchiveInputStream archiveInputStream = factory.createArchiveInputStream(archiverName, inputStream);
OutputStream newOutputStream = Files.newOutputStream(result);
ArchiveOutputStream archiveOutputStream = factory.createArchiveOutputStream(archiverName, newOutputStream)) {
diff --git a/src/test/java/org/apache/commons/compress/changes/ChangeSetSafeTypesTest.java b/src/test/java/org/apache/commons/compress/changes/ChangeSetSafeTypesTest.java
index c93d0dfd1..2f6d847d2 100644
--- a/src/test/java/org/apache/commons/compress/changes/ChangeSetSafeTypesTest.java
+++ b/src/test/java/org/apache/commons/compress/changes/ChangeSetSafeTypesTest.java
@@ -131,7 +131,7 @@ public final class ChangeSetSafeTypesTest<I extends ArchiveInputStream<E>, O ext
final Path input = createArchive(archiverName);
final File result = createTempFile("test", "." + archiverName);
final File file1 = getFile("test.txt");
- try (final InputStream inputStream = Files.newInputStream(input);
+ try (InputStream inputStream = Files.newInputStream(input);
ZipArchiveInputStream ais = createArchiveInputStream(archiverName, inputStream);
OutputStream outputStream = Files.newOutputStream(result.toPath());
ZipArchiveOutputStream out = createArchiveOutputStream(archiverName, outputStream);
@@ -528,7 +528,7 @@ public final class ChangeSetSafeTypesTest<I extends ArchiveInputStream<E>, O ext
public void testDeleteFileCpio2(final String archiverName) throws Exception {
final Path input = createArchive(archiverName);
final File result = createTempFile("test", "." + archiverName);
- try (final InputStream inputStream = Files.newInputStream(input);
+ try (InputStream inputStream = Files.newInputStream(input);
ArchiveInputStream<E> ais = createArchiveInputStream(archiverName, inputStream);
OutputStream outputStream = Files.newOutputStream(result.toPath());
ArchiveOutputStream<E> out = createArchiveOutputStream(archiverName, outputStream)) {
diff --git a/src/test/java/org/apache/commons/compress/compressors/BZip2Test.java b/src/test/java/org/apache/commons/compress/compressors/BZip2Test.java
index bae2174c9..fa94dec2b 100644
--- a/src/test/java/org/apache/commons/compress/compressors/BZip2Test.java
+++ b/src/test/java/org/apache/commons/compress/compressors/BZip2Test.java
@@ -35,7 +35,7 @@ public final class BZip2Test extends AbstractTest {
public void testBzip2Unarchive() throws Exception {
final File input = getFile("bla.txt.bz2");
final File output = newTempFile("bla.txt");
- try (final InputStream is = Files.newInputStream(input.toPath());
+ try (InputStream is = Files.newInputStream(input.toPath());
CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is)) {
Files.copy(in, output.toPath());
}
@@ -48,7 +48,7 @@ public final class BZip2Test extends AbstractTest {
{
output = newTempFile("test.txt.bz2");
try (OutputStream out = Files.newOutputStream(output.toPath());
- final CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("bzip2", out)) {
+ CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("bzip2", out)) {
Files.copy(input.toPath(), cos);
}
}
@@ -82,8 +82,7 @@ public final class BZip2Test extends AbstractTest {
public void testConcatenatedStreamsReadFirstOnly() throws Exception {
final File input = getFile("multiple.bz2");
try (InputStream is = Files.newInputStream(input.toPath())) {
- try (CompressorInputStream in = new CompressorStreamFactory()
- .createCompressorInputStream("bzip2", is)) {
+ try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("bzip2", is)) {
assertEquals('a', in.read());
assertEquals(-1, in.read());
}
diff --git a/src/test/java/org/apache/commons/compress/compressors/CompressorServiceLoaderTest.java b/src/test/java/org/apache/commons/compress/compressors/CompressorServiceLoaderTest.java
index f33cf42d8..d839c487c 100644
--- a/src/test/java/org/apache/commons/compress/compressors/CompressorServiceLoaderTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/CompressorServiceLoaderTest.java
@@ -33,13 +33,13 @@ public class CompressorServiceLoaderTest {
@Test
public void testInputStream() {
assertThrows(InvocationConfirmationException.class,
- () -> new CompressorStreamFactory().createCompressorInputStream("TestInput1", new ByteArrayInputStream(ArrayUtils.EMPTY_BYTE_ARRAY)));
+ () -> new CompressorStreamFactory().createCompressorInputStream("TestInput1", new ByteArrayInputStream(ArrayUtils.EMPTY_BYTE_ARRAY)));
}
@Test
public void testOutputStream() {
assertThrows(InvocationConfirmationException.class,
- () -> new CompressorStreamFactory().createCompressorOutputStream("TestOutput1", new ByteArrayOutputStream()));
+ () -> new CompressorStreamFactory().createCompressorOutputStream("TestOutput1", new ByteArrayOutputStream()));
}
}
diff --git a/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java
index 3d06de378..33abf4e59 100644
--- a/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java
@@ -60,7 +60,7 @@ public class CompressorStreamFactoryRoundtripTest {
}
final ByteArrayInputStream is = new ByteArrayInputStream(compressedOs.toByteArray());
try (CompressorInputStream compressorInputStream = factory.createCompressorInputStream(compressorName, is, false);
- final ByteArrayOutputStream decompressedOs = new ByteArrayOutputStream()) {
+ ByteArrayOutputStream decompressedOs = new ByteArrayOutputStream()) {
IOUtils.copy(compressorInputStream, decompressedOs);
compressorInputStream.close();
decompressedOs.flush();
diff --git a/src/test/java/org/apache/commons/compress/compressors/DeflateTest.java b/src/test/java/org/apache/commons/compress/compressors/DeflateTest.java
index 3b094d025..fe771d89f 100644
--- a/src/test/java/org/apache/commons/compress/compressors/DeflateTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/DeflateTest.java
@@ -70,7 +70,7 @@ public final class DeflateTest extends AbstractTest {
* @throws Exception
*/
@Test
- public void testRawDeflateCreation() throws Exception {
+ public void testRawDeflateCreation() throws Exception {
final File input = getFile("test1.xml");
final File output = newTempFile("test1.xml.deflate");
try (OutputStream out = Files.newOutputStream(output.toPath())) {
diff --git a/src/test/java/org/apache/commons/compress/compressors/DetectCompressorTest.java b/src/test/java/org/apache/commons/compress/compressors/DetectCompressorTest.java
index 0adbd83e3..4fa8c2ea0 100644
--- a/src/test/java/org/apache/commons/compress/compressors/DetectCompressorTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/DetectCompressorTest.java
@@ -119,7 +119,7 @@ public final class DetectCompressorTest {
new TestData("multiple.xz", new char[] { 'a' }, factoryFalse, false),
new TestData("multiple.xz", new char[] { 'a' }, factorySetFalse, false),
new TestData("multiple.xz", new char[] { 'a' }, factory, false),
- // @formatter:off
+ // @formatter:on
};
@SuppressWarnings("resource") // Caller closes.
@@ -128,12 +128,14 @@ public final class DetectCompressorTest {
}
@SuppressWarnings("resource") // Caller closes.
- private CompressorInputStream createCompressorInputStream(final String resource, final CompressorStreamFactory factory) throws CompressorException, IOException {
+ private CompressorInputStream createCompressorInputStream(final String resource, final CompressorStreamFactory factory)
+ throws CompressorException, IOException {
return factory.createCompressorInputStream(new BufferedInputStream(Files.newInputStream(getFile(resource).toPath())));
}
@SuppressWarnings("resource") // Caller closes.
- private CompressorInputStream createCompressorInputStream(final String resource, final Set<String> compressorNames) throws CompressorException, IOException {
+ private CompressorInputStream createCompressorInputStream(final String resource, final Set<String> compressorNames)
+ throws CompressorException, IOException {
return factory.createCompressorInputStream(new BufferedInputStream(Files.newInputStream(getFile(resource).toPath())), compressorNames);
}
@@ -142,7 +144,7 @@ public final class DetectCompressorTest {
final InputStream is = new BufferedInputStream(Files.newInputStream(getFile(fileName).toPath()));
try {
return fac.createCompressorInputStream(is);
- } catch (final CompressorException e) {
+ } catch (CompressorException e) {
if (e.getCause() != null && e.getCause() instanceof Exception) {
// unwrap cause to reveal MemoryLimitException
throw (Exception) e.getCause();
@@ -320,7 +322,6 @@ public final class DetectCompressorTest {
}
}
-
@Test
public void testOverride() {
final CompressorStreamFactory fac1 = new CompressorStreamFactory();
diff --git a/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTest.java b/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTest.java
index 3d3f5983a..04e8b0100 100644
--- a/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/FramedSnappyTest.java
@@ -33,8 +33,7 @@ import org.apache.commons.compress.compressors.snappy.FramedSnappyCompressorInpu
import org.apache.commons.compress.utils.IOUtils;
import org.junit.jupiter.api.Test;
-public final class FramedSnappyTest
- extends AbstractTest {
+public final class FramedSnappyTest extends AbstractTest {
@Test
public void testDefaultExtraction() throws Exception {
@@ -43,9 +42,7 @@ public final class FramedSnappyTest
@Test
public void testDefaultExtractionViaFactory() throws Exception {
- testUnarchive(is -> new CompressorStreamFactory()
- .createCompressorInputStream(CompressorStreamFactory.SNAPPY_FRAMED,
- is));
+ testUnarchive(is -> new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.SNAPPY_FRAMED, is));
}
@Test
@@ -83,25 +80,24 @@ public final class FramedSnappyTest
final Random r = new Random();
final File input = newTempFile("bigChunkTest");
try (OutputStream fs = Files.newOutputStream(input.toPath())) {
- for (int i = 0 ; i < 1 << 17; i++) {
+ for (int i = 0; i < 1 << 17; i++) {
fs.write(r.nextInt(256));
}
}
final long start = System.currentTimeMillis();
final File outputSz = newTempFile(input.getName() + ".sz");
try (InputStream is = Files.newInputStream(input.toPath());
- OutputStream os = Files.newOutputStream(outputSz.toPath());
- CompressorOutputStream sos = new CompressorStreamFactory()
- .createCompressorOutputStream("snappy-framed", os)) {
+ OutputStream os = Files.newOutputStream(outputSz.toPath());
+ CompressorOutputStream sos = new CompressorStreamFactory().createCompressorOutputStream("snappy-framed", os)) {
final byte[] b = IOUtils.toByteArray(is);
sos.write(b[0]);
sos.write(b, 1, b.length - 1); // must be split into multiple compressed chunks
}
// System.err.println(input.getName() + " written, uncompressed bytes: " + input.length()
- // + ", compressed bytes: " + outputSz.length() + " after " + (System.currentTimeMillis() - start) + "ms");
+ // + ", compressed bytes: " + outputSz.length() + " after " + (System.currentTimeMillis() - start) + "ms");
try (InputStream is = Files.newInputStream(input.toPath());
- CompressorInputStream sis = new CompressorStreamFactory()
- .createCompressorInputStream("snappy-framed", Files.newInputStream(outputSz.toPath()))) {
+ CompressorInputStream sis = new CompressorStreamFactory().createCompressorInputStream("snappy-framed",
+ Files.newInputStream(outputSz.toPath()))) {
final byte[] expected = IOUtils.toByteArray(is);
final byte[] actual = IOUtils.toByteArray(sis);
assertArrayEquals(expected, actual);
@@ -122,8 +118,7 @@ public final class FramedSnappyTest
final File original = getFile("bla.tar");
try (InputStream written = Files.newInputStream(output.toPath())) {
try (InputStream orig = Files.newInputStream(original.toPath())) {
- assertArrayEquals(IOUtils.toByteArray(written),
- IOUtils.toByteArray(orig));
+ assertArrayEquals(IOUtils.toByteArray(written), IOUtils.toByteArray(orig));
}
}
}
diff --git a/src/test/java/org/apache/commons/compress/compressors/GZipTest.java b/src/test/java/org/apache/commons/compress/compressors/GZipTest.java
index 00f6310d4..cda460a53 100644
--- a/src/test/java/org/apache/commons/compress/compressors/GZipTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/GZipTest.java
@@ -47,8 +47,7 @@ public final class GZipTest extends AbstractTest {
public void testConcatenatedStreamsReadFirstOnly() throws Exception {
final File input = getFile("multiple.gz");
try (InputStream is = Files.newInputStream(input.toPath())) {
- try (CompressorInputStream in = new CompressorStreamFactory()
- .createCompressorInputStream("gz", is)) {
+ try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("gz", is)) {
assertEquals('a', in.read());
assertEquals(-1, in.read());
}
@@ -75,8 +74,8 @@ public final class GZipTest extends AbstractTest {
public void testCorruptedInput() throws Exception {
final byte[] data = readAllBytes("bla.tgz");
try (InputStream in = new ByteArrayInputStream(data, 0, data.length - 1);
- CompressorInputStream cin = new CompressorStreamFactory().createCompressorInputStream("gz", in);
- OutputStream out = new ByteArrayOutputStream()) {
+ CompressorInputStream cin = new CompressorStreamFactory().createCompressorInputStream("gz", in);
+ OutputStream out = new ByteArrayOutputStream()) {
assertThrows(IOException.class, () -> IOUtils.copy(cin, out), "Expected an exception");
}
}
@@ -193,19 +192,17 @@ public final class GZipTest extends AbstractTest {
}
@ParameterizedTest
- @ValueSource(ints = {0, -1})
+ @ValueSource(ints = { 0, -1 })
public void testInvalidBufferSize(final int bufferSize) {
final GzipParameters parameters = new GzipParameters();
- assertThrows(IllegalArgumentException.class, () -> parameters.setBufferSize(bufferSize),
- "IllegalArgumentException not thrown");
+ assertThrows(IllegalArgumentException.class, () -> parameters.setBufferSize(bufferSize), "IllegalArgumentException not thrown");
}
@ParameterizedTest
- @ValueSource(ints = {10, -5})
+ @ValueSource(ints = { 10, -5 })
public void testInvalidCompressionLevel(final int compressionLevel) {
final GzipParameters parameters = new GzipParameters();
- assertThrows(IllegalArgumentException.class, () -> parameters.setCompressionLevel(compressionLevel),
- "IllegalArgumentException not thrown");
+ assertThrows(IllegalArgumentException.class, () -> parameters.setCompressionLevel(compressionLevel), "IllegalArgumentException not thrown");
}
@Test
@@ -241,7 +238,7 @@ public final class GZipTest extends AbstractTest {
final File input = getFile("bla.tgz");
final byte[] buf = new byte[2];
try (InputStream is = Files.newInputStream(input.toPath());
- final GzipCompressorInputStream in = new GzipCompressorInputStream(is)) {
+ GzipCompressorInputStream in = new GzipCompressorInputStream(is)) {
IOUtils.toByteArray(in);
assertEquals(-1, in.read(buf));
assertEquals(-1, in.read(buf));
@@ -259,7 +256,7 @@ public final class GZipTest extends AbstractTest {
public void testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws IOException {
final File input = getFile("bla.tgz");
try (InputStream is = Files.newInputStream(input.toPath());
- final GzipCompressorInputStream in = new GzipCompressorInputStream(is)) {
+ GzipCompressorInputStream in = new GzipCompressorInputStream(is)) {
IOUtils.toByteArray(in);
assertEquals(-1, in.read());
assertEquals(-1, in.read());
diff --git a/src/test/java/org/apache/commons/compress/compressors/LZMATest.java b/src/test/java/org/apache/commons/compress/compressors/LZMATest.java
index 8604e9eff..98fa05d00 100644
--- a/src/test/java/org/apache/commons/compress/compressors/LZMATest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/LZMATest.java
@@ -47,7 +47,8 @@ public final class LZMATest extends AbstractTest {
}
final byte[] orig = Files.readAllBytes(input);
final byte[] uncompressed;
- try (InputStream is = Files.newInputStream(compressed.toPath()); CompressorInputStream in = new LZMACompressorInputStream(is)) {
+ try (InputStream is = Files.newInputStream(compressed.toPath());
+ CompressorInputStream in = new LZMACompressorInputStream(is)) {
uncompressed = IOUtils.toByteArray(in);
}
assertArrayEquals(orig, uncompressed);
@@ -58,7 +59,7 @@ public final class LZMATest extends AbstractTest {
final File input = getFile("bla.tar.lzma");
final File output = newTempFile("bla.tar");
try (InputStream is = Files.newInputStream(input.toPath())) {
- try (final CompressorInputStream in = new LZMACompressorInputStream(is)) {
+ try (CompressorInputStream in = new LZMACompressorInputStream(is)) {
Files.copy(in, output.toPath());
}
}
@@ -69,7 +70,7 @@ public final class LZMATest extends AbstractTest {
final File input = getFile("bla.tar.lzma");
final File output = newTempFile("bla.tar");
try (InputStream is = new BufferedInputStream(Files.newInputStream(input.toPath()))) {
- try (final CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream(is)) {
+ try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream(is)) {
Files.copy(in, output.toPath());
}
}
diff --git a/src/test/java/org/apache/commons/compress/compressors/Pack200Test.java b/src/test/java/org/apache/commons/compress/compressors/Pack200Test.java
index 167ddbac3..dca89eee7 100644
--- a/src/test/java/org/apache/commons/compress/compressors/Pack200Test.java
+++ b/src/test/java/org/apache/commons/compress/compressors/Pack200Test.java
@@ -52,7 +52,7 @@ public final class Pack200Test extends AbstractTest {
final File file2 = getFile("test2.xml");
try (OutputStream out = new Pack200CompressorOutputStream(Files.newOutputStream(output.toPath()), mode);
- JarArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("jar", out)) {
+ JarArchiveOutputStream os = ArchiveStreamFactory.DEFAULT.createArchiveOutputStream("jar", out)) {
os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
Files.copy(file1.toPath(), os);
@@ -64,7 +64,7 @@ public final class Pack200Test extends AbstractTest {
}
try (InputStream is = new Pack200CompressorInputStream(output);
- final ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+ ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
final List<String> files = new ArrayList<>();
files.add("testdata/test1.xml");
files.add("testdata/test2.xml");
@@ -72,13 +72,11 @@ public final class Pack200Test extends AbstractTest {
}
}
- private void jarUnarchiveAll(final boolean useFile, final Pack200Strategy mode)
- throws Exception {
+ private void jarUnarchiveAll(final boolean useFile, final Pack200Strategy mode) throws Exception {
final File input = getFile("bla.pack");
- try (
- InputStream is = useFile ? new Pack200CompressorInputStream(input, mode)
+ try (InputStream is = useFile ? new Pack200CompressorInputStream(input, mode)
: new Pack200CompressorInputStream(Files.newInputStream(input.toPath()), mode);
- ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
+ ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("jar", is)) {
ArchiveEntry entry = in.getNextEntry();
while (entry != null) {
@@ -98,7 +96,7 @@ public final class Pack200Test extends AbstractTest {
private void multiByteReadConsistentlyReturnsMinusOneAtEof(final Pack200Strategy s) throws Exception {
final File input = getFile("bla.pack");
final byte[] buf = new byte[2];
- try (final Pack200CompressorInputStream in = new Pack200CompressorInputStream(input, s)) {
+ try (Pack200CompressorInputStream in = new Pack200CompressorInputStream(input, s)) {
IOUtils.toByteArray(in);
assertEquals(-1, in.read(buf));
assertEquals(-1, in.read(buf));
@@ -107,7 +105,7 @@ public final class Pack200Test extends AbstractTest {
private void singleByteReadConsistentlyReturnsMinusOneAtEof(final Pack200Strategy s) throws Exception {
final File input = getFile("bla.pack");
- try (final Pack200CompressorInputStream in = new Pack200CompressorInputStream(input, s)) {
+ try (Pack200CompressorInputStream in = new Pack200CompressorInputStream(input, s)) {
IOUtils.toByteArray(in);
assertEquals(-1, in.read());
assertEquals(-1, in.read());
@@ -136,8 +134,7 @@ public final class Pack200Test extends AbstractTest {
public void testInputStreamMethods() throws Exception {
final Map<String, String> m = new HashMap<>();
m.put("foo", "bar");
- try (InputStream is = new Pack200CompressorInputStream(newInputStream("bla.jar"),
- m)) {
+ try (InputStream is = new Pack200CompressorInputStream(newInputStream("bla.jar"), m)) {
// packed file is a jar, which is a ZIP, so it starts with
// a local file header
assertTrue(is.markSupported());
@@ -201,9 +198,9 @@ public final class Pack200Test extends AbstractTest {
final Map<String, String> m = new HashMap<>();
m.put("foo", "bar");
try (OutputStream out = Files.newOutputStream(output.toPath());
- OutputStream os = new Pack200CompressorOutputStream(out, m)) {
+ OutputStream os = new Pack200CompressorOutputStream(out, m)) {
os.write(1);
- os.write(new byte[] {2, 3});
+ os.write(new byte[] { 2, 3 });
}
}
diff --git a/src/test/java/org/apache/commons/compress/compressors/TestCompressorStreamProvider.java b/src/test/java/org/apache/commons/compress/compressors/TestCompressorStreamProvider.java
index 62d72e94c..4fd0e459d 100644
--- a/src/test/java/org/apache/commons/compress/compressors/TestCompressorStreamProvider.java
+++ b/src/test/java/org/apache/commons/compress/compressors/TestCompressorStreamProvider.java
@@ -37,14 +37,13 @@ public class TestCompressorStreamProvider implements CompressorStreamProvider {
}
@Override
- public CompressorInputStream createCompressorInputStream(final String name, final InputStream in,
- final boolean decompressConcatenated) throws CompressorException {
+ public CompressorInputStream createCompressorInputStream(final String name, final InputStream in, final boolean decompressConcatenated)
+ throws CompressorException {
throw new InvocationConfirmationException(name);
}
... 4702 lines suppressed ...