commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1152687 - in /commons/proper/compress/trunk: ./ src/main/java/org/apache/commons/compress/archivers/tar/ src/main/java/org/apache/commons/compress/archivers/zip/ src/main/java/org/apache/commons/compress/compressors/bzip2/ src/test/java/or...
Date Mon, 01 Aug 2011 04:09:12 GMT
Author: bodewig
Date: Mon Aug  1 04:09:10 2011
New Revision: 1152687

URL: http://svn.apache.org/viewvc?rev=1152687&view=rev
Log:
reintegrate ZIP64 branch.  COMPRESS-36, COMPRESS-148, COMPRESS-150, COMPRESS-151.

Added:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java
      - copied unchanged from r1152684, commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
      - copied unchanged from r1152684, commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
Modified:
    commons/proper/compress/trunk/   (props changed)
    commons/proper/compress/trunk/pom.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/   (props changed)
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java   (props changed)
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java   (props changed)
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/   (props changed)
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java   (contents, props changed)
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java   (contents, props changed)
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java   (contents, props changed)
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java   (props changed)
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java   (props changed)
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java   (props changed)

Propchange: commons/proper/compress/trunk/
------------------------------------------------------------------------------
    svn:mergeinfo = /commons/proper/compress/branches/zip64:1149597-1152684

Modified: commons/proper/compress/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/pom.xml?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/pom.xml (original)
+++ commons/proper/compress/trunk/pom.xml Mon Aug  1 04:09:10 2011
@@ -34,8 +34,8 @@
   </description>
 
   <properties>
-    <maven.compile.source>1.4</maven.compile.source>
-    <maven.compile.target>1.4</maven.compile.target>
+    <maven.compile.source>1.5</maven.compile.source>
+    <maven.compile.target>1.5</maven.compile.target>
     <commons.componentid>compress</commons.componentid>
     <commons.jira.id>COMPRESS</commons.jira.id>
     <commons.jira.pid>12310904</commons.jira.pid>
@@ -53,7 +53,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>3.8.2</version>
+      <version>4.8.2</version>
       <scope>test</scope>
     </dependency>
   </dependencies>

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/tar:741089
+/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar:1149597-1152684

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -1,2 +1,3 @@
 /ant/core/trunk/src/main/org/apache/tools/tar/TarArchiveEntry.java:741089
 /ant/core/trunk/src/main/org/apache/tools/tar/TarEntry.java:807513,823136
