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 2020/08/18 15:55:22 UTC
[commons-compress] branch master updated: Bump to Java 7 to 8 and
use lambdas.
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 c244d8e Bump to Java 7 to 8 and use lambdas.
c244d8e is described below
commit c244d8ef98990b5100b82967388ed735c8ee69d3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Aug 18 11:55:14 2020 -0400
Bump to Java 7 to 8 and use lambdas.
---
pom.xml | 4 +-
src/changes/changes.xml | 7 +-
.../compress/archivers/ArchiveStreamFactory.java | 30 +-
.../archivers/examples/CloseableConsumer.java | 12 +-
.../compress/archivers/examples/Expander.java | 60 +-
.../archivers/tar/TarArchiveInputStream.java | 11 +-
.../compressors/CompressorStreamFactory.java | 31 +-
.../lz4/BlockLZ4CompressorOutputStream.java | 25 +-
.../lz4/FramedLZ4CompressorInputStream.java | 7 +-
.../AbstractLZ77CompressorInputStream.java | 7 +-
.../snappy/FramedSnappyCompressorInputStream.java | 7 +-
.../snappy/SnappyCompressorOutputStream.java | 27 +-
.../apache/commons/compress/ArchiveReadTest.java | 8 +-
.../commons/compress/archivers/ZipTestCase.java | 7 +-
.../compress/archivers/zip/Zip64SupportIT.java | 3168 ++++++++++----------
15 files changed, 1628 insertions(+), 1783 deletions(-)
diff --git a/pom.xml b/pom.xml
index fd93f0f..e77c3a9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,8 +37,8 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
</description>
<properties>
- <maven.compiler.source>1.7</maven.compiler.source>
- <maven.compiler.target>1.7</maven.compiler.target>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
<!-- override parent as version used by parent requires Java 8 -->
<commons.felix.version>3.5.1</commons.felix.version>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 73cf48c..53db4fc 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -42,8 +42,11 @@ The <action> type attribute can be add,update,fix,remove.
<title>Apache Commons Compress Release Notes</title>
</properties>
<body>
- <release version="1.21" date="not released, yet"
+ <release version="1.21" date="not released, yet (Java 8)"
description="Release 1.21">
+ <action type="update" date="2020-08-18">
+ Update from Java 7 to 8.
+ </action>
<action type="update" date="2020-03-07"
due-to="Peter Alfred Lee">
Made sure ZstdCompressorOutputStream no longer used
@@ -192,7 +195,7 @@ The <action> type attribute can be add,update,fix,remove.
</action>
</release>
<release version="1.20" date="2020-02-08"
- description="Release 1.20">
+ description="Release 1.20 (Java 7)">
<action issue="COMPRESS-493" type="update" date="2019-08-27">
Update optional library com.github.luben:zstd-jni from 1.4.0-1 to 1.4.4-7.
</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
index b6cbae8..561834c 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
@@ -211,16 +211,13 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
* @since 1.13
*/
public static SortedMap<String, ArchiveStreamProvider> findAvailableArchiveInputStreamProviders() {
- return AccessController.doPrivileged(new PrivilegedAction<SortedMap<String, ArchiveStreamProvider>>() {
- @Override
- public SortedMap<String, ArchiveStreamProvider> run() {
- final TreeMap<String, ArchiveStreamProvider> map = new TreeMap<>();
- putAll(DEFAULT.getInputStreamArchiveNames(), DEFAULT, map);
- for (final ArchiveStreamProvider provider : findArchiveStreamProviders()) {
- putAll(provider.getInputStreamArchiveNames(), provider, map);
- }
- return map;
+ return AccessController.doPrivileged((PrivilegedAction<SortedMap<String, ArchiveStreamProvider>>) () -> {
+ final TreeMap<String, ArchiveStreamProvider> map = new TreeMap<>();
+ putAll(DEFAULT.getInputStreamArchiveNames(), DEFAULT, map);
+ for (final ArchiveStreamProvider provider : findArchiveStreamProviders()) {
+ putAll(provider.getInputStreamArchiveNames(), provider, map);
}
+ return map;
});
}
@@ -252,16 +249,13 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
* @since 1.13
*/
public static SortedMap<String, ArchiveStreamProvider> findAvailableArchiveOutputStreamProviders() {
- return AccessController.doPrivileged(new PrivilegedAction<SortedMap<String, ArchiveStreamProvider>>() {
- @Override
- public SortedMap<String, ArchiveStreamProvider> run() {
- final TreeMap<String, ArchiveStreamProvider> map = new TreeMap<>();
- putAll(DEFAULT.getOutputStreamArchiveNames(), DEFAULT, map);
- for (final ArchiveStreamProvider provider : findArchiveStreamProviders()) {
- putAll(provider.getOutputStreamArchiveNames(), provider, map);
- }
- return map;
+ return AccessController.doPrivileged((PrivilegedAction<SortedMap<String, ArchiveStreamProvider>>) () -> {
+ final TreeMap<String, ArchiveStreamProvider> map = new TreeMap<>();
+ putAll(DEFAULT.getOutputStreamArchiveNames(), DEFAULT, map);
+ for (final ArchiveStreamProvider provider : findArchiveStreamProviders()) {
+ putAll(provider.getOutputStreamArchiveNames(), provider, map);
}
+ return map;
});
}
diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/CloseableConsumer.java b/src/main/java/org/apache/commons/compress/archivers/examples/CloseableConsumer.java
index 25ce537..9a876b6 100644
--- a/src/main/java/org/apache/commons/compress/archivers/examples/CloseableConsumer.java
+++ b/src/main/java/org/apache/commons/compress/archivers/examples/CloseableConsumer.java
@@ -34,20 +34,12 @@ public interface CloseableConsumer {
/**
* Closes the passed in Closeable immediately.
*/
- CloseableConsumer CLOSING_CONSUMER = new CloseableConsumer() {
- @Override
- public void accept(final Closeable c) throws IOException {
- c.close();
- }
- };
+ CloseableConsumer CLOSING_CONSUMER = Closeable::close;
/**
* Completely ignores the passed in Closeable.
*/
- CloseableConsumer NULL_CONSUMER = new CloseableConsumer() {
- @Override
- public void accept(final Closeable c) { }
- };
+ CloseableConsumer NULL_CONSUMER = c -> { };
/**
* Callback that is informed about a closable resource that has
diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java b/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java
index 3edfa5f..ce3e086 100644
--- a/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java
+++ b/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java
@@ -258,21 +258,13 @@ public class Expander {
*/
public void expand(final ArchiveInputStream archive, final File targetDirectory)
throws IOException, ArchiveException {
- expand(new ArchiveEntrySupplier() {
- @Override
- public ArchiveEntry getNextReadableEntry() throws IOException {
- ArchiveEntry next = archive.getNextEntry();
- while (next != null && !archive.canReadEntryData(next)) {
- next = archive.getNextEntry();
- }
- return next;
- }
- }, new EntryWriter() {
- @Override
- public void writeEntryDataTo(final ArchiveEntry entry, final OutputStream out) throws IOException {
- IOUtils.copy(archive, out);
+ expand(() -> {
+ ArchiveEntry next = archive.getNextEntry();
+ while (next != null && !archive.canReadEntryData(next)) {
+ next = archive.getNextEntry();
}
- }, targetDirectory);
+ return next;
+ }, (entry, out) -> IOUtils.copy(archive, out), targetDirectory);
}
/**
@@ -286,21 +278,15 @@ public class Expander {
public void expand(final ZipFile archive, final File targetDirectory)
throws IOException, ArchiveException {
final Enumeration<ZipArchiveEntry> entries = archive.getEntries();
- expand(new ArchiveEntrySupplier() {
- @Override
- public ArchiveEntry getNextReadableEntry() throws IOException {
- ZipArchiveEntry next = entries.hasMoreElements() ? entries.nextElement() : null;
- while (next != null && !archive.canReadEntryData(next)) {
- next = entries.hasMoreElements() ? entries.nextElement() : null;
- }
- return next;
+ expand(() -> {
+ ZipArchiveEntry next = entries.hasMoreElements() ? entries.nextElement() : null;
+ while (next != null && !archive.canReadEntryData(next)) {
+ next = entries.hasMoreElements() ? entries.nextElement() : null;
}
- }, new EntryWriter() {
- @Override
- public void writeEntryDataTo(final ArchiveEntry entry, final OutputStream out) throws IOException {
- try (InputStream in = archive.getInputStream((ZipArchiveEntry) entry)) {
- IOUtils.copy(in, out);
- }
+ return next;
+ }, (entry, out) -> {
+ try (InputStream in = archive.getInputStream((ZipArchiveEntry) entry)) {
+ IOUtils.copy(in, out);
}
}, targetDirectory);
}
@@ -315,19 +301,11 @@ public class Expander {
*/
public void expand(final SevenZFile archive, final File targetDirectory)
throws IOException, ArchiveException {
- expand(new ArchiveEntrySupplier() {
- @Override
- public ArchiveEntry getNextReadableEntry() throws IOException {
- return archive.getNextEntry();
- }
- }, new EntryWriter() {
- @Override
- public void writeEntryDataTo(final ArchiveEntry entry, final OutputStream out) throws IOException {
- final byte[] buffer = new byte[8024];
- int n;
- while (-1 != (n = archive.read(buffer))) {
- out.write(buffer, 0, n);
- }
+ expand(() -> archive.getNextEntry(), (entry, out) -> {
+ final byte[] buffer = new byte[8024];
+ int n;
+ while (-1 != (n = archive.read(buffer))) {
+ out.write(buffer, 0, n);
}
}, targetDirectory);
}
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index 17275de..42aed57 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -1106,13 +1106,10 @@ public class TarArchiveInputStream extends ArchiveInputStream {
final List<TarArchiveStructSparse> sparseHeaders = currEntry.getSparseHeaders();
// sort the sparse headers in case they are written in wrong order
if (sparseHeaders != null && sparseHeaders.size() > 1) {
- final Comparator<TarArchiveStructSparse> sparseHeaderComparator = new Comparator<TarArchiveStructSparse>() {
- @Override
- public int compare(final TarArchiveStructSparse p, final TarArchiveStructSparse q) {
- final Long pOffset = p.getOffset();
- final Long qOffset = q.getOffset();
- return pOffset.compareTo(qOffset);
- }
+ final Comparator<TarArchiveStructSparse> sparseHeaderComparator = (p, q) -> {
+ final Long pOffset = p.getOffset();
+ final Long qOffset = q.getOffset();
+ return pOffset.compareTo(qOffset);
};
Collections.sort(sparseHeaders, sparseHeaderComparator);
}
diff --git a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
index 463089c..863cd8b 100644
--- a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
@@ -245,16 +245,13 @@ public class CompressorStreamFactory implements CompressorStreamProvider {
* @since 1.13
*/
public static SortedMap<String, CompressorStreamProvider> findAvailableCompressorInputStreamProviders() {
- return AccessController.doPrivileged(new PrivilegedAction<SortedMap<String, CompressorStreamProvider>>() {
- @Override
- public SortedMap<String, CompressorStreamProvider> run() {
- final TreeMap<String, CompressorStreamProvider> map = new TreeMap<>();
- putAll(SINGLETON.getInputStreamCompressorNames(), SINGLETON, map);
- for (final CompressorStreamProvider provider : findCompressorStreamProviders()) {
- putAll(provider.getInputStreamCompressorNames(), provider, map);
- }
- return map;
+ return AccessController.doPrivileged((PrivilegedAction<SortedMap<String, CompressorStreamProvider>>) () -> {
+ final TreeMap<String, CompressorStreamProvider> map = new TreeMap<>();
+ putAll(SINGLETON.getInputStreamCompressorNames(), SINGLETON, map);
+ for (final CompressorStreamProvider provider : findCompressorStreamProviders()) {
+ putAll(provider.getInputStreamCompressorNames(), provider, map);
}
+ return map;
});
}
@@ -286,17 +283,13 @@ public class CompressorStreamFactory implements CompressorStreamProvider {
* @since 1.13
*/
public static SortedMap<String, CompressorStreamProvider> findAvailableCompressorOutputStreamProviders() {
- return AccessController.doPrivileged(new PrivilegedAction<SortedMap<String, CompressorStreamProvider>>() {
- @Override
- public SortedMap<String, CompressorStreamProvider> run() {
- final TreeMap<String, CompressorStreamProvider> map = new TreeMap<>();
- putAll(SINGLETON.getOutputStreamCompressorNames(), SINGLETON, map);
- for (final CompressorStreamProvider provider : findCompressorStreamProviders()) {
- putAll(provider.getOutputStreamCompressorNames(), provider, map);
- }
- return map;
+ return AccessController.doPrivileged((PrivilegedAction<SortedMap<String, CompressorStreamProvider>>) () -> {
+ final TreeMap<String, CompressorStreamProvider> map = new TreeMap<>();
+ putAll(SINGLETON.getOutputStreamCompressorNames(), SINGLETON, map);
+ for (final CompressorStreamProvider provider : findCompressorStreamProviders()) {
+ putAll(provider.getOutputStreamCompressorNames(), provider, map);
}
-
+ return map;
});
}
private static ArrayList<CompressorStreamProvider> findCompressorStreamProviders() {
diff --git a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
index d4ba040..9397c6e 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
@@ -113,20 +113,17 @@ public class BlockLZ4CompressorOutputStream extends CompressorOutputStream {
public BlockLZ4CompressorOutputStream(final OutputStream os, final Parameters params) throws IOException {
this.os = os;
compressor = new LZ77Compressor(params,
- new LZ77Compressor.Callback() {
- @Override
- public void accept(final LZ77Compressor.Block block) throws IOException {
- switch (block.getType()) {
- case LITERAL:
- addLiteralBlock((LZ77Compressor.LiteralBlock) block);
- break;
- case BACK_REFERENCE:
- addBackReference((LZ77Compressor.BackReference) block);
- break;
- case EOD:
- writeFinalLiteralBlock();
- break;
- }
+ block -> {
+ switch (block.getType()) {
+ case LITERAL:
+ addLiteralBlock((LZ77Compressor.LiteralBlock) block);
+ break;
+ case BACK_REFERENCE:
+ addBackReference((LZ77Compressor.BackReference) block);
+ break;
+ case EOD:
+ writeFinalLiteralBlock();
+ break;
}
});
}
diff --git a/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStream.java
index 869e7ea..99ed3ca 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lz4/FramedLZ4CompressorInputStream.java
@@ -63,12 +63,7 @@ public class FramedLZ4CompressorInputStream extends CompressorInputStream
// used in no-arg read method
private final byte[] oneByte = new byte[1];
- private final ByteUtils.ByteSupplier supplier = new ByteUtils.ByteSupplier() {
- @Override
- public int getAsByte() throws IOException {
- return readOneByte();
- }
- };
+ private final ByteUtils.ByteSupplier supplier = this::readOneByte;
private final CountingInputStream inputStream;
private final boolean decompressConcatenated;
diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
index cb1c4bb..240dc11 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
@@ -114,12 +114,7 @@ public abstract class AbstractLZ77CompressorInputStream extends CompressorInputS
/**
* Supplier that delegates to {@link #readOneByte}.
*/
- protected final ByteUtils.ByteSupplier supplier = new ByteUtils.ByteSupplier() {
- @Override
- public int getAsByte() throws IOException {
- return readOneByte();
- }
- };
+ protected final ByteUtils.ByteSupplier supplier = this::readOneByte;
/**
* Creates a new LZ77 input stream.
diff --git a/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java
index c1d07b5..7f29bec 100644
--- a/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java
@@ -82,12 +82,7 @@ public class FramedSnappyCompressorInputStream extends CompressorInputStream
private final int blockSize;
private final PureJavaCrc32C checksum = new PureJavaCrc32C();
- private final ByteUtils.ByteSupplier supplier = new ByteUtils.ByteSupplier() {
- @Override
- public int getAsByte() throws IOException {
- return readOneByte();
- }
- };
+ private final ByteUtils.ByteSupplier supplier = this::readOneByte;
/**
* Constructs a new input stream that decompresses
diff --git a/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorOutputStream.java
index ac040f7..01d984d 100644
--- a/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorOutputStream.java
@@ -99,21 +99,18 @@ public class SnappyCompressorOutputStream extends CompressorOutputStream {
throws IOException {
this.os = os;
consumer = new ByteUtils.OutputStreamByteConsumer(os);
- compressor = new LZ77Compressor(params, new LZ77Compressor.Callback() {
- @Override
- public void accept(final LZ77Compressor.Block block) throws IOException {
- switch (block.getType()) {
- case LITERAL:
- writeLiteralBlock((LZ77Compressor.LiteralBlock) block);
- break;
- case BACK_REFERENCE:
- writeBackReference((LZ77Compressor.BackReference) block);
- break;
- case EOD:
- break;
- }
- }
- });
+ compressor = new LZ77Compressor(params, block -> {
+ switch (block.getType()) {
+ case LITERAL:
+ writeLiteralBlock((LZ77Compressor.LiteralBlock) block);
+ break;
+ case BACK_REFERENCE:
+ writeBackReference((LZ77Compressor.BackReference) block);
+ break;
+ case EOD:
+ break;
+ }
+ });
writeUncompressedSize(uncompressedSize);
}
diff --git a/src/test/java/org/apache/commons/compress/ArchiveReadTest.java b/src/test/java/org/apache/commons/compress/ArchiveReadTest.java
index c9cc951..bfe543f 100644
--- a/src/test/java/org/apache/commons/compress/ArchiveReadTest.java
+++ b/src/test/java/org/apache/commons/compress/ArchiveReadTest.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
-import java.io.FilenameFilter;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
@@ -85,12 +84,7 @@ public class ArchiveReadTest extends AbstractTestCase {
public static Collection<Object[]> data() {
assertTrue(ARCDIR.exists());
final Collection<Object[]> params = new ArrayList<>();
- for (final String f : ARCDIR.list(new FilenameFilter() {
- @Override
- public boolean accept(final File dir, final String name) {
- return !name.endsWith(".txt");
- }
- }))
+ for (final String f : ARCDIR.list((dir, name) -> !name.endsWith(".txt")))
{
params.add(new Object[] { f });
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
index aa2441e..6fda1ac 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java
@@ -346,12 +346,7 @@ public final class ZipTestCase extends AbstractTestCase {
}
String first_payload = "ABBA";
String second_payload = "AAAAAAAAAAAA";
- ZipArchiveEntryPredicate allFilesPredicate = new ZipArchiveEntryPredicate() {
- @Override
- public boolean test(final ZipArchiveEntry zipArchiveEntry) {
- return true;
- }
- };
+ ZipArchiveEntryPredicate allFilesPredicate = zipArchiveEntry -> true;
@Test
public void testCopyRawEntriesFromFile()
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 467f3ea..3267e8e 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
@@ -204,100 +204,96 @@ public class Zip64SupportIT {
}
private static ZipOutputTest write100KFiles(final Zip64Mode mode) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- write100KFilesToStream(zos);
- try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
- 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);
- }
- }
- };
+ return (f, zos) -> {
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
+ }
+ write100KFilesToStream(zos);
+ try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
+ 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);
+ }
+ };
}
@Test public void write100KFilesFile() throws Throwable {
@@ -319,20 +315,16 @@ public class Zip64SupportIT {
}
private static final ZipOutputTest write100KFilesModeNever =
- new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- zos.setUseZip64(Zip64Mode.Never);
- try {
- write100KFilesToStream(zos);
- fail("expected a Zip64RequiredException");
- } catch (final Zip64RequiredException ex) {
- assertEquals(Zip64RequiredException.TOO_MANY_ENTRIES_MESSAGE,
- ex.getMessage());
- }
- }
- };
+ (f, zos) -> {
+ zos.setUseZip64(Zip64Mode.Never);
+ try {
+ write100KFilesToStream(zos);
+ fail("expected a Zip64RequiredException");
+ } catch (final Zip64RequiredException ex) {
+ assertEquals(Zip64RequiredException.TOO_MANY_ENTRIES_MESSAGE,
+ ex.getMessage());
+ }
+ };
@Test public void write100KFilesFileModeNever() throws Throwable {
withTemporaryArchive("write100KFilesFileModeNever",
@@ -347,15 +339,10 @@ public class Zip64SupportIT {
@Test public void readSelfGenerated100KFilesUsingZipFile()
throws Throwable {
withTemporaryArchive("readSelfGenerated100KFilesUsingZipFile()",
- new ZipOutputTest() {
- @Override
- public void test(final File f,
- final ZipArchiveOutputStream zos)
- throws IOException {
- write100KFilesToStream(zos);
- read100KFilesUsingZipFileImpl(f);
- }
- },
+ (f, zos) -> {
+ write100KFilesToStream(zos);
+ read100KFilesUsingZipFileImpl(f);
+ },
true);
}
@@ -376,113 +363,109 @@ public class Zip64SupportIT {
*/
private static ZipOutputTest
write3EntriesCreatingBigArchive(final Zip64Mode mode, final boolean isSplitArchive) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- write3EntriesCreatingBigArchiveToStream(zos);
-
- try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
- 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("CDH start", 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);
- // ignore timestamp, CRC, compressed size
- a.skipBytes(12);
- // Original Size
- final byte[] originalSize = new byte[4];
- a.readFully(originalSize);
- if (mode == Zip64Mode.Always) {
- assertArrayEquals("CDH original size", new byte[] {
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- }, originalSize);
- } else {
- assertArrayEquals("CDH original size", new byte[] {
- 1, 0, 0, 0
- }, originalSize);
- }
- final byte[] rest = new byte[19];
- a.readFully(rest);
- assertArrayEquals("CDH rest", 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);
- if (mode == Zip64Mode.Always) {
- final byte[] extra = new byte[12];
- a.readFully(extra);
- assertArrayEquals("CDH extra", new byte[] {
- // Header-ID
- 1, 0,
- // size
- 28, 0,
- // Original Size
- 1, 0, 0, 0, 0, 0, 0, 0,
- }, extra);
- // skip compressed size
- a.skipBytes(8);
- } else {
- final byte[] extra = new byte[4];
- a.readFully(extra);
- assertArrayEquals("CDH extra", new byte[] {
- // Header-ID
- 1, 0,
- // size
- 8, 0,
- }, extra);
- }
-
- // read offset of LFH
- final byte[] offset = new byte[8];
- a.readFully(offset);
- // verify there is a LFH where the CD claims it
- a.seek(ZipEightByteInteger.getLongValue(offset));
- final byte[] sig = new byte[4];
- a.readFully(sig);
- assertArrayEquals("LFH signature", new byte[] {
- (byte) 0x50, (byte) 0x4b, 3, 4,
- }, sig);
- }
+ return (f, zos) -> {
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
+ }
+ write3EntriesCreatingBigArchiveToStream(zos);
+
+ try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
+ 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("CDH start", 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);
+ // ignore timestamp, CRC, compressed size
+ a.skipBytes(12);
+ // Original Size
+ final byte[] originalSize = new byte[4];
+ a.readFully(originalSize);
+ if (mode == Zip64Mode.Always) {
+ assertArrayEquals("CDH original size", new byte[] {
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ }, originalSize);
+ } else {
+ assertArrayEquals("CDH original size", new byte[] {
+ 1, 0, 0, 0
+ }, originalSize);
+ }
+ final byte[] rest = new byte[19];
+ a.readFully(rest);
+ assertArrayEquals("CDH rest", 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);
+ if (mode == Zip64Mode.Always) {
+ final byte[] extra1 = new byte[12];
+ a.readFully(extra1);
+ assertArrayEquals("CDH extra", new byte[] {
+ // Header-ID
+ 1, 0,
+ // size
+ 28, 0,
+ // Original Size
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ }, extra1);
+ // skip compressed size
+ a.skipBytes(8);
+ } else {
+ final byte[] extra2 = new byte[4];
+ a.readFully(extra2);
+ assertArrayEquals("CDH extra", new byte[] {
+ // Header-ID
+ 1, 0,
+ // size
+ 8, 0,
+ }, extra2);
}
- };
+
+ // read offset of LFH
+ final byte[] offset = new byte[8];
+ a.readFully(offset);
+ // verify there is a LFH where the CD claims it
+ a.seek(ZipEightByteInteger.getLongValue(offset));
+ final byte[] sig = new byte[4];
+ a.readFully(sig);
+ assertArrayEquals("LFH signature", new byte[] {
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ }, sig);
+ }
+ };
}
@Test public void write3EntriesCreatingBigArchiveFile() throws Throwable {
@@ -512,20 +495,16 @@ public class Zip64SupportIT {
}
private static final ZipOutputTest write3EntriesCreatingBigArchiveModeNever =
- new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- zos.setUseZip64(Zip64Mode.Never);
- try {
- write3EntriesCreatingBigArchiveToStream(zos);
- fail("expected a Zip64RequiredException");
- } catch (final Zip64RequiredException ex) {
- assertEquals(Zip64RequiredException.ARCHIVE_TOO_BIG_MESSAGE,
- ex.getMessage());
- }
- }
- };
+ (f, zos) -> {
+ zos.setUseZip64(Zip64Mode.Never);
+ try {
+ write3EntriesCreatingBigArchiveToStream(zos);
+ fail("expected a Zip64RequiredException");
+ } catch (final Zip64RequiredException ex) {
+ assertEquals(Zip64RequiredException.ARCHIVE_TOO_BIG_MESSAGE,
+ ex.getMessage());
+ }
+ };
@Test public void write3EntriesCreatingBigArchiveFileModeNever()
throws Throwable {
@@ -544,39 +523,34 @@ public class Zip64SupportIT {
@Test public void read3EntriesCreatingBigArchiveFileUsingZipFile()
throws Throwable {
withTemporaryArchive("read3EntriesCreatingBigArchiveFileUsingZipFile",
- new ZipOutputTest() {
- @Override
- public void test(final File f,
- final ZipArchiveOutputStream zos)
- throws IOException {
- 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());
- }
- }
+ (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);
}
}
- },
+ } finally {
+ ZipFile.closeQuietly(zf);
+ }
+ },
true);
}
@@ -595,154 +569,150 @@ public class Zip64SupportIT {
*/
private static ZipOutputTest writeBigStoredEntry(final boolean knownSize,
final Zip64Mode mode) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- 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 = new RandomAccessFile(f, "r")) {
- 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("CDH start", 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);
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[26];
- a.readFully(rest);
- assertArrayEquals("CDH rest", 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);
- byte[] offset = new byte[4];
- a.readFully(offset);
- if (mode == Zip64Mode.Always) {
- assertArrayEquals("offset", new byte[] {
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- }, offset);
- } else {
- assertArrayEquals("offset", new byte[] {
- 0, 0, 0, 0,
- }, offset);
- }
- assertEquals('0', a.read());
- final byte[] extra = new byte[20];
- a.readFully(extra);
- // 5e9 == 0x12A05F200
- assertArrayEquals("CDH extra", 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);
- if (mode == Zip64Mode.Always) {
- offset = new byte[8];
- a.readFully(offset);
- assertArrayEquals("extra offset", new byte[] {
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, offset);
- }
+ 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();
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals("LFH start", new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 45, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header);
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- assertArrayEquals("LFH rest", 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);
- a.readFully(extra);
- // 5e9 == 0x12A05F200
- assertArrayEquals("LFH extra", 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);
- }
+ try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
+ 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("CDH start", 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);
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[26];
+ a.readFully(rest);
+ assertArrayEquals("CDH rest", 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);
+ byte[] offset = new byte[4];
+ a.readFully(offset);
+ if (mode == Zip64Mode.Always) {
+ assertArrayEquals("offset", new byte[] {
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ }, offset);
+ } else {
+ assertArrayEquals("offset", new byte[] {
+ 0, 0, 0, 0,
+ }, offset);
+ }
+ assertEquals('0', a.read());
+ final byte[] extra = new byte[20];
+ a.readFully(extra);
+ // 5e9 == 0x12A05F200
+ assertArrayEquals("CDH extra", 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);
+ if (mode == Zip64Mode.Always) {
+ offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals("extra offset", new byte[] {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ }, offset);
}
- };
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals("LFH start", new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0
+ }, header);
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ assertArrayEquals("LFH rest", 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);
+ a.readFully(extra);
+ // 5e9 == 0x12A05F200
+ assertArrayEquals("LFH extra", 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);
+ }
+ };
}
/*
@@ -789,30 +759,26 @@ public class Zip64SupportIT {
private static ZipOutputTest
writeBigStoredEntryModeNever(final boolean knownSize) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- zos.setUseZip64(Zip64Mode.Never);
- try {
- 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();
- fail("expected a Zip64RequiredException");
- } catch (final Zip64RequiredException ex) {
- assertTrue(ex.getMessage().startsWith("0's size"));
- }
+ return (f, zos) -> {
+ zos.setUseZip64(Zip64Mode.Never);
+ try {
+ 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();
+ fail("expected a Zip64RequiredException");
+ } catch (final Zip64RequiredException ex) {
+ assertTrue(ex.getMessage().startsWith("0's size"));
+ }
+ };
}
@Test public void writeBigStoredEntryToStreamModeNever() throws Throwable {
@@ -847,175 +813,170 @@ public class Zip64SupportIT {
private static ZipOutputTest
writeBigDeflatedEntryToStream(final boolean knownSize,
final Zip64Mode mode) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f,
- final ZipArchiveOutputStream zos)
- throws IOException {
- 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 = new RandomAccessFile(f, "r")) {
- 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("CDH start", 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);
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[26];
- a.readFully(rest);
- assertArrayEquals("CDH rest", 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);
- byte[] offset = new byte[4];
- a.readFully(offset);
- if (mode == Zip64Mode.Always) {
- assertArrayEquals("offset", new byte[] {
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- }, offset);
- } else {
- assertArrayEquals("offset", new byte[] {
- 0, 0, 0, 0,
- }, offset);
- }
- assertEquals('0', a.read());
- byte[] extra = new byte[12];
- a.readFully(extra);
- // 5e9 == 0x12A05F200
- assertArrayEquals("CDH extra", 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);
- if (mode == Zip64Mode.Always) {
- // skip compressed size
- a.skipBytes(8);
- offset = new byte[8];
- a.readFully(offset);
- assertArrayEquals("extra offset", new byte[] {
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, offset);
- }
+ 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();
- // validate data descriptor
- a.seek(cfhPos - 24);
- byte[] dd = new byte[8];
- a.readFully(dd);
- assertArrayEquals("DD", new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 7, 8,
- // CRC
- (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
- }, dd);
- // skip compressed size
- a.skipBytes(8);
- dd = new byte[8];
- a.readFully(dd);
- assertArrayEquals("DD sizes", new byte[] {
- // original size
- 0, (byte) 0xF2, 5, (byte) 0x2A,
- 1, 0, 0, 0,
- }, dd);
-
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals("LFH start", 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);
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- assertArrayEquals("LFH rest", 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);
- extra = new byte[20];
- a.readFully(extra);
- assertArrayEquals("LFH extra", 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);
- }
+ try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
+ 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("CDH start", 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);
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[26];
+ a.readFully(rest);
+ assertArrayEquals("CDH rest", 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);
+ byte[] offset = new byte[4];
+ a.readFully(offset);
+ if (mode == Zip64Mode.Always) {
+ assertArrayEquals("offset", new byte[] {
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ }, offset);
+ } else {
+ assertArrayEquals("offset", new byte[] {
+ 0, 0, 0, 0,
+ }, offset);
}
- };
+ assertEquals('0', a.read());
+ byte[] extra = new byte[12];
+ a.readFully(extra);
+ // 5e9 == 0x12A05F200
+ assertArrayEquals("CDH extra", 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);
+ if (mode == Zip64Mode.Always) {
+ // skip compressed size
+ a.skipBytes(8);
+ offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals("extra offset", new byte[] {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ }, offset);
+ }
+
+ // validate data descriptor
+ a.seek(cfhPos - 24);
+ byte[] dd = new byte[8];
+ a.readFully(dd);
+ assertArrayEquals("DD", new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 7, 8,
+ // CRC
+ (byte) 0x50, (byte) 0x6F, (byte) 0x31, (byte) 0x5c,
+ }, dd);
+ // skip compressed size
+ a.skipBytes(8);
+ dd = new byte[8];
+ a.readFully(dd);
+ assertArrayEquals("DD sizes", new byte[] {
+ // original size
+ 0, (byte) 0xF2, 5, (byte) 0x2A,
+ 1, 0, 0, 0,
+ }, dd);
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals("LFH start", 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);
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ assertArrayEquals("LFH rest", 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);
+ extra = new byte[20];
+ a.readFully(extra);
+ assertArrayEquals("LFH extra", 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);
+ }
+ };
}
@Test public void writeBigDeflatedEntryKnownSizeToStream()
@@ -1044,28 +1005,24 @@ public class Zip64SupportIT {
private static ZipOutputTest
writeBigDeflatedEntryUnknownSizeToStream(final Zip64Mode mode) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- try {
- if (mode != Zip64Mode.AsNeeded) {
- zos.setUseZip64(mode);
- }
- final byte[] buf = new byte[ONE_MILLION];
- final ZipArchiveEntry zae = new ZipArchiveEntry("0");
- zae.setMethod(ZipEntry.DEFLATED);
- zos.putArchiveEntry(zae);
- for (int j = 0; j < FIVE_BILLION / 1000 / 1000; j++) {
- zos.write(buf);
- }
- zos.closeArchiveEntry();
- fail("expected a Zip64RequiredException");
- } catch (final Zip64RequiredException ex) {
- assertTrue(ex.getMessage().startsWith("0's size"));
- }
+ return (f, zos) -> {
+ try {
+ if (mode != Zip64Mode.AsNeeded) {
+ zos.setUseZip64(mode);
}
- };
+ final byte[] buf = new byte[ONE_MILLION];
+ final ZipArchiveEntry zae = new ZipArchiveEntry("0");
+ zae.setMethod(ZipEntry.DEFLATED);
+ zos.putArchiveEntry(zae);
+ for (int j = 0; j < FIVE_BILLION / 1000 / 1000; j++) {
+ zos.write(buf);
+ }
+ zos.closeArchiveEntry();
+ fail("expected a Zip64RequiredException");
+ } catch (final Zip64RequiredException ex) {
+ assertTrue(ex.getMessage().startsWith("0's size"));
+ }
+ };
}
@Test public void writeBigDeflatedEntryUnknownSizeToStream()
@@ -1101,153 +1058,149 @@ public class Zip64SupportIT {
private static ZipOutputTest
writeBigDeflatedEntryToFile(final boolean knownSize,
final Zip64Mode mode) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- 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 = new RandomAccessFile(f, "r")) {
- 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("CDH start", 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);
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[26];
- a.readFully(rest);
- assertArrayEquals("CDH rest", 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);
- byte[] offset = new byte[4];
- a.readFully(offset);
- if (mode == Zip64Mode.Always) {
- assertArrayEquals("offset", new byte[] {
- (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
- }, offset);
- } else {
- assertArrayEquals("offset", new byte[] {
- 0, 0, 0, 0,
- }, offset);
- }
- assertEquals('0', a.read());
- byte[] extra = new byte[12];
- a.readFully(extra);
- // 5e9 == 0x12A05F200
- assertArrayEquals("CDH extra", 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);
- if (mode == Zip64Mode.Always) {
- // skip compressed size
- a.skipBytes(8);
- offset = new byte[8];
- a.readFully(offset);
- assertArrayEquals("extra offset", new byte[] {
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, offset);
- }
+ 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();
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals("LFH start", 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);
- // 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);
- }
+ try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
+ 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("CDH start", 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);
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[26];
+ a.readFully(rest);
+ assertArrayEquals("CDH rest", 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);
+ byte[] offset = new byte[4];
+ a.readFully(offset);
+ if (mode == Zip64Mode.Always) {
+ assertArrayEquals("offset", new byte[] {
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
+ }, offset);
+ } else {
+ assertArrayEquals("offset", new byte[] {
+ 0, 0, 0, 0,
+ }, offset);
+ }
+ assertEquals('0', a.read());
+ byte[] extra = new byte[12];
+ a.readFully(extra);
+ // 5e9 == 0x12A05F200
+ assertArrayEquals("CDH extra", 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);
+ if (mode == Zip64Mode.Always) {
+ // skip compressed size
+ a.skipBytes(8);
+ offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals("extra offset", new byte[] {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ }, offset);
}
- };
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals("LFH start", 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);
+ // 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);
+ }
+ };
}
@Test public void writeBigDeflatedEntryKnownSizeToFile()
@@ -1282,26 +1235,21 @@ public class Zip64SupportIT {
@Test public void writeBigDeflatedEntryKnownSizeToStreamModeNever()
throws Throwable {
withTemporaryArchive("writeBigDeflatedEntryKnownSizeToStreamModeNever",
- new ZipOutputTest() {
- @Override
- public void test(final File f,
- final ZipArchiveOutputStream zos)
- throws IOException {
- zos.setUseZip64(Zip64Mode.Never);
- try {
- final ZipArchiveEntry zae =
- new ZipArchiveEntry("0");
- zae.setSize(FIVE_BILLION);
- zae.setMethod(ZipEntry.DEFLATED);
- zos.putArchiveEntry(zae);
- fail("expected a"
- + " Zip64RequiredException");
- } catch (final Zip64RequiredException ex) {
- assertTrue(ex.getMessage()
- .startsWith("0's size"));
- }
- }
- },
+ (f, zos) -> {
+ zos.setUseZip64(Zip64Mode.Never);
+ try {
+ final ZipArchiveEntry zae =
+ new ZipArchiveEntry("0");
+ zae.setSize(FIVE_BILLION);
+ zae.setMethod(ZipEntry.DEFLATED);
+ zos.putArchiveEntry(zae);
+ fail("expected a"
+ + " Zip64RequiredException");
+ } catch (final Zip64RequiredException ex) {
+ assertTrue(ex.getMessage()
+ .startsWith("0's size"));
+ }
+ },
false);
}
@@ -1316,31 +1264,27 @@ public class Zip64SupportIT {
*/
private static ZipOutputTest
writeBigDeflatedEntryToFileModeNever(final boolean knownSize) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- zos.setUseZip64(Zip64Mode.Never);
- try {
- 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();
- fail("expected a Zip64RequiredException");
- } catch (final Zip64RequiredException ex) {
- assertTrue(ex.getMessage().startsWith("0's size"));
- }
+ return (f, zos) -> {
+ zos.setUseZip64(Zip64Mode.Never);
+ try {
+ 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();
+ fail("expected a Zip64RequiredException");
+ } catch (final Zip64RequiredException ex) {
+ assertTrue(ex.getMessage().startsWith("0's size"));
+ }
+ };
}
@Test public void writeBigDeflatedEntryKnownSizeToFileModeNever()
@@ -1372,131 +1316,127 @@ public class Zip64SupportIT {
*/
private static ZipOutputTest writeSmallStoredEntry(final boolean knownSize,
final Zip64Mode mode) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- 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 = new RandomAccessFile(f, "r")) {
- 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("CDH start", 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);
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[31];
- a.readFully(rest);
- // 1e6 == 0xF4240
- assertArrayEquals("CDH rest", 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);
-
- // 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("LFH start", new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 10, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header);
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- // 1e6 == 0xF4240
- assertArrayEquals("LFH rest", 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);
- if (hasExtra) {
- final byte[] extra = new byte[20];
- a.readFully(extra);
- assertArrayEquals("ZIP64 extra field", 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);
- }
- }
+ 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();
+
+ try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
+ 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("CDH start", 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);
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[31];
+ a.readFully(rest);
+ // 1e6 == 0xF4240
+ assertArrayEquals("CDH rest", 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);
+
+ // 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("LFH start", new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 10, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0
+ }, header);
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ // 1e6 == 0xF4240
+ assertArrayEquals("LFH rest", 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);
+ if (hasExtra) {
+ final byte[] extra = new byte[20];
+ a.readFully(extra);
+ assertArrayEquals("ZIP64 extra field", 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);
}
- };
+ }
+ };
}
@Test public void writeSmallStoredEntryToStream() throws Throwable {
@@ -1548,140 +1488,136 @@ public class Zip64SupportIT {
*/
private static ZipOutputTest
writeSmallStoredEntryModeAlways(final boolean knownSize) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- 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 = new RandomAccessFile(f, "r")) {
- 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("CDH start", 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);
- // ignore timestamp
- a.skipBytes(4);
- byte[] rest = new byte[31];
- a.readFully(rest);
- // 1e6 == 0xF4240
- assertArrayEquals("CDH rest", 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);
-
- byte[] extra = new byte[28];
- a.readFully(extra);
- assertArrayEquals("CDH extra", 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);
-
- // 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("LFH start", new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 3, 4,
- // version needed to extract
- 45, 0,
- // GPB (EFS bit)
- 0, 8,
- // method
- 0, 0
- }, header);
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- // 1e6 == 0xF4240
- assertArrayEquals("LFH rest", 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);
-
- extra = new byte[20];
- a.readFully(extra);
- assertArrayEquals("LFH extra", 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);
- }
- }
- };
+ 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();
+
+ try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
+ 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("CDH start", 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);
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] rest = new byte[31];
+ a.readFully(rest);
+ // 1e6 == 0xF4240
+ assertArrayEquals("CDH rest", 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);
+
+ byte[] extra = new byte[28];
+ a.readFully(extra);
+ assertArrayEquals("CDH extra", 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);
+
+ // 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("LFH start", new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 3, 4,
+ // version needed to extract
+ 45, 0,
+ // GPB (EFS bit)
+ 0, 8,
+ // method
+ 0, 0
+ }, header);
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ // 1e6 == 0xF4240
+ assertArrayEquals("LFH rest", 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);
+
+ extra = new byte[20];
+ a.readFully(extra);
+ assertArrayEquals("LFH extra", 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);
+ }
+ };
}
@Test public void writeSmallStoredEntryToStreamModeAlways()
@@ -1715,132 +1651,128 @@ public class Zip64SupportIT {
private static ZipOutputTest
writeSmallDeflatedEntryToStream(final boolean knownSize,
final Zip64Mode mode) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- 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 = new RandomAccessFile(f, "r")) {
- 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);
- }
- }
- };
+ 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();
+
+ try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
+ 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);
+ }
+ };
}
@@ -1885,163 +1817,159 @@ public class Zip64SupportIT {
*/
private static ZipOutputTest
writeSmallDeflatedEntryToStreamModeAlways(final boolean knownSize) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- 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 = new RandomAccessFile(f, "r")) {
- 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("CDH start", 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);
- // 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("CDH rest", 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);
- byte[] extra = new byte[12];
- a.readFully(extra);
- assertArrayEquals("CDH extra", 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);
- // skip compressed size
- a.skipBytes(8);
- final byte[] offset = new byte[8];
- a.readFully(offset);
- assertArrayEquals("extra offset", new byte[] {
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, offset);
-
- // validate data descriptor
- a.seek(cfhPos - 24);
- byte[] dd = new byte[8];
- a.readFully(dd);
- assertArrayEquals("DD", new byte[] {
- // sig
- (byte) 0x50, (byte) 0x4b, 7, 8,
- // CRC
- (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
- }, dd);
- // skip compressed size
- a.skipBytes(8);
- dd = new byte[8];
- a.readFully(dd);
- assertArrayEquals("DD size", new byte[] {
- // original size
- (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
- 0, 0, 0, 0
- }, dd);
-
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals("LFH start", 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);
- // ignore timestamp
- a.skipBytes(4);
- rest = new byte[17];
- a.readFully(rest);
- assertArrayEquals("LFH rest", 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);
-
- extra = new byte[20];
- a.readFully(extra);
- assertArrayEquals("LFH extra", 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);
- }
- }
- };
+ 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 = new RandomAccessFile(f, "r")) {
+ 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("CDH start", 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);
+ // 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("CDH rest", 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);
+ byte[] extra = new byte[12];
+ a.readFully(extra);
+ assertArrayEquals("CDH extra", 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);
+ // skip compressed size
+ a.skipBytes(8);
+ final byte[] offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals("extra offset", new byte[] {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ }, offset);
+
+ // validate data descriptor
+ a.seek(cfhPos - 24);
+ byte[] dd = new byte[8];
+ a.readFully(dd);
+ assertArrayEquals("DD", new byte[] {
+ // sig
+ (byte) 0x50, (byte) 0x4b, 7, 8,
+ // CRC
+ (byte) 0x9E, (byte) 0xCB, (byte) 0x79, (byte) 0x12,
+ }, dd);
+ // skip compressed size
+ a.skipBytes(8);
+ dd = new byte[8];
+ a.readFully(dd);
+ assertArrayEquals("DD size", new byte[] {
+ // original size
+ (byte) 0x40, (byte) 0x42, (byte) 0x0F, 0,
+ 0, 0, 0, 0
+ }, dd);
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals("LFH start", 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);
+ // ignore timestamp
+ a.skipBytes(4);
+ rest = new byte[17];
+ a.readFully(rest);
+ assertArrayEquals("LFH rest", 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);
+
+ extra = new byte[20];
+ a.readFully(extra);
+ assertArrayEquals("LFH extra", 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);
+ }
+ };
}
@@ -2074,136 +2002,132 @@ public class Zip64SupportIT {
private static ZipOutputTest
writeSmallDeflatedEntryToFile(final boolean knownSize,
final Zip64Mode mode) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- 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 = new RandomAccessFile(f, "r")) {
- 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);
- 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);
- }
- }
+ 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();
+
+ try (RandomAccessFile a = new RandomAccessFile(f, "r")) {
+ 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);
+ 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);
}
- };
+ }
+ };
}
@Test public void writeSmallDeflatedEntryKnownSizeToFile()
@@ -2246,147 +2170,143 @@ public class Zip64SupportIT {
*/
private static ZipOutputTest
writeSmallDeflatedEntryToFileModeAlways(final boolean knownSize) {
- return new ZipOutputTest() {
- @Override
- public void test(final File f, final ZipArchiveOutputStream zos)
- throws IOException {
- 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 = new RandomAccessFile(f, "r")) {
- getLengthAndPositionAtCentralDirectory(a);
-
- // grab first CD entry, verify sizes are not
- // 0xFFFFFFFF and it has a an empty ZIP64 extended
- // information extra field
- byte[] header = new byte[12];
- a.readFully(header);
- assertArrayEquals("CDH start", 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);
- // ignore timestamp
- a.skipBytes(4);
- byte[] crc = new byte[4];
- a.readFully(crc);
- assertArrayEquals("CDH CRC", 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("CDH rest", 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);
- byte[] extra = new byte[12];
- a.readFully(extra);
- assertArrayEquals("CDH extra", 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);
- // skip compressed size
- a.skipBytes(8);
- final byte[] offset = new byte[8];
- a.readFully(offset);
- assertArrayEquals("extra offset", new byte[] {
- 0, 0, 0, 0, 0, 0, 0, 0,
- }, offset);
-
- // and now validate local file header
- a.seek(0);
- header = new byte[10];
- a.readFully(header);
- assertArrayEquals("LFH start", 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);
- // ignore timestamp
- a.skipBytes(4);
- crc = new byte[4];
- a.readFully(crc);
- assertArrayEquals("LFH CRC", new byte[] {
- (byte) 0x9E, (byte) 0xCB,
- (byte) 0x79, (byte) 0x12,
- }, crc);
- rest = new byte[13];
- a.readFully(rest);
-
- assertArrayEquals("LFH rest", 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);
-
- extra = new byte[12];
- a.readFully(extra);
- assertArrayEquals("LFH extra", 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);
- }
- }
- };
+ 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 = new RandomAccessFile(f, "r")) {
+ getLengthAndPositionAtCentralDirectory(a);
+
+ // grab first CD entry, verify sizes are not
+ // 0xFFFFFFFF and it has a an empty ZIP64 extended
+ // information extra field
+ byte[] header = new byte[12];
+ a.readFully(header);
+ assertArrayEquals("CDH start", 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);
+ // ignore timestamp
+ a.skipBytes(4);
+ byte[] crc = new byte[4];
+ a.readFully(crc);
+ assertArrayEquals("CDH CRC", 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("CDH rest", 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);
+ byte[] extra = new byte[12];
+ a.readFully(extra);
+ assertArrayEquals("CDH extra", 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);
+ // skip compressed size
+ a.skipBytes(8);
+ final byte[] offset = new byte[8];
+ a.readFully(offset);
+ assertArrayEquals("extra offset", new byte[] {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ }, offset);
+
+ // and now validate local file header
+ a.seek(0);
+ header = new byte[10];
+ a.readFully(header);
+ assertArrayEquals("LFH start", 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);
+ // ignore timestamp
+ a.skipBytes(4);
+ crc = new byte[4];
+ a.readFully(crc);
+ assertArrayEquals("LFH CRC", new byte[] {
+ (byte) 0x9E, (byte) 0xCB,
+ (byte) 0x79, (byte) 0x12,
+ }, crc);
+ rest = new byte[13];
+ a.readFully(rest);
+
+ assertArrayEquals("LFH rest", 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);
+
+ extra = new byte[12];
+ a.readFully(extra);
+ assertArrayEquals("LFH extra", 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);
+ }
+ };
}
@Test public void writeSmallDeflatedEntryKnownSizeToFileModeAlways()