commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1152615 - in /commons/proper/compress/branches/zip64/src: main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
Date Sun, 31 Jul 2011 19:09:22 GMT
Author: bodewig
Date: Sun Jul 31 19:09:21 2011
New Revision: 1152615

URL: http://svn.apache.org/viewvc?rev=1152615&view=rev
Log:
cases five and six of seven: unknown sizes, writing to a file, compressed and uncompressed.
 COMPRESS-150

Modified:
    commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
    commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java

Modified: commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=1152615&r1=1152614&r2=1152615&view=diff
==============================================================================
--- commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
(original)
+++ commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Sun Jul 31 19:09:21 2011
@@ -444,13 +444,17 @@ public class ZipArchiveOutputStream exte
 
             raf.seek(localDataStart);
             writeOut(ZipLong.getBytes(entry.getCrc()));
-            if (!hasZip64Extra(entry)) {
+            if (!hasZip64Extra(entry)
+                || (entry.getSize() < ZIP64_MAGIC
+                    && entry.getCompressedSize() < ZIP64_MAGIC)) {
                 writeOut(ZipLong.getBytes(entry.getCompressedSize()));
                 writeOut(ZipLong.getBytes(entry.getSize()));
             } else {
                 writeOut(ZipLong.ZIP64_MAGIC.getBytes());
                 writeOut(ZipLong.ZIP64_MAGIC.getBytes());
+            }
 
+            if (hasZip64Extra(entry)) {
                 // seek to ZIP64 extra, skip header and size information
                 raf.seek(localDataStart + 3 * WORD + 2 * SHORT
                          + getName(entry).limit() + 2 * SHORT);
@@ -507,12 +511,16 @@ public class ZipArchiveOutputStream exte
         }
 
         // add a ZIP64 extended information extra field if we already
-        // know it is going to be needed
+        // know it is going to be needed or the size is unknown and we
+        // can ensure it won't hurt other implementations if we add it
+        // (i.e. we can erase its usage)
         if (entry.getSize() >= ZIP64_MAGIC
-            || entry.getCompressedSize() >= ZIP64_MAGIC) {
+            || entry.getCompressedSize() >= ZIP64_MAGIC
+            || (entry.getSize() == ArchiveEntry.SIZE_UNKNOWN && raf != null)) {
 
             Zip64ExtendedInformationExtraField z64 = getZip64Extra(entry);
-            if (entry.getMethod() == STORED) {
+            if (entry.getMethod() == STORED
+                && entry.getSize() != ArchiveEntry.SIZE_UNKNOWN) {
                 ZipEightByteInteger size =
                     new ZipEightByteInteger(entry.getSize());
                 z64.setSize(size);

Modified: commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java?rev=1152615&r1=1152614&r2=1152615&view=diff
==============================================================================
--- commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
(original)
+++ commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
Sun Jul 31 19:09:21 2011
@@ -461,6 +461,12 @@ public class Zip64SupportTest {
                              true);
     }
 
+    @Test public void writeBigStoredEntryUnnownSizeToFile() throws Throwable {
+        withTemporaryArchive("writeBigStoredEntryUnknownSizeToFile",
+                             writeBigStoredEntry(false),
+                             true);
+    }
+
     /*
      * One entry of length 5 billion bytes, written with
      * compression to a stream.
@@ -645,17 +651,17 @@ public class Zip64SupportTest {
      *
      * Creates a temporary archive of approx 4MB in size
      */
-    @Test public void writeBigDeflatedEntryKnownSizeToFile()
-        throws Throwable {
-        withTemporaryArchive("writeBigDeflatedEntryKnownSizeToFile",
-                             new ZipOutputTest() {
+    private static ZipOutputTest writeBigDeflatedEntryToFile(final boolean knownSize) {
+        return new ZipOutputTest() {
                                  public void test(File f,
                                                   ZipArchiveOutputStream zos)
                                      throws IOException {
                                      byte[] buf = new byte[1000 * 1000];
                                      ZipArchiveEntry zae =
                                          new ZipArchiveEntry("0");
+                                     if (knownSize) {
                                      zae.setSize(FIVE_BILLION);
+                                     }
                                      zae.setMethod(ZipArchiveEntry.DEFLATED);
                                      zos.putArchiveEntry(zae);
                                      for (int j = 0;
@@ -793,7 +799,21 @@ public class Zip64SupportTest {
                                          a.close();
                                      }
                                  }
-                             },
+        };
+    }
+
+    @Ignore
+    @Test public void writeBigDeflatedEntryKnownSizeToFile()
+        throws Throwable {
+        withTemporaryArchive("writeBigDeflatedEntryKnownSizeToFile",
+                             writeBigDeflatedEntryToFile(true),
+                             true);
+    }
+
+    @Test public void writeBigDeflatedEntryUnknownSizeToFile()
+        throws Throwable {
+        withTemporaryArchive("writeBigDeflatedEntryUnknownSizeToFile",
+                             writeBigDeflatedEntryToFile(false),
                              true);
     }
 



Mime
View raw message