Author: bodewig Date: Thu Aug 4 10:28:06 2011 New Revision: 1153835 URL: http://svn.apache.org/viewvc?rev=1153835&view=rev Log: ensure the CRC is correct for empty entries, with this 7ZIP likes the 100K files written to stream archive as well
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=1153835&r1=1153834&r2=1153835&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Thu Aug 4 10:28:06 2011 @@ -375,6 +375,10 @@ public class ZipArchiveOutputStream exte throw new IOException("No current entry to close"); } + if (!entry.hasWritten) { + write(new byte[0], 0, 0); + } + if (entry.entry.getMethod() == DEFLATED) { def.finish(); while (!def.finished()) { @@ -600,6 +604,7 @@ public class ZipArchiveOutputStream exte @Override public void write(byte[] b, int offset, int length) throws IOException { ZipUtil.checkRequestedFeatures(entry.entry); + entry.hasWritten = true; if (entry.entry.getMethod() == DEFLATED) { if (length > 0 && !def.finished()) { entry.bytesRead += length; @@ -1228,6 +1233,15 @@ public class ZipArchiveOutputStream exte * Whether current entry was the first one using ZIP64 features. */ private boolean causedUseOfZip64 = false; + /** + * Whether write() has been called at all. + * + * <p>In order to create a valid archive {@link + * #closeArchiveEntry closeArchiveEntry} will write an empty + * array to get the CRC right if nothing has been written to + * the stream at all.</p> + */ + private boolean hasWritten; } } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java?rev=1153835&r1=1153834&r2=1153835&view=diff ============================================================================== --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java Thu Aug 4 10:28:06 2011 @@ -84,10 +84,12 @@ public class Zip64SupportTest { read100KFilesImpl(get100KFileFileGeneratedByJava7Jar()); } + @Ignore @Test public void read5GBOfZerosUsingZipFile() throws Throwable { read5GBOfZerosUsingZipFileImpl(get5GBZerosFile(), "5GB_of_Zeros"); } + @Ignore @Test public void read5GBOfZerosGeneratedBy7ZIPUsingZipFile() throws Throwable { read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedBy7ZIP(), @@ -221,11 +223,11 @@ public class Zip64SupportTest { withTemporaryArchive("write100KFilesFile", write100KFiles, true); } - @Ignore @Test public void write100KFilesStream() throws Throwable { withTemporaryArchive("write100KFilesStream", write100KFiles, false); } + @Ignore @Test public void readSelfGenerated100KFilesUsingZipFile() throws Throwable { withTemporaryArchive("readSelfGenerated100KFilesUsingZipFile()", @@ -334,12 +336,14 @@ public class Zip64SupportTest { true); } + @Ignore @Test public void write3EntriesCreatingBigArchiveStream() throws Throwable { withTemporaryArchive("write3EntriesCreatingBigArchiveStream", write3EntriesCreatingBigArchive, false); } + @Ignore @Test public void read3EntriesCreatingBigArchiveFileUsingZipFile() throws Throwable { withTemporaryArchive("read3EntriesCreatingBigArchiveFileUsingZipFile",