+/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java:1149597-1152684

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/tar/TarBuffer.java:741089,789556
+/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java:1149597-1152684

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/zip:738844,739300,741089
+/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip:1149597-1152684

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java Mon Aug  1 04:09:10 2011
@@ -35,14 +35,15 @@ public class ExtraFieldUtils {
     /**
      * Static registry of known extra fields.
      */
-    private static final Map implementations;
+    private static final Map<ZipShort, Class<?>> implementations;
 
     static {
-        implementations = new HashMap();
+        implementations = new HashMap<ZipShort, Class<?>>();
         register(AsiExtraField.class);
         register(JarMarker.class);
         register(UnicodePathExtraField.class);
         register(UnicodeCommentExtraField.class);
+        register(Zip64ExtendedInformationExtraField.class);
     }
 
     /**
@@ -52,7 +53,7 @@ public class ExtraFieldUtils {
      * the {@link ZipExtraField ZipExtraField interface}.</p>
      * @param c the class to register
      */
-    public static void register(Class c) {
+    public static void register(Class<?> c) {
         try {
             ZipExtraField ze = (ZipExtraField) c.newInstance();
             implementations.put(ze.getHeaderId(), c);
@@ -75,7 +76,7 @@ public class ExtraFieldUtils {
      */
     public static ZipExtraField createExtraField(ZipShort headerId)
         throws InstantiationException, IllegalAccessException {
-        Class c = (Class) implementations.get(headerId);
+        Class<?> c = implementations.get(headerId);
         if (c != null) {
             return (ZipExtraField) c.newInstance();
         }
@@ -126,7 +127,7 @@ public class ExtraFieldUtils {
     public static ZipExtraField[] parse(byte[] data, boolean local,
                                         UnparseableExtraField onUnparseableData)
         throws ZipException {
-        List v = new ArrayList();
+        List<ZipExtraField> v = new ArrayList<ZipExtraField>();
         int start = 0;
         LOOP:
         while (start <= data.length - WORD) {
@@ -181,7 +182,7 @@ public class ExtraFieldUtils {
         }
 
         ZipExtraField[] result = new ZipExtraField[v.size()];
-        return (ZipExtraField[]) v.toArray(result);
+        return v.toArray(result);
     }
 
     /**

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java Mon Aug  1 04:09:10 2011
@@ -149,6 +149,7 @@ public final class GeneralPurposeBit {
         return b;
     }
 
+    @Override
     public int hashCode() {
         return 3 * (7 * (13 * (17 * (encryptionFlag ? 1 : 0)
                                + (strongEncryptionFlag ? 1 : 0))
@@ -156,6 +157,7 @@ public final class GeneralPurposeBit {
                     + (dataDescriptorFlag ? 1 : 0));
     }
 
+    @Override
     public boolean equals(Object o) {
         if (!(o instanceof GeneralPurposeBit)) {
             return false;

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java Mon Aug  1 04:09:10 2011
@@ -82,7 +82,7 @@ class Simple8BitZipEncoding implements Z
      * field.  This list is used to binary search reverse mapping of
      * unicode characters with a character code greater than 127.
      */
-    private final List reverseMapping;
+    private final List<Simple8BitChar> reverseMapping;
 
     /**
      * @param highChars The characters for byte values of 128 to 255
@@ -90,7 +90,7 @@ class Simple8BitZipEncoding implements Z
      */
     public Simple8BitZipEncoding(char[] highChars) {
         this.highChars = (char[]) highChars.clone();
-        List temp = new ArrayList(this.highChars.length);
+        List temp = new ArrayList<Simple8BitChar>(this.highChars.length);
 
         byte code = 127;
 
@@ -172,7 +172,7 @@ class Simple8BitZipEncoding implements Z
 
             int i = i0 + (i1 - i0) / 2;
 
-            Simple8BitChar m = (Simple8BitChar) this.reverseMapping.get(i);
+            Simple8BitChar m = this.reverseMapping.get(i);
 
             if (m.unicode == c) {
                 return m;
@@ -189,7 +189,7 @@ class Simple8BitZipEncoding implements Z
             return null;
         }
 
-        Simple8BitChar r = (Simple8BitChar) this.reverseMapping.get(i0);
+        Simple8BitChar r = this.reverseMapping.get(i0);
 
         if (r.unicode != c) {
             return null;

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -0,0 +1 @@
+/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java:1149597-1152684

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java Mon Aug  1 04:09:10 2011
@@ -20,6 +20,9 @@ package org.apache.commons.compress.arch
 
 import java.util.zip.ZipException;
 
+import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
+
 /**
  * Holds size and other extended information for entries that use Zip64
  * features.
@@ -71,15 +74,12 @@ import java.util.zip.ZipException;
  * @NotThreadSafe
  */
 public class Zip64ExtendedInformationExtraField implements ZipExtraField {
-    // TODO: the LFH should probably not contain relativeHeaderOffset
-    // and diskStart but then ZipArchivePOutputStream won't write it to
-    // the CD either - need to test interop with other implementations
-    // to see whether they do have a problem with the extraneous
-    // information inside the LFH
 
-    private static final ZipShort HEADER_ID = new ZipShort(0x0001);
+    static final ZipShort HEADER_ID = new ZipShort(0x0001);
 
-    private static final int WORD = 4, DWORD = 8;
+    private static final String LFH_MUST_HAVE_BOTH_SIZES_MSG =
+        "Zip64 extended information must contain"
+        + " both size values in the local file header.";
 
     private ZipEightByteInteger size, compressedSize, relativeHeaderOffset;
     private ZipLong diskStart;
@@ -115,12 +115,6 @@ public class Zip64ExtendedInformationExt
                                               ZipEightByteInteger compressedSize,
                                               ZipEightByteInteger relativeHeaderOffset,
                                               ZipLong diskStart) {
-        if (size == null) {
-            throw new IllegalArgumentException("size must not be null");
-        }
-        if (compressedSize == null) {
-            throw new IllegalArgumentException("compressedSize must not be null");
-        }
         this.size = size;
         this.compressedSize = compressedSize;
         this.relativeHeaderOffset = relativeHeaderOffset;
@@ -134,26 +128,34 @@ public class Zip64ExtendedInformationExt
 
     /** {@inheritDoc} */
     public ZipShort getLocalFileDataLength() {
-        return getCentralDirectoryLength();
+        return new ZipShort(size != null ? 2 * DWORD : 0);
     }
 
     /** {@inheritDoc} */
     public ZipShort getCentralDirectoryLength() {
-        return new ZipShort(2 * DWORD  // both size fields
+        return new ZipShort((size != null ? DWORD : 0)
+                            + (compressedSize != null ? DWORD : 0)
                             + (relativeHeaderOffset != null ? DWORD : 0)
                             + (diskStart != null ? WORD : 0));
     }
 
     /** {@inheritDoc} */
     public byte[] getLocalFileDataData() {
-        return getCentralDirectoryData();
+        if (size != null || compressedSize != null) {
+            if (size == null || compressedSize == null) {
+                throw new IllegalArgumentException(LFH_MUST_HAVE_BOTH_SIZES_MSG);
+            }
+            byte[] data = new byte[2 * DWORD];
+            addSizes(data);
+            return data;
+        }
+        return new byte[0];
     }
 
     /** {@inheritDoc} */
     public byte[] getCentralDirectoryData() {
         byte[] data = new byte[getCentralDirectoryLength().getValue()];
-        addSizes(data);
-        int off = 2 * DWORD;
+        int off = addSizes(data);
         if (relativeHeaderOffset != null) {
             System.arraycopy(relativeHeaderOffset.getBytes(), 0, data, off, DWORD);
             off += DWORD;
@@ -169,9 +171,7 @@ public class Zip64ExtendedInformationExt
     public void parseFromLocalFileData(byte[] buffer, int offset, int length)
         throws ZipException {
         if (length < 2 * DWORD) {
-            throw new ZipException("Zip64 extended information must contain"
-                                   + " both size values in the local file"
-                                   + " header.");
+            throw new ZipException(LFH_MUST_HAVE_BOTH_SIZES_MSG);
         }
         size = new ZipEightByteInteger(buffer, offset);
         offset += DWORD;
@@ -198,9 +198,16 @@ public class Zip64ExtendedInformationExt
         // can only hope things will get resolved by LFH data later
         // But there are some cases that can be detected
         // * all data is there
+        // * length == 24 -> both sizes and offset
         // * length % 8 == 4 -> at least we can identify the diskStart field
         if (length >= 3 * DWORD + WORD) {
             parseFromLocalFileData(buffer, offset, length);
+        } else if (length == 3 * DWORD) {
+            size = new ZipEightByteInteger(buffer, offset);
+            offset += DWORD;
+            compressedSize = new ZipEightByteInteger(buffer, offset);
+            offset += DWORD;
+            relativeHeaderOffset = new ZipEightByteInteger(buffer, offset);
         } else if (length % DWORD == WORD) {
             diskStart = new ZipLong(buffer, offset + length - WORD);
         }
@@ -214,6 +221,13 @@ public class Zip64ExtendedInformationExt
     }
 
     /**
+     * The uncompressed size stored in this extra field.
+     */
+    public void setSize(ZipEightByteInteger size) {
+        this.size = size;
+    }
+
+    /**
      * The compressed size stored in this extra field.
      */
     public ZipEightByteInteger getCompressedSize() {
@@ -221,6 +235,13 @@ public class Zip64ExtendedInformationExt
     }
 
     /**
+     * The uncompressed size stored in this extra field.
+     */
+    public void setCompressedSize(ZipEightByteInteger compressedSize) {
+        this.compressedSize = compressedSize;
+    }
+
+    /**
      * The relative header offset stored in this extra field.
      */
     public ZipEightByteInteger getRelativeHeaderOffset() {
@@ -228,14 +249,36 @@ public class Zip64ExtendedInformationExt
     }
 
     /**
+     * The relative header offset stored in this extra field.
+     */
+    public void setRelativeHeaderOffset(ZipEightByteInteger rho) {
+        relativeHeaderOffset = rho;
+    }
+
+    /**
      * The disk start number stored in this extra field.
      */
     public ZipLong getDiskStartNumber() {
         return diskStart;
     }
 
-    private void addSizes(byte[] data) {
-        System.arraycopy(size.getBytes(), 0, data, 0, DWORD);
-        System.arraycopy(compressedSize.getBytes(), 0, data, DWORD, DWORD);
+    /**
+     * The disk start number stored in this extra field.
+     */
+    public void setDiskStartNumber(ZipLong ds) {
+        diskStart = ds;
+    }
+
+    private int addSizes(byte[] data) {
+        int off = 0;
+        if (size != null) {
+            System.arraycopy(size.getBytes(), 0, data, 0, DWORD);
+            off += DWORD;
+        }
+        if (compressedSize != null) {
+            System.arraycopy(compressedSize.getBytes(), 0, data, off, DWORD);
+            off += DWORD;
+        }
+        return off;
     }
 }
\ No newline at end of file

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java Mon Aug  1 04:09:10 2011
@@ -68,10 +68,18 @@ public class ZipArchiveEntry extends jav
      */
     private int method = -1;
 
+    /**
+     * The {@link java.util.zip.ZipEntry#setSize} method in the base
+     * class throws an IllegalArgumentException if the size is bigger
+     * than 2GB for Java versions < 7.  Need to keep our own size
+     * information for Zip64 support.
+     */
+    private long size = SIZE_UNKNOWN;
+
     private int internalAttributes = 0;
     private int platform = PLATFORM_FAT;
     private long externalAttributes = 0;
-    private LinkedHashMap/*<ZipShort, ZipExtraField>*/ extraFields = null;
+    private LinkedHashMap<ZipShort, ZipExtraField> extraFields = null;
     private UnparseableExtraFieldData unparseableExtra = null;
     private String name = null;
     private byte[] rawName = null;
@@ -112,6 +120,7 @@ public class ZipArchiveEntry extends jav
             setExtra();
         }
         setMethod(entry.getMethod());
+        this.size = entry.getSize();
     }
 
     /**
@@ -159,6 +168,7 @@ public class ZipArchiveEntry extends jav
      * Overwrite clone.
      * @return a cloned copy of this ZipArchiveEntry
      */
+    @Override
     public Object clone() {
         ZipArchiveEntry e = (ZipArchiveEntry) super.clone();
 
@@ -277,7 +287,7 @@ public class ZipArchiveEntry extends jav
      * @param fields an array of extra fields
      */
     public void setExtraFields(ZipExtraField[] fields) {
-        extraFields = new LinkedHashMap();
+        extraFields = new LinkedHashMap<ZipShort, ZipExtraField>();
         for (int i = 0; i < fields.length; i++) {
             if (fields[i] instanceof UnparseableExtraFieldData) {
                 unparseableExtra = (UnparseableExtraFieldData) fields[i];
@@ -311,11 +321,12 @@ public class ZipArchiveEntry extends jav
                 ? new ZipExtraField[0]
                 : new ZipExtraField[] { unparseableExtra };
         }
-        List result = new ArrayList(extraFields.values());
+        List<ZipExtraField> result =
+            new ArrayList<ZipExtraField>(extraFields.values());
         if (includeUnparseable && unparseableExtra != null) {
             result.add(unparseableExtra);
         }
-        return (ZipExtraField[]) result.toArray(new ZipExtraField[0]);
+        return result.toArray(new ZipExtraField[0]);
     }
 
     /**
@@ -331,7 +342,7 @@ public class ZipArchiveEntry extends jav
             unparseableExtra = (UnparseableExtraFieldData) ze;
         } else {
             if (extraFields == null) {
-                extraFields = new LinkedHashMap();
+                extraFields = new LinkedHashMap<ZipShort, ZipExtraField>();
             }
             extraFields.put(ze.getHeaderId(), ze);
         }
@@ -350,7 +361,7 @@ public class ZipArchiveEntry extends jav
             unparseableExtra = (UnparseableExtraFieldData) ze;
         } else {
             LinkedHashMap copy = extraFields;
-            extraFields = new LinkedHashMap();
+            extraFields = new LinkedHashMap<ZipShort, ZipExtraField>();
             extraFields.put(ze.getHeaderId(), ze);
             if (copy != null) {
                 copy.remove(ze.getHeaderId());
@@ -394,7 +405,7 @@ public class ZipArchiveEntry extends jav
      */
     public ZipExtraField getExtraField(ZipShort type) {
         if (extraFields != null) {
-            return (ZipExtraField) extraFields.get(type);
+            return extraFields.get(type);
         }
         return null;
     }
@@ -418,6 +429,7 @@ public class ZipArchiveEntry extends jav
      * @throws RuntimeException if the bytes cannot be parsed
      * @throws RuntimeException on error
      */
+    @Override
     public void setExtra(byte[] extra) throws RuntimeException {
         try {
             ZipExtraField[] local =
@@ -425,7 +437,7 @@ public class ZipArchiveEntry extends jav
                                       ExtraFieldUtils.UnparseableExtraField.READ);
             mergeExtraFields(local, true);
         } catch (ZipException e) {
-            // actually this is not be possible as of Commons Compress 1.1
+            // actually this is not possible as of Commons Compress 1.1
             throw new RuntimeException("Error parsing extra fields for entry: "
                                        + getName() + " - " + e.getMessage(), e);
         }
@@ -476,6 +488,7 @@ public class ZipArchiveEntry extends jav
      * Get the name of the entry.
      * @return the entry name
      */
+    @Override
     public String getName() {
         return name == null ? super.getName() : name;
     }
@@ -497,6 +510,29 @@ public class ZipArchiveEntry extends jav
     }
 
     /**
+     * Gets the uncompressed size of the entry data.
+     * @return the entry size
+     */
+    @Override
+    public long getSize() {
+        return size;
+    }
+
+    /**
+     * Sets the uncompressed size of the entry data.
+     * @param size the uncompressed size in bytes
+     * @exception IllegalArgumentException if the specified size is less
+     *            than 0
+     */
+    @Override
+    public void setSize(long size) {
+        if (size < 0) {
+            throw new IllegalArgumentException("invalid entry size");
+        }
+        this.size = size;
+    }
+
+    /**
      * Sets the name using the raw bytes and the string created from
      * it by guessing or using the configured encoding.
      * @param name the name to use created from the raw bytes using
@@ -533,6 +569,7 @@ public class ZipArchiveEntry extends jav
      * This uses the name as the hashcode.
      * @return a hashcode.
      */
+    @Override
     public int hashCode() {
         // this method has severe consequences on performance. We cannot rely
         // on the super.hashCode() method since super.getName() always return
@@ -601,6 +638,7 @@ public class ZipArchiveEntry extends jav
     /* (non-Javadoc)
      * @see java.lang.Object#equals(java.lang.Object)
      */
+    @Override
     public boolean equals(Object obj) {
         if (this == obj) {
             return true;

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java:745537
+/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java:1149597-1152684

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java Mon Aug  1 04:09:10 2011
@@ -32,6 +32,10 @@ import java.util.zip.ZipException;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 
+import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.SHORT;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
+
 /**
  * Implements an input stream that can read Zip archives.
  * <p>
@@ -45,9 +49,6 @@ import org.apache.commons.compress.archi
  */
 public class ZipArchiveInputStream extends ArchiveInputStream {
 
-    private static final int SHORT = 2;
-    private static final int WORD = 4;
-
     /**
      * The zip encoding to use for filenames and the file comment.
      */
@@ -72,6 +73,7 @@ public class ZipArchiveInputStream exten
     private long readBytesOfEntry = 0, bytesReadFromStream = 0;
     private int lengthOfLastRead = 0;
     private boolean hasDataDescriptor = false;
+    private boolean usesZip64 = false;
     private ByteArrayInputStream lastStoredEntry = null;
 
     private boolean allowStoredEntriesWithDataDescriptor = false;
@@ -173,14 +175,15 @@ public class ZipArchiveInputStream exten
         current.setTime(time);
         off += WORD;
 
+        ZipLong size = null, cSize = null;
         if (!hasDataDescriptor) {
             current.setCrc(ZipLong.getValue(lfh, off));
             off += WORD;
 
-            current.setCompressedSize(ZipLong.getValue(lfh, off));
+            cSize = new ZipLong(lfh, off);
             off += WORD;
 
-            current.setSize(ZipLong.getValue(lfh, off));
+            size = new ZipLong(lfh, off);
             off += WORD;
         } else {
             off += 3 * WORD;
@@ -204,10 +207,29 @@ public class ZipArchiveInputStream exten
         if (!hasUTF8Flag && useUnicodeExtraFields) {
             ZipUtil.setNameAndCommentFromExtraFields(current, fileName, null);
         }
+
+        Zip64ExtendedInformationExtraField z64 =  
+            (Zip64ExtendedInformationExtraField)
+            current.getExtraField(Zip64ExtendedInformationExtraField
+                                  .HEADER_ID);
+        usesZip64 = z64 != null;
+        if (!hasDataDescriptor) {
+            if (usesZip64 && (cSize.equals(ZipLong.ZIP64_MAGIC)
+                              || size.equals(ZipLong.ZIP64_MAGIC))
+                ) {
+                current.setCompressedSize(z64.getCompressedSize()
+                                          .getLongValue());
+                current.setSize(z64.getSize().getLongValue());
+            } else {
+                current.setCompressedSize(cSize.getValue());
+                current.setSize(size.getValue());
+            }
+        }
         return current;
     }
 
     /** {@inheritDoc} */
+    @Override
     public ArchiveEntry getNextEntry() throws IOException {
         return getNextZipEntry();
     }
@@ -219,6 +241,7 @@ public class ZipArchiveInputStream exten
      * compression method that hasn't been implemented yet.</p>
      * @since Apache Commons Compress 1.1
      */
+    @Override
     public boolean canReadEntryData(ArchiveEntry ae) {
         if (ae instanceof ZipArchiveEntry) {
             ZipArchiveEntry ze = (ZipArchiveEntry) ae;
@@ -229,6 +252,7 @@ public class ZipArchiveInputStream exten
         return false;
     }
 
+    @Override
     public int read(byte[] buffer, int start, int length) throws IOException {
         if (closed) {
             throw new IOException("The stream is closed");
@@ -307,6 +331,7 @@ public class ZipArchiveInputStream exten
         throw new ArrayIndexOutOfBoundsException();
     }
 
+    @Override
     public void close() throws IOException {
         if (!closed) {
             closed = true;
@@ -329,6 +354,7 @@ public class ZipArchiveInputStream exten
      * @throws IOException - if an I/O error occurs.
      * @throws IllegalArgumentException - if value is negative.
      */
+    @Override
     public long skip(long value) throws IOException {
         if (value >= 0) {
             long skipped = 0;
@@ -420,7 +446,7 @@ public class ZipArchiveInputStream exten
 
             long inB;
             if (current.getMethod() == ZipArchiveOutputStream.DEFLATED) {
-                inB = ZipUtil.adjustToLong(inf.getTotalIn());
+                inB = inf.getBytesRead();
             } else {
                 inB = readBytesOfEntry;
             }
@@ -480,10 +506,18 @@ public class ZipArchiveInputStream exten
             val = new ZipLong(b);
         }
         current.setCrc(val.getValue());
-        readFully(b);
-        current.setCompressedSize(new ZipLong(b).getValue());
-        readFully(b);
-        current.setSize(new ZipLong(b).getValue());
+        if (!usesZip64) {
+            readFully(b);
+            current.setCompressedSize(ZipLong.getValue(b));
+            readFully(b);
+            current.setSize(ZipLong.getValue(b));
+        } else {
+            byte[] b8 = new byte[DWORD];
+            readFully(b8);
+            current.setCompressedSize(ZipEightByteInteger.getLongValue(b8));
+            readFully(b8);
+            current.setSize(ZipEightByteInteger.getLongValue(b8));
+        }
     }
 
     /**
@@ -524,6 +558,9 @@ public class ZipArchiveInputStream exten
         int off = 0;
         boolean done = false;
 
+        // length of DD without signature
+        int ddLen = usesZip64 ? WORD + 2 * DWORD : 3 * WORD;
+
         while (!done) {
             int r = in.read(buf, off, ZipArchiveOutputStream.BUFFER_SIZE - off);
             if (r <= 0) {
@@ -543,7 +580,7 @@ public class ZipArchiveInputStream exten
                     if ((buf[i + 2] == LFH[2] && buf[i + 3] == LFH[3])
                         || (buf[i] == CFH[2] && buf[i + 3] == CFH[3])) {
                         // found a LFH or CFH:
-                        readTooMuch = off + r - i - 12 /* dd without signature */;
+                        readTooMuch = off + r - i - ddLen;
                         done = true;
                     }
                     else if (buf[i + 2] == DD[2] && buf[i + 3] == DD[3]) {
@@ -564,14 +601,15 @@ public class ZipArchiveInputStream exten
             }
             if (!done) {
                 // worst case we've read a data descriptor without a
-                // signature (12 bytes) plus the first three bytes of
+                // signature (up to 20 bytes) plus the first three bytes of
                 // a LFH or CFH signature
-                // save the last 15 bytes in the buffer, cache
+                // save the last ddLen + 3 bytes in the buffer, cache
                 // anything in front of that, read on
-                if (off + r > 15) {
-                    bos.write(buf, 0, off + r - 15);
-                    System.arraycopy(buf, off + r - 15, buf, 0, 15);
-                    off = 15;
+                if (off + r > ddLen + 3) {
+                    bos.write(buf, 0, off + r - ddLen - 3);
+                    System.arraycopy(buf, off + r - ddLen - 3, buf, 0,
+                                     ddLen + 3);
+                    off = ddLen + 3;
                 } else {
                     off += r;
                 }

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=1152687&r1=1152686&r2=1152687&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 Mon Aug  1 04:09:10 2011
@@ -24,7 +24,6 @@ import java.io.OutputStream;
 import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -35,6 +34,16 @@ import java.util.zip.ZipException;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 
+import static org.apache.commons.compress.archivers.zip.ZipConstants.BYTE_MASK;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.DATA_DESCRIPTOR_MIN_VERSION;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.INITIAL_VERSION;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.SHORT;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MAGIC;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MAGIC_SHORT;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MIN_VERSION;
+
 /**
  * Reimplementation of {@link java.util.zip.ZipOutputStream
  * java.util.zip.ZipOutputStream} that does handle the extended
@@ -57,9 +66,6 @@ import org.apache.commons.compress.archi
  */
 public class ZipArchiveOutputStream extends ArchiveOutputStream {
 
-    static final int BYTE_MASK = 0xFF;
-    private static final int SHORT = 2;
-    private static final int WORD = 4;
     static final int BUFFER_SIZE = 512;
 
     /** indicates if this archive is finished. protected for use in Jar implementation */
@@ -104,7 +110,7 @@ public class ZipArchiveOutputStream exte
     /**
      * Current entry.
      */
-    private ZipArchiveEntry entry;
+    private CurrentEntry entry;
 
     /**
      * The file comment.
@@ -130,7 +136,8 @@ public class ZipArchiveOutputStream exte
     /**
      * List of ZipArchiveEntries written so far.
      */
-    private final List entries = new LinkedList();
+    private final List<ZipArchiveEntry> entries =
+        new LinkedList<ZipArchiveEntry>();
 
     /**
      * CRC instance to avoid parsing DEFLATED data twice.
@@ -143,17 +150,6 @@ public class ZipArchiveOutputStream exte
     private long written = 0;
 
     /**
-     * Data for local header data
-     */
-    private long dataStart = 0;
-
-    /**
-     * Offset for CRC entry in the local file header data for the
-     * current entry starts here.
-     */
-    private long localDataStart = 0;
-
-    /**
      * Start of central directory.
      */
     private long cdOffset = 0;
@@ -176,7 +172,8 @@ public class ZipArchiveOutputStream exte
     /**
      * Holds the offsets of the LFH starts for each entry.
      */
-    private final Map offsets = new HashMap();
+    private final Map<ZipArchiveEntry, Long> offsets =
+        new HashMap<ZipArchiveEntry, Long>();
 
     /**
      * The encoding to use for filenames and the file comment.
@@ -232,6 +229,13 @@ public class ZipArchiveOutputStream exte
     private UnicodeExtraFieldPolicy createUnicodeExtraFields = UnicodeExtraFieldPolicy.NEVER;
 
     /**
+     * Whether anything inside this archive has used a ZIP64 feature.
+     *
+     * @since Apache Commons Compress 1.3
+     */
+    private boolean hasUsedZip64 = false;
+
+    /**
      * Creates a new ZIP OutputStream filtering the underlying stream.
      * @param out the outputstream to zip
      */
@@ -334,6 +338,7 @@ public class ZipArchiveOutputStream exte
     }
 
     /** {@inheritDoc} */
+    @Override
     public void finish() throws IOException {
         if (finished) {
             throw new IOException("This archive has already been finished");
@@ -344,10 +349,11 @@ public class ZipArchiveOutputStream exte
         }
 
         cdOffset = written;
-        for (Iterator i = entries.iterator(); i.hasNext(); ) {
-            writeCentralFileHeader((ZipArchiveEntry) i.next());
+        for (ZipArchiveEntry ze : entries) {
+            writeCentralFileHeader(ze);
         }
         cdLength = written - cdOffset;
+        writeZip64CentralDirectory();
         writeCentralDirectoryEnd();
         offsets.clear();
         entries.clear();
@@ -358,6 +364,7 @@ public class ZipArchiveOutputStream exte
      * Writes all necessary data for this entry.
      * @throws IOException on error
      */
+    @Override
     public void closeArchiveEntry() throws IOException {
         if (finished) {
             throw new IOException("Stream has already been finished");
@@ -370,56 +377,95 @@ public class ZipArchiveOutputStream exte
         long realCrc = crc.getValue();
         crc.reset();
 
-        if (entry.getMethod() == DEFLATED) {
+        if (entry.entry.getMethod() == DEFLATED) {
             def.finish();
             while (!def.finished()) {
                 deflate();
             }
 
-            entry.setSize(ZipUtil.adjustToLong(def.getTotalIn()));
-            entry.setCompressedSize(ZipUtil.adjustToLong(def.getTotalOut()));
-            entry.setCrc(realCrc);
+            /* It turns out def.getBytesRead() returns wrong values if
+             * the size exceeds 4 GB - no idea whether one can trust
+             * def.getBytesWritten()
+            entry.entry.setSize(def.getBytesRead());
+            */
+            entry.entry.setSize(entry.bytesRead);
+            entry.entry.setCompressedSize(def.getBytesWritten());
+            entry.entry.setCrc(realCrc);
 
             def.reset();
 
-            written += entry.getCompressedSize();
+            written += entry.entry.getCompressedSize();
         } else if (raf == null) {
-            if (entry.getCrc() != realCrc) {
+            if (entry.entry.getCrc() != realCrc) {
                 throw new ZipException("bad CRC checksum for entry "
-                                       + entry.getName() + ": "
-                                       + Long.toHexString(entry.getCrc())
+                                       + entry.entry.getName() + ": "
+                                       + Long.toHexString(entry.entry.getCrc())
                                        + " instead of "
                                        + Long.toHexString(realCrc));
             }
 
-            if (entry.getSize() != written - dataStart) {
+            if (entry.entry.getSize() != written - entry.dataStart) {
                 throw new ZipException("bad size for entry "
-                                       + entry.getName() + ": "
-                                       + entry.getSize()
+                                       + entry.entry.getName() + ": "
+                                       + entry.entry.getSize()
                                        + " instead of "
-                                       + (written - dataStart));
+                                       + (written - entry.dataStart));
             }
         } else { /* method is STORED and we used RandomAccessFile */
-            long size = written - dataStart;
+            long size = written - entry.dataStart;
 
-            entry.setSize(size);
-            entry.setCompressedSize(size);
-            entry.setCrc(realCrc);
+            entry.entry.setSize(size);
+            entry.entry.setCompressedSize(size);
+            entry.entry.setCrc(realCrc);
         }
 
         // If random access output, write the local file header containing
         // the correct CRC and compressed/uncompressed sizes
         if (raf != null) {
             long save = raf.getFilePointer();
+            boolean actuallyNeedsZip64 = entry.entry.getSize() >= ZIP64_MAGIC
+                || entry.entry.getCompressedSize() >= ZIP64_MAGIC;
+
+            raf.seek(entry.localDataStart);
+            writeOut(ZipLong.getBytes(entry.entry.getCrc()));
+            if (!hasZip64Extra(entry.entry) || !actuallyNeedsZip64) {
+                writeOut(ZipLong.getBytes(entry.entry.getCompressedSize()));
+                writeOut(ZipLong.getBytes(entry.entry.getSize()));
+            } else {
+                writeOut(ZipLong.ZIP64_MAGIC.getBytes());
+                writeOut(ZipLong.ZIP64_MAGIC.getBytes());
+            }
 
-            raf.seek(localDataStart);
-            writeOut(ZipLong.getBytes(entry.getCrc()));
-            writeOut(ZipLong.getBytes(entry.getCompressedSize()));
-            writeOut(ZipLong.getBytes(entry.getSize()));
+            if (hasZip64Extra(entry.entry)) {
+                // seek to ZIP64 extra, skip header and size information
+                raf.seek(entry.localDataStart + 3 * WORD + 2 * SHORT
+                         + getName(entry.entry).limit() + 2 * SHORT);
+                // inside the ZIP64 extra uncompressed size comes
+                // first, unlike the LFH, CD or data descriptor
+                writeOut(ZipEightByteInteger.getBytes(entry.entry.getSize()));
+                writeOut(ZipEightByteInteger.getBytes(entry.entry.getCompressedSize()));
+
+                if (!actuallyNeedsZip64) {
+                    // do some cleanup:
+                    // * rewrite version needed to extract
+                    raf.seek(entry.localDataStart  - 5 * SHORT);
+                    writeOut(ZipShort.getBytes(INITIAL_VERSION));
+
+                    // * remove ZIP64 extra so it doesn't get written
+                    //   to the central directory
+                    entry.entry.removeExtraField(Zip64ExtendedInformationExtraField
+                                                 .HEADER_ID);
+                    entry.entry.setExtra();
+
+                    // * reset hasUsedZip64 if it has been set because
+                    //   of this entry
+                    hasUsedZip64 &= !entry.causedUseOfZip64;
+                }
+            }
             raf.seek(save);
         }
 
-        writeDataDescriptor(entry);
+        writeDataDescriptor(entry.entry);
         entry = null;
     }
 
@@ -427,6 +473,7 @@ public class ZipArchiveOutputStream exte
      * {@inheritDoc} 
      * @throws ClassCastException if entry is not an instance of ZipArchiveEntry
      */
+    @Override
     public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException {
         if (finished) {
             throw new IOException("Stream has already been finished");
@@ -436,36 +483,61 @@ public class ZipArchiveOutputStream exte
             closeArchiveEntry();
         }
 
-        entry = ((ZipArchiveEntry) archiveEntry);
-        entries.add(entry);
+        entry = new CurrentEntry((ZipArchiveEntry) archiveEntry);
+        entries.add(entry.entry);
 
-        if (entry.getMethod() == -1) { // not specified
-            entry.setMethod(method);
+        if (entry.entry.getMethod() == -1) { // not specified
+            entry.entry.setMethod(method);
         }
 
-        if (entry.getTime() == -1) { // not specified
-            entry.setTime(System.currentTimeMillis());
+        if (entry.entry.getTime() == -1) { // not specified
+            entry.entry.setTime(System.currentTimeMillis());
         }
 
         // Size/CRC not required if RandomAccessFile is used
-        if (entry.getMethod() == STORED && raf == null) {
-            if (entry.getSize() == -1) {
+        if (entry.entry.getMethod() == STORED && raf == null) {
+            if (entry.entry.getSize() == ArchiveEntry.SIZE_UNKNOWN) {
                 throw new ZipException("uncompressed size is required for"
                                        + " STORED method when not writing to a"
                                        + " file");
             }
-            if (entry.getCrc() == -1) {
+            if (entry.entry.getCrc() == -1) {
                 throw new ZipException("crc checksum is required for STORED"
                                        + " method when not writing to a file");
             }
-            entry.setCompressedSize(entry.getSize());
+            entry.entry.setCompressedSize(entry.entry.getSize());
+        }
+
+        // add a ZIP64 extended information extra field if we already
+        // 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.entry.getSize() >= ZIP64_MAGIC
+            || entry.entry.getCompressedSize() >= ZIP64_MAGIC
+            || (entry.entry.getSize() == ArchiveEntry.SIZE_UNKNOWN
+                && raf != null)) {
+
+            Zip64ExtendedInformationExtraField z64 = getZip64Extra(entry.entry);
+            if (entry.entry.getMethod() == STORED
+                && entry.entry.getSize() != ArchiveEntry.SIZE_UNKNOWN) {
+                ZipEightByteInteger size =
+                    new ZipEightByteInteger(entry.entry.getSize());
+                z64.setSize(size);
+                z64.setCompressedSize(size);
+            } else {
+                // just a placeholder, real data will be in data
+                // descriptor or inserted later via RandomAccessFile
+                z64.setSize(ZipEightByteInteger.ZERO);
+                z64.setCompressedSize(ZipEightByteInteger.ZERO);
+            }
+            entry.entry.setExtra();
         }
 
-        if (entry.getMethod() == DEFLATED && hasCompressionLevelChanged) {
+        if (entry.entry.getMethod() == DEFLATED && hasCompressionLevelChanged) {
             def.setLevel(level);
             hasCompressionLevelChanged = false;
         }
-        writeLocalFileHeader(entry);
+        writeLocalFileHeader(entry.entry);
     }
 
     /**
@@ -511,6 +583,7 @@ public class ZipArchiveOutputStream exte
      * compression method that hasn't been implemented yet.</p>
      * @since Apache Commons Compress 1.1
      */
+    @Override
     public boolean canWriteEntryData(ArchiveEntry ae) {
         if (ae instanceof ZipArchiveEntry) {
             return ZipUtil.canHandleEntryData((ZipArchiveEntry) ae);
@@ -525,10 +598,12 @@ public class ZipArchiveOutputStream exte
      * @param length the number of bytes to write
      * @throws IOException on error
      */
+    @Override
     public void write(byte[] b, int offset, int length) throws IOException {
-        ZipUtil.checkRequestedFeatures(entry);
-        if (entry.getMethod() == DEFLATED) {
+        ZipUtil.checkRequestedFeatures(entry.entry);
+        if (entry.entry.getMethod() == DEFLATED) {
             if (length > 0 && !def.finished()) {
+                entry.bytesRead += length;
                 if (length <= DEFLATER_BLOCK_SIZE) {
                     def.setInput(b, offset, length);
                     deflateUntilInputIsNeeded();
@@ -560,6 +635,7 @@ public class ZipArchiveOutputStream exte
      *
      * @exception  IOException  if an I/O error occurs.
      */
+    @Override
     public void close() throws IOException {
         if (!finished) {
             finish();
@@ -579,6 +655,7 @@ public class ZipArchiveOutputStream exte
      *
      * @exception  IOException  if an I/O error occurs.
      */
+    @Override
     public void flush() throws IOException {
         if (out != null) {
             out.flush();
@@ -604,6 +681,14 @@ public class ZipArchiveOutputStream exte
      * end of central dir signature
      */
     static final byte[] EOCD_SIG = ZipLong.getBytes(0X06054B50L);
+    /**
+     * ZIP64 end of central dir signature
+     */
+    static final byte[] ZIP64_EOCD_SIG = ZipLong.getBytes(0X06064B50L);
+    /**
+     * ZIP64 end of central dir locator signature
+     */
+    static final byte[] ZIP64_EOCD_LOC_SIG = ZipLong.getBytes(0X07064B50L);
 
     /**
      * Writes next block of compressed data to the output stream.
@@ -624,16 +709,7 @@ public class ZipArchiveOutputStream exte
     protected void writeLocalFileHeader(ZipArchiveEntry ze) throws IOException {
 
         boolean encodable = zipEncoding.canEncode(ze.getName());
-
-        final ZipEncoding entryEncoding;
-
-        if (!encodable && fallbackToUTF8) {
-            entryEncoding = ZipEncodingHelper.UTF8_ZIP_ENCODING;
-        } else {
-            entryEncoding = zipEncoding;
-        }
-
-        ByteBuffer name = entryEncoding.encode(ze.getName());
+        ByteBuffer name = getName(ze);
 
         if (createUnicodeExtraFields != UnicodeExtraFieldPolicy.NEVER) {
 
@@ -648,11 +724,11 @@ public class ZipArchiveOutputStream exte
             String comm = ze.getComment();
             if (comm != null && !"".equals(comm)) {
 
-                boolean commentEncodable = this.zipEncoding.canEncode(comm);
+                boolean commentEncodable = zipEncoding.canEncode(comm);
 
                 if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS
                     || !commentEncodable) {
-                    ByteBuffer commentB = entryEncoding.encode(comm);
+                    ByteBuffer commentB = getEntryEncoding(ze).encode(comm);
                     ze.addExtraField(new UnicodeCommentExtraField(comm,
                                                                   commentB.array(),
                                                                   commentB.arrayOffset(),
@@ -662,7 +738,7 @@ public class ZipArchiveOutputStream exte
             }
         }
 
-        offsets.put(ze, ZipLong.getBytes(written));
+        offsets.put(ze, Long.valueOf(written));
 
         writeOut(LFH_SIG);
         written += WORD;
@@ -672,7 +748,8 @@ public class ZipArchiveOutputStream exte
 
         writeVersionNeededToExtractAndGeneralPurposeBits(zipMethod,
                                                          !encodable
-                                                         && fallbackToUTF8);
+                                                         && fallbackToUTF8,
+                                                         hasZip64Extra(ze));
         written += WORD;
 
         // compression method
@@ -686,15 +763,16 @@ public class ZipArchiveOutputStream exte
         // CRC
         // compressed length
         // uncompressed length
-        localDataStart = written;
+        entry.localDataStart = written;
         if (zipMethod == DEFLATED || raf != null) {
             writeOut(LZERO);
             writeOut(LZERO);
             writeOut(LZERO);
         } else {
             writeOut(ZipLong.getBytes(ze.getCrc()));
-            writeOut(ZipLong.getBytes(ze.getSize()));
-            writeOut(ZipLong.getBytes(ze.getSize()));
+            byte[] size = ZipLong.getBytes(Math.min(ze.getSize(), ZIP64_MAGIC));
+            writeOut(size);
+            writeOut(size);
         }
         // CheckStyle:MagicNumber OFF
         written += 12;
@@ -717,7 +795,7 @@ public class ZipArchiveOutputStream exte
         writeOut(extra);
         written += extra.length;
 
-        dataStart = written;
+        entry.dataStart = written;
     }
 
     /**
@@ -730,12 +808,17 @@ public class ZipArchiveOutputStream exte
             return;
         }
         writeOut(DD_SIG);
-        writeOut(ZipLong.getBytes(entry.getCrc()));
-        writeOut(ZipLong.getBytes(entry.getCompressedSize()));
-        writeOut(ZipLong.getBytes(entry.getSize()));
-        // CheckStyle:MagicNumber OFF
-        written += 16;
-        // CheckStyle:MagicNumber ON
+        writeOut(ZipLong.getBytes(ze.getCrc()));
+        int sizeFieldSize = WORD;
+        if (!hasZip64Extra(ze)) {
+            writeOut(ZipLong.getBytes(ze.getCompressedSize()));
+            writeOut(ZipLong.getBytes(ze.getSize()));
+        } else {
+            sizeFieldSize = DWORD;
+            writeOut(ZipEightByteInteger.getBytes(ze.getCompressedSize()));
+            writeOut(ZipEightByteInteger.getBytes(ze.getSize()));
+        }
+        written += 2 * WORD + 2 * sizeFieldSize;
     }
 
     /**
@@ -747,16 +830,41 @@ public class ZipArchiveOutputStream exte
         writeOut(CFH_SIG);
         written += WORD;
 
+        final long lfhOffset = offsets.get(ze).longValue();
+        final boolean needsZip64Extra = ze.getCompressedSize() >= ZIP64_MAGIC
+            || ze.getSize() >= ZIP64_MAGIC
+            || lfhOffset >= ZIP64_MAGIC;
+
+        if (needsZip64Extra) {
+            Zip64ExtendedInformationExtraField z64 = getZip64Extra(ze);
+            if (ze.getCompressedSize() >= ZIP64_MAGIC
+                || ze.getSize() >= ZIP64_MAGIC) {
+                z64.setCompressedSize(new ZipEightByteInteger(ze.getCompressedSize()));
+                z64.setSize(new ZipEightByteInteger(ze.getSize()));
+            } else {
+                // reset value that may have been set for LFH
+                z64.setCompressedSize(null);
+                z64.setSize(null);
+            }
+            if (lfhOffset >= ZIP64_MAGIC) {
+                z64.setRelativeHeaderOffset(new ZipEightByteInteger(lfhOffset));
+            }
+            ze.setExtra();
+        }
+
         // version made by
         // CheckStyle:MagicNumber OFF
-        writeOut(ZipShort.getBytes((ze.getPlatform() << 8) | 20));
+        writeOut(ZipShort.getBytes((ze.getPlatform() << 8) | 
+                                   (!hasUsedZip64 ? DATA_DESCRIPTOR_MIN_VERSION
+                                                  : ZIP64_MIN_VERSION)));
         written += SHORT;
 
         final int zipMethod = ze.getMethod();
         final boolean encodable = zipEncoding.canEncode(ze.getName());
         writeVersionNeededToExtractAndGeneralPurposeBits(zipMethod,
                                                          !encodable
-                                                         && fallbackToUTF8);
+                                                         && fallbackToUTF8,
+                                                         needsZip64Extra);
         written += WORD;
 
         // compression method
@@ -771,22 +879,19 @@ public class ZipArchiveOutputStream exte
         // compressed length
         // uncompressed length
         writeOut(ZipLong.getBytes(ze.getCrc()));
-        writeOut(ZipLong.getBytes(ze.getCompressedSize()));
-        writeOut(ZipLong.getBytes(ze.getSize()));
+        if (ze.getCompressedSize() >= ZIP64_MAGIC
+            || ze.getSize() >= ZIP64_MAGIC) {
+            writeOut(ZipLong.ZIP64_MAGIC.getBytes());
+            writeOut(ZipLong.ZIP64_MAGIC.getBytes());
+        } else {
+            writeOut(ZipLong.getBytes(ze.getCompressedSize()));
+            writeOut(ZipLong.getBytes(ze.getSize()));
+        }
         // CheckStyle:MagicNumber OFF
         written += 12;
         // CheckStyle:MagicNumber ON
 
-        // file name length
-        final ZipEncoding entryEncoding;
-
-        if (!encodable && fallbackToUTF8) {
-            entryEncoding = ZipEncodingHelper.UTF8_ZIP_ENCODING;
-        } else {
-            entryEncoding = zipEncoding;
-        }
-
-        ByteBuffer name = entryEncoding.encode(ze.getName());
+        ByteBuffer name = getName(ze);
 
         writeOut(ZipShort.getBytes(name.limit()));
         written += SHORT;
@@ -802,7 +907,7 @@ public class ZipArchiveOutputStream exte
             comm = "";
         }
 
-        ByteBuffer commentB = entryEncoding.encode(comm);
+        ByteBuffer commentB = getEntryEncoding(ze).encode(comm);
 
         writeOut(ZipShort.getBytes(commentB.limit()));
         written += SHORT;
@@ -820,7 +925,7 @@ public class ZipArchiveOutputStream exte
         written += WORD;
 
         // relative offset of LFH
-        writeOut((byte[]) offsets.get(ze));
+        writeOut(ZipLong.getBytes(Math.min(lfhOffset, ZIP64_MAGIC)));
         written += WORD;
 
         // file name
@@ -848,13 +953,14 @@ public class ZipArchiveOutputStream exte
         writeOut(ZERO);
 
         // number of entries
-        byte[] num = ZipShort.getBytes(entries.size());
+        byte[] num = ZipShort.getBytes(Math.min(entries.size(),
+                                                ZIP64_MAGIC_SHORT));
         writeOut(num);
         writeOut(num);
 
         // length and location of CD
-        writeOut(ZipLong.getBytes(cdLength));
-        writeOut(ZipLong.getBytes(cdOffset));
+        writeOut(ZipLong.getBytes(Math.min(cdLength, ZIP64_MAGIC)));
+        writeOut(ZipLong.getBytes(Math.min(cdOffset, ZIP64_MAGIC)));
 
         // ZIP file comment
         ByteBuffer data = this.zipEncoding.encode(comment);
@@ -862,6 +968,73 @@ public class ZipArchiveOutputStream exte
         writeOut(data.array(), data.arrayOffset(), data.limit());
     }
 
+    private static final byte[] ONE = ZipLong.getBytes(1L);
+
+    /**
+     * Writes the &quot;ZIP64 End of central dir record&quot; and
+     * &quot;ZIP64 End of central dir locator&quot;.
+     * @throws IOException on error
+     * @since Apache Commons Compress 1.3
+     */
+    protected void writeZip64CentralDirectory() throws IOException {
+        if (!hasUsedZip64) {
+            if (cdOffset >= ZIP64_MAGIC || cdLength >= ZIP64_MAGIC
+                || entries.size() >= ZIP64_MAGIC_SHORT) {
+                // actually "will use"
+                hasUsedZip64 = true;
+            }
+        }
+
+        if (!hasUsedZip64) {
+            return;
+        }
+
+        long offset = written;
+
+        writeOut(ZIP64_EOCD_SIG);
+        // size, we don't have any variable length as we don't support
+        // the extensible data sector, yet
+        writeOut(ZipEightByteInteger
+                 .getBytes(SHORT   /* version made by */
+                           + SHORT /* version needed to extract */
+                           + WORD  /* disk number */
+                           + WORD  /* disk with central directory */
+                           + DWORD /* number of entries in CD on this disk */
+                           + DWORD /* total number of entries */
+                           + DWORD /* size of CD */
+                           + DWORD /* offset of CD */
+                           ));
+
+        // version made by and version needed to extract
+        writeOut(ZipShort.getBytes(ZIP64_MIN_VERSION));
+        writeOut(ZipShort.getBytes(ZIP64_MIN_VERSION));
+
+        // disk numbers - four bytes this time
+        writeOut(LZERO);
+        writeOut(LZERO);
+
+        // number of entries
+        byte[] num = ZipEightByteInteger.getBytes(entries.size());
+        writeOut(num);
+        writeOut(num);
+
+        // length and location of CD
+        writeOut(ZipEightByteInteger.getBytes(cdLength));
+        writeOut(ZipEightByteInteger.getBytes(cdOffset));
+
+        // no "zip64 extensible data sector" for now
+
+        // and now the "ZIP64 end of central directory locator"
+        writeOut(ZIP64_EOCD_LOC_SIG);
+
+        // disk number holding the ZIP64 EOCD record
+        writeOut(LZERO);
+        // relative offset of ZIP64 EOCD record
+        writeOut(ZipEightByteInteger.getBytes(offset));
+        // total number of disks
+        writeOut(ONE);
+    }
+
     /**
      * Write bytes to output or random access file.
      * @param data the byte array to write
@@ -896,19 +1069,24 @@ public class ZipArchiveOutputStream exte
     private void writeVersionNeededToExtractAndGeneralPurposeBits(final int
                                                                   zipMethod,
                                                                   final boolean
-                                                                  utfFallback)
+                                                                  utfFallback,
+                                                                  final boolean
+                                                                  zip64)
         throws IOException {
 
         // CheckStyle:MagicNumber OFF
-        int versionNeededToExtract = 10;
+        int versionNeededToExtract = INITIAL_VERSION;
         GeneralPurposeBit b = new GeneralPurposeBit();
         b.useUTF8ForNames(useUTF8Flag || utfFallback);
         if (zipMethod == DEFLATED && raf == null) {
             // requires version 2 as we are going to store length info
             // in the data descriptor
-            versionNeededToExtract =  20;
+            versionNeededToExtract = DATA_DESCRIPTOR_MIN_VERSION;
             b.useDataDescriptor(true);
         }
+        if (zip64) {
+            versionNeededToExtract = ZIP64_MIN_VERSION;
+        }
         // CheckStyle:MagicNumber ON
 
         // version needed to extract
@@ -918,6 +1096,80 @@ public class ZipArchiveOutputStream exte
     }
 
     /**
+     * Creates a new zip entry taking some information from the given
+     * file and using the provided name.
+     *
+     * <p>The name will be adjusted to end with a forward slash "/" if
+     * the file is a directory.  If the file is not a directory a
+     * potential trailing forward slash will be stripped from the
+     * entry name.</p>
+     *
+     * <p>Must not be used if the stream has already been closed.</p>
+     */
+    @Override
+    public ArchiveEntry createArchiveEntry(File inputFile, String entryName)
+            throws IOException {
+        if (finished) {
+            throw new IOException("Stream has already been finished");
+        }
+        return new ZipArchiveEntry(inputFile, entryName);
+    }
+
+    /**
+     * Get the existing ZIP64 extended information extra field or
+     * create a new one and add it to the entry.
+     *
+     * @since Apache Commons Compress 1.3
+     */
+    private Zip64ExtendedInformationExtraField
+        getZip64Extra(ZipArchiveEntry ze) {
+        if (entry != null) {
+            entry.causedUseOfZip64 = !hasUsedZip64;
+        }
+        hasUsedZip64 = true;
+        Zip64ExtendedInformationExtraField z64 =
+            (Zip64ExtendedInformationExtraField)
+            ze.getExtraField(Zip64ExtendedInformationExtraField
+                             .HEADER_ID);
+        if (z64 == null) {
+            /*
+            System.err.println("Adding z64 for " + ze.getName()
+                               + ", method: " + ze.getMethod()
+                               + " (" + (ze.getMethod() == STORED) + ")"
+                               + ", raf: " + (raf != null));
+            */
+            z64 = new Zip64ExtendedInformationExtraField();
+        }
+
+        // even if the field is there already, make sure it is the first one
+        ze.addAsFirstExtraField(z64);
+
+        return z64;
+    }
+
+    /**
+     * Is there a ZIP64 extended information extra field for the
+     * entry?
+     *
+     * @since Apache Commons Compress 1.3
+     */
+    private boolean hasZip64Extra(ZipArchiveEntry ze) {
+        return ze.getExtraField(Zip64ExtendedInformationExtraField
+                                .HEADER_ID)
+            != null;
+    }
+
+    private ZipEncoding getEntryEncoding(ZipArchiveEntry ze) {
+        boolean encodable = zipEncoding.canEncode(ze.getName());
+        return !encodable && fallbackToUTF8
+            ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
+    }
+
+    private ByteBuffer getName(ZipArchiveEntry ze) throws IOException {
+        return getEntryEncoding(ze).encode(ze.getName());
+    }
+
+    /**
      * enum that represents the possible policies for creating Unicode
      * extra fields.
      */
@@ -947,21 +1199,35 @@ public class ZipArchiveOutputStream exte
     }
 
     /**
-     * Creates a new zip entry taking some information from the given
-     * file and using the provided name.
-     *
-     * <p>The name will be adjusted to end with a forward slash "/" if
-     * the file is a directory.  If the file is not a directory a
-     * potential trailing forward slash will be stripped from the
-     * entry name.</p>
-     *
-     * <p>Must not be used if the stream has already been closed.</p>
+     * Structure collecting information for the entry that is
+     * currently being written.
      */
-    public ArchiveEntry createArchiveEntry(File inputFile, String entryName)
-            throws IOException {
-        if (finished) {
-            throw new IOException("Stream has already been finished");
+    private static final class CurrentEntry {
+        private CurrentEntry(ZipArchiveEntry entry) {
+            this.entry = entry;
         }
-        return new ZipArchiveEntry(inputFile, entryName);
+        /**
+         * Current ZIP entry.
+         */
+        private final ZipArchiveEntry entry;
+        /**
+         * Offset for CRC entry in the local file header data for the
+         * current entry starts here.
+         */
+        private long localDataStart = 0;
+        /**
+         * Data for local header data
+         */
+        private long dataStart = 0;
+        /**
+         * Number of bytes read for the current entry (can't rely on
+         * Deflater#getBytesRead) when using DEFLATED.
+         */
+        private long bytesRead = 0;
+        /**
+         * Whether current entry was the first one using ZIP64 features.
+         */
+        private boolean causedUseOfZip64 = false;
     }
+
 }

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -0,0 +1 @@
+/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java:1149597-1152684

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java Mon Aug  1 04:09:10 2011
@@ -19,6 +19,8 @@ package org.apache.commons.compress.arch
 
 import java.math.BigInteger;
 
+import static org.apache.commons.compress.archivers.zip.ZipConstants.BYTE_MASK;
+
 /**
  * Utility class that represents an eight byte integer with conversion
  * rules for the big endian byte order of ZIP files.
@@ -28,8 +30,6 @@ import java.math.BigInteger;
  */
 public final class ZipEightByteInteger {
 
-    private static final int BYTE_MASK = 0xFF;
-
     private static final int BYTE_1 = 1;
     private static final int BYTE_1_MASK = 0xFF00;
     private static final int BYTE_1_SHIFT = 8;
@@ -63,6 +63,8 @@ public final class ZipEightByteInteger {
 
     private final BigInteger value;
 
+    public static ZipEightByteInteger ZERO = new ZipEightByteInteger(0);
+
     /**
      * Create instance from a number.
      * @param value the long to store as a ZipEightByteInteger
@@ -206,6 +208,7 @@ public final class ZipEightByteInteger {
      * @param o an object to compare
      * @return true if the objects are equal
      */
+    @Override
     public boolean equals(Object o) {
         if (o == null || !(o instanceof ZipEightByteInteger)) {
             return false;
@@ -217,10 +220,12 @@ public final class ZipEightByteInteger {
      * Override to make two instances with same value equal.
      * @return the hashCode of the value stored in the ZipEightByteInteger
      */
+    @Override
     public int hashCode() {
         return value.hashCode();
     }
 
+    @Override
     public String toString() {
         return "ZipEightByteInteger value: " + value;
     }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java Mon Aug  1 04:09:10 2011
@@ -62,10 +62,10 @@ abstract class ZipEncodingHelper {
         }
     }
 
-    private static final Map simpleEncodings;
+    private static final Map<String, SimpleEncodingHolder> simpleEncodings;
 
     static {
-        simpleEncodings = new HashMap();
+        simpleEncodings = new HashMap<String, SimpleEncodingHolder>();
 
         char[] cp437_high_chars =
             new char[] { 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0,
@@ -218,8 +218,7 @@ abstract class ZipEncodingHelper {
             return new FallbackZipEncoding();
         }
 
-        SimpleEncodingHolder h =
-            (SimpleEncodingHolder) simpleEncodings.get(name);
+        SimpleEncodingHolder h = simpleEncodings.get(name);
 
         if (h!=null) {
             return h.getEncoding();

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java:738844,738853,739300,741089,747002,1146020
+/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java:1149597-1152684

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java Mon Aug  1 04:09:10 2011
@@ -17,6 +17,9 @@
  */
 package org.apache.commons.compress.archivers.zip;
 
+import static org.apache.commons.compress.archivers.zip.ZipConstants.BYTE_MASK;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
+
 /**
  * Utility class that represents a four byte integer with conversion
  * rules for the big endian byte order of ZIP files.
@@ -24,9 +27,7 @@ package org.apache.commons.compress.arch
  */
 public final class ZipLong implements Cloneable {
 
-    private static final int WORD = 4;
     //private static final int BYTE_BIT_SIZE = 8;
-    private static final int BYTE_MASK = 0xFF;
 
     private static final int BYTE_1 = 1;
     private static final int BYTE_1_MASK = 0xFF00;
@@ -55,6 +56,13 @@ public final class ZipLong implements Cl
     public static final ZipLong DD_SIG = new ZipLong(0X08074B50L);
 
     /**
+     * Value stored in size and similar fields if ZIP64 extensions are
+     * used.
+     * @since Apache Commons Compress 1.3
+     */
+    static final ZipLong ZIP64_MAGIC = new ZipLong(ZipConstants.ZIP64_MAGIC);
+
+    /**
      * Create instance from a number.
      * @param value the long to store as a ZipLong
      */
@@ -137,6 +145,7 @@ public final class ZipLong implements Cl
      * @param o an object to compare
      * @return true if the objects are equal
      */
+    @Override
     public boolean equals(Object o) {
         if (o == null || !(o instanceof ZipLong)) {
             return false;
@@ -148,10 +157,12 @@ public final class ZipLong implements Cl
      * Override to make two instances with same value equal.
      * @return the value stored in the ZipLong
      */
+    @Override
     public int hashCode() {
         return (int) value;
     }
 
+    @Override
     public Object clone() {
         try {
             return super.clone();
@@ -161,6 +172,7 @@ public final class ZipLong implements Cl
         }
     }
 
+    @Override
     public String toString() {
         return "ZipLong value: " + value;
     }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipShort.java Mon Aug  1 04:09:10 2011
@@ -17,13 +17,14 @@
  */
 package org.apache.commons.compress.archivers.zip;
 
+import static org.apache.commons.compress.archivers.zip.ZipConstants.BYTE_MASK;
+
 /**
  * Utility class that represents a two byte integer with conversion
  * rules for the big endian byte order of ZIP files.
  * @Immutable
  */
 public final class ZipShort implements Cloneable {
-    private static final int BYTE_MASK = 0xFF;
     private static final int BYTE_1_MASK = 0xFF00;
     private static final int BYTE_1_SHIFT = 8;
 
@@ -111,6 +112,7 @@ public final class ZipShort implements C
      * @param o an object to compare
      * @return true if the objects are equal
      */
+    @Override
     public boolean equals(Object o) {
         if (o == null || !(o instanceof ZipShort)) {
             return false;
@@ -122,10 +124,12 @@ public final class ZipShort implements C
      * Override to make two instances with same value equal.
      * @return the value stored in the ZipShort
      */
+    @Override
     public int hashCode() {
         return value;
     }
 
+    @Override
     public Object clone() {
         try {
             return super.clone();
@@ -135,6 +139,7 @@ public final class ZipShort implements C
         }
     }
 
+    @Override
     public String toString() {
         return "ZipShort value: " + value;
     }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java Mon Aug  1 04:09:10 2011
@@ -69,6 +69,10 @@ public abstract class ZipUtil {
     /**
      * Assumes a negative integer really is a positive integer that
      * has wrapped around and re-creates the original value.
+     *
+     * <p>This methods is no longer used as of Apache Commons Compress
+     * 1.3</p>
+     *
      * @param i the value to treat as unsigned int.
      * @return the unsigned int as a long.
      */

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -1 +1,2 @@
 /ant/core/trunk/src/main/org/apache/tools/bzip2/CBZip2OutputStream.java:741089
+/commons/proper/compress/branches/zip64/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java:1149597-1152684

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java?rev=1152687&r1=1152686&r2=1152687&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java (original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java Mon Aug  1 04:09:10 2011
@@ -148,6 +148,20 @@ public class Zip64ExtendedInformationExt
         assertEquals(DISK, f.getDiskStartNumber());
     }
 
+    public void testReadCDSizesAndOffset() throws ZipException {
+        Zip64ExtendedInformationExtraField f =
+            new Zip64ExtendedInformationExtraField();
+        byte[] b = new byte[24];
+        System.arraycopy(SIZE.getBytes(), 0, b, 0, 8);
+        System.arraycopy(CSIZE.getBytes(), 0, b, 8, 8);
+        System.arraycopy(OFF.getBytes(), 0, b, 16, 8);
+        f.parseFromCentralDirectoryData(b, 0, b.length);
+        assertEquals(SIZE, f.getSize());
+        assertEquals(CSIZE, f.getCompressedSize());
+        assertEquals(OFF, f.getRelativeHeaderOffset());
+        assertNull(f.getDiskStartNumber());
+    }
+
     public void testReadCDSomethingAndDisk() throws ZipException {
         Zip64ExtendedInformationExtraField f =
             new Zip64ExtendedInformationExtraField();

Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Aug  1 04:09:10 2011
@@ -1 +1,2 @@
 /ant/core/trunk/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java:745537
+/commons/proper/compress/branches/zip64/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntryTest.java:1149597-1152684



Mime
View raw message