Return-Path: X-Original-To: apmail-ant-notifications-archive@minotaur.apache.org Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 385FB9A9E for ; Mon, 4 Jun 2012 16:35:33 +0000 (UTC) Received: (qmail 37844 invoked by uid 500); 4 Jun 2012 16:35:32 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 37794 invoked by uid 500); 4 Jun 2012 16:35:32 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 37787 invoked by uid 99); 4 Jun 2012 16:35:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Jun 2012 16:35:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Jun 2012 16:35:28 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C3C8323889E0 for ; Mon, 4 Jun 2012 16:35:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1346025 [1/3] - in /ant/core/trunk: ./ src/main/org/apache/tools/zip/ src/tests/junit/org/apache/tools/ant/taskdefs/ src/tests/junit/org/apache/tools/zip/ Date: Mon, 04 Jun 2012 16:35:07 -0000 To: notifications@ant.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120604163508.C3C8323889E0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bodewig Date: Mon Jun 4 16:35:06 2012 New Revision: 1346025 URL: http://svn.apache.org/viewvc?rev=1346025&view=rev Log: merge Zip64 support from Commons Compress Added: ant/core/trunk/src/main/org/apache/tools/zip/GeneralPurposeBit.java - copied, changed from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java ant/core/trunk/src/main/org/apache/tools/zip/UnsupportedZipFeatureException.java - copied, changed from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java ant/core/trunk/src/main/org/apache/tools/zip/Zip64ExtendedInformationExtraField.java - copied, changed from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java ant/core/trunk/src/main/org/apache/tools/zip/Zip64Mode.java - copied, changed from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64Mode.java ant/core/trunk/src/main/org/apache/tools/zip/Zip64RequiredException.java - copied, changed from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64RequiredException.java ant/core/trunk/src/main/org/apache/tools/zip/ZipConstants.java - copied, changed from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java ant/core/trunk/src/main/org/apache/tools/zip/ZipEightByteInteger.java - copied, changed from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java Modified: ant/core/trunk/WHATSNEW ant/core/trunk/src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java ant/core/trunk/src/main/org/apache/tools/zip/AsiExtraField.java ant/core/trunk/src/main/org/apache/tools/zip/ExtraFieldUtils.java ant/core/trunk/src/main/org/apache/tools/zip/FallbackZipEncoding.java ant/core/trunk/src/main/org/apache/tools/zip/Simple8BitZipEncoding.java ant/core/trunk/src/main/org/apache/tools/zip/UnicodeCommentExtraField.java ant/core/trunk/src/main/org/apache/tools/zip/UnicodePathExtraField.java ant/core/trunk/src/main/org/apache/tools/zip/UnparseableExtraFieldData.java ant/core/trunk/src/main/org/apache/tools/zip/ZipEncoding.java ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java ant/core/trunk/src/main/org/apache/tools/zip/ZipLong.java ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java ant/core/trunk/src/main/org/apache/tools/zip/ZipShort.java ant/core/trunk/src/main/org/apache/tools/zip/ZipUtil.java ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java ant/core/trunk/src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java ant/core/trunk/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java Modified: ant/core/trunk/WHATSNEW URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/WHATSNEW (original) +++ ant/core/trunk/WHATSNEW Mon Jun 4 16:35:06 2012 @@ -9,7 +9,6 @@ Changes that could break older environme the task now really leaves the EOL characters alone. This also implies that EOL ASIS will not insert a newline even if fixlast is set to true. Bugzilla report 53036 - Fixed bugs: ----------- @@ -34,6 +33,10 @@ Fixed bugs: Other changes: -------------- +* merged the ZIP package from Commons Compress, it can now read + archives using Zip64 extensions (files and archives bigger that 4GB + and with more that 64k entries). + Changes from Ant 1.8.3 TO Ant 1.8.4 =================================== Modified: ant/core/trunk/src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java Mon Jun 4 16:35:06 2012 @@ -105,24 +105,42 @@ public abstract class AbstractUnicodeExt * @return The utf-8 encoded name. */ public byte[] getUnicodeName() { - return unicodeName; + byte[] b = null; + if (unicodeName != null) { + b = new byte[unicodeName.length]; + System.arraycopy(unicodeName, 0, b, 0, b.length); + } + return b; } /** * @param unicodeName The utf-8 encoded name to set. */ public void setUnicodeName(byte[] unicodeName) { - this.unicodeName = unicodeName; + if (unicodeName != null) { + this.unicodeName = new byte[unicodeName.length]; + System.arraycopy(unicodeName, 0, this.unicodeName, 0, + unicodeName.length); + } else { + this.unicodeName = null; + } data = null; } + /** {@inheritDoc} */ public byte[] getCentralDirectoryData() { if (data == null) { this.assembleData(); } - return data; + byte[] b = null; + if (data != null) { + b = new byte[data.length]; + System.arraycopy(data, 0, b, 0, b.length); + } + return b; } + /** {@inheritDoc} */ public ZipShort getCentralDirectoryLength() { if (data == null) { assembleData(); @@ -130,14 +148,17 @@ public abstract class AbstractUnicodeExt return new ZipShort(data.length); } + /** {@inheritDoc} */ public byte[] getLocalFileDataData() { return getCentralDirectoryData(); } + /** {@inheritDoc} */ public ZipShort getLocalFileDataLength() { return getCentralDirectoryLength(); } + /** {@inheritDoc} */ public void parseFromLocalFileData(byte[] buffer, int offset, int length) throws ZipException { Modified: ant/core/trunk/src/main/org/apache/tools/zip/AsiExtraField.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/AsiExtraField.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/AsiExtraField.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/AsiExtraField.java Mon Jun 4 16:35:06 2012 @@ -45,6 +45,9 @@ import java.util.zip.ZipException; *

Short is two bytes and Long is four bytes in big endian byte and * word order, device numbers are currently not supported.

* + *

Since the documentation this class is based upon doesn't mention + * the character encoding of the file name at all, it is assumed that + * it uses the current platform's default encoding.

*/ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { @@ -116,6 +119,7 @@ public class AsiExtraField implements Zi + 2 // UID + 2 // GID + getLinkedFile().getBytes().length); + // Uses default charset - see class Javadoc } /** @@ -138,7 +142,7 @@ public class AsiExtraField implements Zi byte[] data = new byte[getLocalFileDataLength().getValue() - WORD]; System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2); - byte[] linkArray = getLinkedFile().getBytes(); + byte[] linkArray = getLinkedFile().getBytes(); // Uses default charset - see class Javadoc // CheckStyle:MagicNumber OFF System.arraycopy(ZipLong.getBytes(linkArray.length), 0, data, 2, WORD); @@ -311,7 +315,7 @@ public class AsiExtraField implements Zi link = ""; } else { System.arraycopy(tmp, 10, linkArray, 0, linkArray.length); - link = new String(linkArray); + link = new String(linkArray); // Uses default charset - see class Javadoc } // CheckStyle:MagicNumber ON setDirectory((newMode & DIR_FLAG) != 0); @@ -334,6 +338,7 @@ public class AsiExtraField implements Zi return type | (mode & PERM_MASK); } + @Override public Object clone() { try { AsiExtraField cloned = (AsiExtraField) super.clone(); Modified: ant/core/trunk/src/main/org/apache/tools/zip/ExtraFieldUtils.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ExtraFieldUtils.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/ExtraFieldUtils.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/ExtraFieldUtils.java Mon Jun 4 16:35:06 2012 @@ -38,14 +38,15 @@ public class ExtraFieldUtils { * * @since 1.1 */ - private static final Map implementations; + private static final Map> implementations; static { - implementations = new HashMap(); + implementations = new HashMap>(); register(AsiExtraField.class); register(JarMarker.class); register(UnicodePathExtraField.class); register(UnicodeCommentExtraField.class); + register(Zip64ExtendedInformationExtraField.class); } /** @@ -57,7 +58,7 @@ public class ExtraFieldUtils { * * @since 1.1 */ - public static void register(Class c) { + public static void register(Class c) { try { ZipExtraField ze = (ZipExtraField) c.newInstance(); implementations.put(ze.getHeaderId(), c); @@ -81,7 +82,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(); } @@ -132,7 +133,7 @@ public class ExtraFieldUtils { public static ZipExtraField[] parse(byte[] data, boolean local, UnparseableExtraField onUnparseableData) throws ZipException { - List v = new ArrayList(); + List v = new ArrayList(); int start = 0; LOOP: while (start <= data.length - WORD) { @@ -158,7 +159,7 @@ public class ExtraFieldUtils { data.length - start); } v.add(field); - /*FALLTHROUGH*/ + //$FALL-THROUGH$ case UnparseableExtraField.SKIP_KEY: // since we cannot parse the data we must assume // the extra field consumes the whole rest of the @@ -189,7 +190,7 @@ public class ExtraFieldUtils { } ZipExtraField[] result = new ZipExtraField[v.size()]; - return (ZipExtraField[]) v.toArray(result); + return v.toArray(result); } /** @@ -205,8 +206,8 @@ public class ExtraFieldUtils { lastIsUnparseableHolder ? data.length - 1 : data.length; int sum = WORD * regularExtraFieldCount; - for (int i = 0; i < data.length; i++) { - sum += data[i].getLocalFileDataLength().getValue(); + for (ZipExtraField element : data) { + sum += element.getLocalFileDataLength().getValue(); } byte[] result = new byte[sum]; @@ -240,8 +241,8 @@ public class ExtraFieldUtils { lastIsUnparseableHolder ? data.length - 1 : data.length; int sum = WORD * regularExtraFieldCount; - for (int i = 0; i < data.length; i++) { - sum += data[i].getCentralDirectoryLength().getValue(); + for (ZipExtraField element : data) { + sum += element.getCentralDirectoryLength().getValue(); } byte[] result = new byte[sum]; int start = 0; Modified: ant/core/trunk/src/main/org/apache/tools/zip/FallbackZipEncoding.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/FallbackZipEncoding.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/FallbackZipEncoding.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/FallbackZipEncoding.java Mon Jun 4 16:35:06 2012 @@ -30,7 +30,7 @@ import java.nio.ByteBuffer; * marks leading to unreadable ZIP entries on some operating * systems.

* - *

Furthermore this implementation is unable to tell, whether a + *

Furthermore this implementation is unable to tell whether a * given name can be safely encoded or not.

* *

This implementation acts as a last resort implementation, when @@ -53,7 +53,7 @@ class FallbackZipEncoding implements Zip /** * Construct a fallback zip encoding, which uses the given charset. * - * @param charset The name of the charset or null for + * @param charset The name of the charset or {@code null} for * the platform's default character set. */ public FallbackZipEncoding(String charset) { @@ -73,7 +73,7 @@ class FallbackZipEncoding implements Zip * org.apache.tools.zip.ZipEncoding#encode(java.lang.String) */ public ByteBuffer encode(String name) throws IOException { - if (this.charset == null) { + if (this.charset == null) { // i.e. use default charset, see no-args constructor return ByteBuffer.wrap(name.getBytes()); } else { return ByteBuffer.wrap(name.getBytes(this.charset)); @@ -85,7 +85,7 @@ class FallbackZipEncoding implements Zip * org.apache.tools.zip.ZipEncoding#decode(byte[]) */ public String decode(byte[] data) throws IOException { - if (this.charset == null) { + if (this.charset == null) { // i.e. use default charset, see no-args constructor return new String(data); } else { return new String(data,this.charset); Copied: ant/core/trunk/src/main/org/apache/tools/zip/GeneralPurposeBit.java (from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java) URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/GeneralPurposeBit.java?p2=ant/core/trunk/src/main/org/apache/tools/zip/GeneralPurposeBit.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java&r1=1345686&r2=1346025&rev=1346025&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBit.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/GeneralPurposeBit.java Mon Jun 4 16:35:06 2012 @@ -15,13 +15,13 @@ * limitations under the License. * */ -package org.apache.commons.compress.archivers.zip; +package org.apache.tools.zip; /** * Parser/encoder for the "general purpose bit" field in ZIP's local * file and central directory headers. - * @since 1.1 - * @NotThreadSafe + * + * @since Ant 1.9.0 */ public final class GeneralPurposeBit { /** @@ -44,8 +44,8 @@ public final class GeneralPurposeBit { * Indicates that filenames are written in utf-8. * *

The only reason this is public is that {@link - * ZipArchiveOutputStream#EFS_FLAG} was public in Apache Commons - * Compress 1.0 and we needed a substitute for it.

+ * ZipOutputStream#EFS_FLAG} was public in several versions of + * Apache Ant and we needed a substitute for it.

*/ public static final int UFT8_NAMES_FLAG = 1 << 11; Modified: ant/core/trunk/src/main/org/apache/tools/zip/Simple8BitZipEncoding.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/Simple8BitZipEncoding.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/Simple8BitZipEncoding.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/Simple8BitZipEncoding.java Mon Jun 4 16:35:06 2012 @@ -49,7 +49,7 @@ class Simple8BitZipEncoding implements Z * A character entity, which is put to the reverse mapping table * of a simple encoding. */ - private static final class Simple8BitChar implements Comparable { + private static final class Simple8BitChar implements Comparable { public final char unicode; public final byte code; @@ -58,15 +58,28 @@ class Simple8BitZipEncoding implements Z this.unicode = unicode; } - public int compareTo(Object o) { - Simple8BitChar a = (Simple8BitChar) o; - + public int compareTo(Simple8BitChar a) { return this.unicode - a.unicode; } + @Override public String toString() { - return "0x" + Integer.toHexString(0xffff & (int) unicode) - + "->0x" + Integer.toHexString(0xff & (int) code); + return "0x" + Integer.toHexString(0xffff & unicode) + + "->0x" + Integer.toHexString(0xff & code); + } + + @Override + public boolean equals(Object o) { + if (o instanceof Simple8BitChar) { + Simple8BitChar other = (Simple8BitChar) o; + return unicode == other.unicode && code == other.code; + } + return false; + } + + @Override + public int hashCode() { + return unicode; } } @@ -81,24 +94,25 @@ 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 reverseMapping; /** * @param highChars The characters for byte values of 128 to 255 * stored as an array of 128 chars. */ public Simple8BitZipEncoding(char[] highChars) { - this.highChars = highChars; - this.reverseMapping = new ArrayList(this.highChars.length); + this.highChars = highChars.clone(); + List temp = + new ArrayList(this.highChars.length); byte code = 127; for (int i = 0; i < this.highChars.length; ++i) { - this.reverseMapping.add(new Simple8BitChar(++code, - this.highChars[i])); + temp.add(new Simple8BitChar(++code, this.highChars[i])); } - Collections.sort(this.reverseMapping); + Collections.sort(temp); + this.reverseMapping = Collections.unmodifiableList(temp); } /** @@ -114,7 +128,7 @@ class Simple8BitZipEncoding implements Z } // byte is signed, so 128 == -128 and 255 == -1 - return this.highChars[128 + (int) b]; + return this.highChars[128 + b]; } /** @@ -137,7 +151,7 @@ class Simple8BitZipEncoding implements Z * @param bb The byte buffer to write to. * @param c The character to encode. * @return Whether the given unicode character is covered by this encoding. - * If false is returned, nothing is pushed to the + * If {@code false} is returned, nothing is pushed to the * byte buffer. */ public boolean pushEncodedChar(ByteBuffer bb, char c) { @@ -158,7 +172,7 @@ class Simple8BitZipEncoding implements Z /** * @param c A unicode character in the range from 0x0080 to 0x7f00 * @return A Simple8BitChar, if this character is covered by this encoding. - * A null value is returned, if this character is not + * A {@code null} value is returned, if this character is not * covered by this encoding. */ private Simple8BitChar encodeHighChar(char c) { @@ -171,7 +185,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; @@ -188,7 +202,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; Modified: ant/core/trunk/src/main/org/apache/tools/zip/UnicodeCommentExtraField.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/UnicodeCommentExtraField.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/UnicodeCommentExtraField.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/UnicodeCommentExtraField.java Mon Jun 4 16:35:06 2012 @@ -67,6 +67,7 @@ public class UnicodeCommentExtraField ex super(comment, bytes); } + /** {@inheritDoc} */ public ZipShort getHeaderId() { return UCOM_ID; } Modified: ant/core/trunk/src/main/org/apache/tools/zip/UnicodePathExtraField.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/UnicodePathExtraField.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/UnicodePathExtraField.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/UnicodePathExtraField.java Mon Jun 4 16:35:06 2012 @@ -66,6 +66,7 @@ public class UnicodePathExtraField exten super(name, bytes); } + /** {@inheritDoc} */ public ZipShort getHeaderId() { return UPATH_ID; } Modified: ant/core/trunk/src/main/org/apache/tools/zip/UnparseableExtraFieldData.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/UnparseableExtraFieldData.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/UnparseableExtraFieldData.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/UnparseableExtraFieldData.java Mon Jun 4 16:35:06 2012 @@ -21,12 +21,11 @@ package org.apache.tools.zip; /** * Wrapper for extra field data that doesn't conform to the recommended format of header-tag + size + data. * - *

The header-id is artificial (and not listed as a know ID in - * the .ZIP File Format Specification). - * Since it isn't used anywhere except to satisfy the + *

The header-id is artificial (and not listed as a known ID in + * {@link + * APPNOTE.TXT}). Since it isn't used anywhere except to satisfy the * ZipExtraField contract it shouldn't matter anyway.

- * @see .ZIP File Format Specification + * * @since Ant 1.8.1 */ public final class UnparseableExtraFieldData @@ -103,7 +102,6 @@ public final class UnparseableExtraField * @param buffer the buffer to read data from * @param offset offset into buffer to read data * @param length the length of data - * @exception ZipException on error */ public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) { Copied: ant/core/trunk/src/main/org/apache/tools/zip/UnsupportedZipFeatureException.java (from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java) URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/UnsupportedZipFeatureException.java?p2=ant/core/trunk/src/main/org/apache/tools/zip/UnsupportedZipFeatureException.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java&r1=1345686&r2=1346025&rev=1346025&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnsupportedZipFeatureException.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/UnsupportedZipFeatureException.java Mon Jun 4 16:35:06 2012 @@ -16,19 +16,19 @@ * */ -package org.apache.commons.compress.archivers.zip; +package org.apache.tools.zip; import java.util.zip.ZipException; /** * Exception thrown when attempting to read or write data for a zip * entry that uses ZIP features not supported by this library. - * @since Commons Compress 1.1 + * @since Ant 1.9.0 */ public class UnsupportedZipFeatureException extends ZipException { private final Feature reason; - private final ZipArchiveEntry entry; + private final ZipEntry entry; private static final long serialVersionUID = 4430521921766595597L; /** @@ -37,7 +37,7 @@ public class UnsupportedZipFeatureExcept * @param entry the entry using the feature */ public UnsupportedZipFeatureException(Feature reason, - ZipArchiveEntry entry) { + ZipEntry entry) { super("unsupported feature " + reason + " used in entry " + entry.getName()); this.reason = reason; @@ -54,13 +54,12 @@ public class UnsupportedZipFeatureExcept /** * The entry using the unsupported feature. */ - public ZipArchiveEntry getEntry() { + public ZipEntry getEntry() { return entry; } /** * ZIP Features that may or may not be supported. - * @since Commons Compress 1.1 */ public static class Feature { /** Copied: ant/core/trunk/src/main/org/apache/tools/zip/Zip64ExtendedInformationExtraField.java (from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java) URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/Zip64ExtendedInformationExtraField.java?p2=ant/core/trunk/src/main/org/apache/tools/zip/Zip64ExtendedInformationExtraField.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java&r1=1345686&r2=1346025&rev=1346025&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/Zip64ExtendedInformationExtraField.java Mon Jun 4 16:35:06 2012 @@ -16,12 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.commons.compress.archivers.zip; +package org.apache.tools.zip; 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; +import static org.apache.tools.zip.ZipConstants.DWORD; +import static org.apache.tools.zip.ZipConstants.WORD; /** * Holds size and other extended information for entries that use Zip64 @@ -64,16 +64,16 @@ import static org.apache.commons.compres * Local Header for the original file size will be zero. *

* - *

Currently Commons Compress doesn't support encrypting the - * central directory so the not about masking doesn't apply.

+ *

Currently Ant doesn't support encrypting the + * central directory so the note about masking doesn't apply.

* *

The implementation relies on data being read from the local file * header and assumes that both size values are always present.

* - * @since 1.2 - * @NotThreadSafe + * @since Ant 1.9.0 */ -public class Zip64ExtendedInformationExtraField implements ZipExtraField { +public class Zip64ExtendedInformationExtraField + implements CentralDirectoryParsingZipExtraField { static final ZipShort HEADER_ID = new ZipShort(0x0001); @@ -91,14 +91,12 @@ public class Zip64ExtendedInformationExt * reparseCentralDirectoryData}. * *

Not used for anything else

- * - * @since 1.3 */ private byte[] rawCentralDirectoryData; /** * This constructor should only be used by the code that reads - * archives inside of Commons Compress. + * archives inside of Ant. */ public Zip64ExtendedInformationExtraField() { } Copied: ant/core/trunk/src/main/org/apache/tools/zip/Zip64Mode.java (from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64Mode.java) URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/Zip64Mode.java?p2=ant/core/trunk/src/main/org/apache/tools/zip/Zip64Mode.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64Mode.java&r1=1345686&r2=1346025&rev=1346025&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64Mode.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/Zip64Mode.java Mon Jun 4 16:35:06 2012 @@ -16,14 +16,14 @@ * */ -package org.apache.commons.compress.archivers.zip; +package org.apache.tools.zip; /** - * The different modes {@link ZipArchiveOutputStream} can operate in. + * The different modes {@link ZipOutputStream} can operate in. * - * @see ZipArchiveOutputStream#setUseZip64 + * @see ZipOutputStream#setUseZip64 * - * @since 1.3 + * @since Ant 1.9.0 */ public enum Zip64Mode { /** @@ -35,7 +35,7 @@ public enum Zip64Mode { * Don't use Zip64 extensions for any entries. * *

This will cause a {@link Zip64RequiredException} to be - * thrown if {@link ZipArchiveOutputStream} detects it needs Zip64 + * thrown if {@link ZipOutputStream} detects it needs Zip64 * support.

*/ Never, Copied: ant/core/trunk/src/main/org/apache/tools/zip/Zip64RequiredException.java (from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64RequiredException.java) URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/Zip64RequiredException.java?p2=ant/core/trunk/src/main/org/apache/tools/zip/Zip64RequiredException.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64RequiredException.java&r1=1345686&r2=1346025&rev=1346025&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64RequiredException.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/Zip64RequiredException.java Mon Jun 4 16:35:06 2012 @@ -16,15 +16,15 @@ * */ -package org.apache.commons.compress.archivers.zip; +package org.apache.tools.zip; import java.util.zip.ZipException; /** * Exception thrown when attempting to write data that requires Zip64 - * support to an archive and {@link ZipArchiveOutputStream#setUseZip64 + * support to an archive and {@link ZipOutputStream#setUseZip64 * UseZip64} has been set to {@link Zip64Mode#Never Never}. - * @since 1.3 + * @since Ant 1.9.0 */ public class Zip64RequiredException extends ZipException { @@ -33,7 +33,7 @@ public class Zip64RequiredException exte /** * Helper to format "entry too big" messages. */ - static String getEntryTooBigMessage(ZipArchiveEntry ze) { + static String getEntryTooBigMessage(ZipEntry ze) { return ze.getName() + "'s size exceeds the limit of 4GByte."; } Copied: ant/core/trunk/src/main/org/apache/tools/zip/ZipConstants.java (from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java) URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipConstants.java?p2=ant/core/trunk/src/main/org/apache/tools/zip/ZipConstants.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java&r1=1345686&r2=1346025&rev=1346025&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipConstants.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/ZipConstants.java Mon Jun 4 16:35:06 2012 @@ -15,12 +15,10 @@ * limitations under the License. * */ -package org.apache.commons.compress.archivers.zip; +package org.apache.tools.zip; /** * Various constants used throughout the package. - * - * @since 1.3 */ final class ZipConstants { private ZipConstants() { } Copied: ant/core/trunk/src/main/org/apache/tools/zip/ZipEightByteInteger.java (from r1345686, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java) URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipEightByteInteger.java?p2=ant/core/trunk/src/main/org/apache/tools/zip/ZipEightByteInteger.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java&r1=1345686&r2=1346025&rev=1346025&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEightByteInteger.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/ZipEightByteInteger.java Mon Jun 4 16:35:06 2012 @@ -15,18 +15,15 @@ * limitations under the License. * */ -package org.apache.commons.compress.archivers.zip; +package org.apache.tools.zip; import java.math.BigInteger; -import static org.apache.commons.compress.archivers.zip.ZipConstants.BYTE_MASK; +import static org.apache.tools.zip.ZipConstants.BYTE_MASK; /** * Utility class that represents an eight byte integer with conversion * rules for the big endian byte order of ZIP files. - * @Immutable - * - * @since 1.2 */ public final class ZipEightByteInteger { Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipEncoding.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipEncoding.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/ZipEncoding.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/ZipEncoding.java Mon Jun 4 16:35:06 2012 @@ -68,7 +68,7 @@ interface ZipEncoding { * character sequences are mapped to a sequence of utf-16 * words encoded in the format %Uxxxx. It is * assumed, that the byte buffer is positioned at the - * beinning of the encoded result, the byte buffer has a + * beginning of the encoded result, the byte buffer has a * backing array and the limit of the byte buffer points * to the end of the encoded result. * @throws IOException Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/ZipEncodingHelper.java Mon Jun 4 16:35:06 2012 @@ -62,10 +62,10 @@ abstract class ZipEncodingHelper { } } - private static final Map simpleEncodings; + private static final Map simpleEncodings; static { - simpleEncodings = new HashMap(); + simpleEncodings = new HashMap(); char[] cp437_high_chars = new char[] { 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, @@ -203,7 +203,7 @@ abstract class ZipEncodingHelper { /** * Instantiates a zip encoding. * - * @param name The name of the zip encoding. Specify null for + * @param name The name of the zip encoding. Specify {@code null} for * the platform's default encoding. * @return A zip encoding for the given encoding name. */ @@ -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(); Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java?rev=1346025&r1=1346024&r2=1346025&view=diff ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java (original) +++ ant/core/trunk/src/main/org/apache/tools/zip/ZipEntry.java Mon Jun 4 16:35:06 2012 @@ -18,7 +18,10 @@ package org.apache.tools.zip; +import java.io.File; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.zip.ZipException; @@ -28,7 +31,8 @@ import java.util.zip.ZipException; * access to the internal and external file attributes. * *

The extra data is expected to follow the recommendation of - * the .ZIP File Format Specification created by PKWARE Inc. :

+ * {@link + * APPNOTE.txt}:

*
    *
  • the extra byte array consists of a sequence of extra fields
  • *
  • each extra fields starts by a two byte header id followed by @@ -38,11 +42,9 @@ import java.util.zip.ZipException; * *

    Any extra data that cannot be parsed by the rules above will be * consumed as "unparseable" extra data and treated differently by the - * methods of this class. Versions prior to Apache Commons Compress - * 1.1 would have thrown an exception if any attempt was made to read - * or write extra data not conforming to the recommendation.

    - * @see - * .ZIP File Format Specification + * methods of this class. Older versions would have thrown an + * exception if any attempt was made to read or write extra data not + * conforming to the recommendation.

    * */ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { @@ -52,30 +54,59 @@ public class ZipEntry extends java.util. private static final int SHORT_MASK = 0xFFFF; private static final int SHORT_SHIFT = 16; + /** + * The {@link java.util.zip.ZipEntry} base class only supports + * the compression methods STORED and DEFLATED. We override the + * field so that any compression methods can be used. + *

    + * The default value -1 means that the method has not been specified. + */ + 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 = -1; + private int internalAttributes = 0; private int platform = PLATFORM_FAT; private long externalAttributes = 0; - private LinkedHashMap/**/ extraFields = null; + private LinkedHashMap extraFields = null; private UnparseableExtraFieldData unparseableExtra = null; private String name = null; + private byte[] rawName = null; + private GeneralPurposeBit gpb = new GeneralPurposeBit(); /** * Creates a new zip entry with the specified name. + * + *

    Assumes the entry represents a directory if and only if the + * name ends with a forward slash "/".

    + * * @param name the name of the entry * @since 1.1 */ public ZipEntry(String name) { super(name); + setName(name); } /** * Creates a new zip entry with fields taken from the specified zip entry. + * + *

    Assumes the entry represents a directory if and only if the + * name ends with a forward slash "/".

    + * * @param entry the entry to get fields from * @since 1.1 * @throws ZipException on error */ public ZipEntry(java.util.zip.ZipEntry entry) throws ZipException { super(entry); + setName(entry.getName()); byte[] extra = entry.getExtra(); if (extra != null) { setExtraFields(ExtraFieldUtils.parse(extra, true, @@ -85,10 +116,16 @@ public class ZipEntry extends java.util. // initializes extra data to an empty byte array setExtra(); } + setMethod(entry.getMethod()); + this.size = entry.getSize(); } /** * Creates a new zip entry with fields taken from the specified zip entry. + * + *

    Assumes the entry represents a directory if and only if the + * name ends with a forward slash "/".

    + * * @param entry the entry to get fields from * @throws ZipException on error * @since 1.1 @@ -104,7 +141,26 @@ public class ZipEntry extends java.util. * @since 1.9 */ protected ZipEntry() { - super(""); + this(""); + } + + /** + * Creates a new zip entry taking some information from the given + * file and using the provided name. + * + *

    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.

    + */ + public ZipEntry(File inputFile, String entryName) { + this(inputFile.isDirectory() && !entryName.endsWith("/") ? + entryName + "/" : entryName); + if (inputFile.isFile()){ + setSize(inputFile.length()); + } + setTime(inputFile.lastModified()); + // TODO are there any other fields we can set here? } /** @@ -112,6 +168,7 @@ public class ZipEntry extends java.util. * @return a cloned copy of this ZipEntry * @since 1.1 */ + @Override public Object clone() { ZipEntry e = (ZipEntry) super.clone(); @@ -122,6 +179,31 @@ public class ZipEntry extends java.util. } /** + * Returns the compression method of this entry, or -1 if the + * compression method has not been specified. + * + * @return compression method + */ + @Override + public int getMethod() { + return method; + } + + /** + * Sets the compression method of this entry. + * + * @param method compression method + */ + @Override + public void setMethod(int method) { + if (method < 0) { + throw new IllegalArgumentException( + "ZIP compression method can not be negative: " + method); + } + this.method = method; + } + + /** * Retrieves the internal file attributes. * * @return the internal file attributes @@ -213,12 +295,12 @@ public class ZipEntry extends java.util. * @since 1.1 */ public void setExtraFields(ZipExtraField[] fields) { - extraFields = new LinkedHashMap(); - for (int i = 0; i < fields.length; i++) { - if (fields[i] instanceof UnparseableExtraFieldData) { - unparseableExtra = (UnparseableExtraFieldData) fields[i]; + extraFields = new LinkedHashMap(); + for (ZipExtraField field : fields) { + if (field instanceof UnparseableExtraFieldData) { + unparseableExtra = (UnparseableExtraFieldData) field; } else { - extraFields.put(fields[i].getHeaderId(), fields[i]); + extraFields.put(field.getHeaderId(), field); } } setExtra(); @@ -246,11 +328,12 @@ public class ZipEntry extends java.util. ? new ZipExtraField[0] : new ZipExtraField[] { unparseableExtra }; } - List result = new ArrayList(extraFields.values()); + List result = + new ArrayList(extraFields.values()); if (includeUnparseable && unparseableExtra != null) { result.add(unparseableExtra); } - return (ZipExtraField[]) result.toArray(new ZipExtraField[0]); + return result.toArray(new ZipExtraField[0]); } /** @@ -267,7 +350,7 @@ public class ZipEntry extends java.util. unparseableExtra = (UnparseableExtraFieldData) ze; } else { if (extraFields == null) { - extraFields = new LinkedHashMap(); + extraFields = new LinkedHashMap(); } extraFields.put(ze.getHeaderId(), ze); } @@ -286,8 +369,8 @@ public class ZipEntry extends java.util. if (ze instanceof UnparseableExtraFieldData) { unparseableExtra = (UnparseableExtraFieldData) ze; } else { - LinkedHashMap copy = extraFields; - extraFields = new LinkedHashMap(); + LinkedHashMap copy = extraFields; + extraFields = new LinkedHashMap(); extraFields.put(ze.getHeaderId(), ze); if (copy != null) { copy.remove(ze.getHeaderId()); @@ -330,7 +413,7 @@ public class ZipEntry extends java.util. */ public ZipExtraField getExtraField(ZipShort type) { if (extraFields != null) { - return (ZipExtraField) extraFields.get(type); + return extraFields.get(type); } return null; } @@ -353,13 +436,14 @@ public class ZipEntry extends java.util. * @since 1.1 * @throws RuntimeException on error */ + @Override public void setExtra(byte[] extra) throws RuntimeException { try { ZipExtraField[] local = ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ); mergeExtraFields(local, true); - } catch (Exception e) { + } catch (ZipException e) { // actually this is not be possible as of Ant 1.8.1 throw new RuntimeException("Error parsing extra fields for entry: " + getName() + " - " + e.getMessage(), e); @@ -387,7 +471,7 @@ public class ZipEntry extends java.util. ExtraFieldUtils.parse(b, false, ExtraFieldUtils.UnparseableExtraField.READ); mergeExtraFields(central, false); - } catch (Exception e) { + } catch (ZipException e) { throw new RuntimeException(e.getMessage(), e); } } @@ -430,6 +514,7 @@ public class ZipEntry extends java.util. * @return the entry name * @since 1.9 */ + @Override public String getName() { return name == null ? super.getName() : name; } @@ -439,6 +524,7 @@ public class ZipEntry extends java.util. * @return true if the entry is a directory * @since 1.10 */ + @Override public boolean isDirectory() { return getName().endsWith("/"); } @@ -448,15 +534,72 @@ public class ZipEntry extends java.util. * @param name the name to use */ protected void setName(String name) { + if (name != null && getPlatform() == PLATFORM_FAT + && name.indexOf("/") == -1) { + name = name.replace('\\', '/'); + } this.name = name; } /** + * 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 + * the guessed or configured encoding + * @param rawName the bytes originally read as name from the + * archive + */ + protected void setName(String name, byte[] rawName) { + setName(name); + this.rawName = rawName; + } + + /** + * Returns the raw bytes that made up the name before it has been + * converted using the configured or guessed encoding. + * + *

    This method will return null if this instance has not been + * read from an archive.

    + */ + public byte[] getRawName() { + if (rawName != null) { + byte[] b = new byte[rawName.length]; + System.arraycopy(rawName, 0, b, 0, rawName.length); + return b; + } + return null; + } + + /** * Get the hashCode of the entry. * This uses the name as the hashcode. * @return a hashcode. * @since Ant 1.7 */ + @Override public int hashCode() { // this method has severe consequences on performance. We cannot rely // on the super.hashCode() method since super.getName() always return @@ -466,14 +609,17 @@ public class ZipEntry extends java.util. } /** - * The equality method. In this case, the implementation returns 'this == o' - * which is basically the equals method of the Object class. - * @param o the object to compare to - * @return true if this object is the same as o - * @since Ant 1.7 + * The "general purpose bit" field. + */ + public GeneralPurposeBit getGeneralPurposeBit() { + return gpb; + } + + /** + * The "general purpose bit" field. */ - public boolean equals(Object o) { - return (this == o); + public void setGeneralPurposeBit(GeneralPurposeBit b) { + gpb = b; } /** @@ -489,23 +635,23 @@ public class ZipEntry extends java.util. if (extraFields == null) { setExtraFields(f); } else { - for (int i = 0; i < f.length; i++) { + for (ZipExtraField element : f) { ZipExtraField existing; - if (f[i] instanceof UnparseableExtraFieldData) { + if (element instanceof UnparseableExtraFieldData) { existing = unparseableExtra; } else { - existing = getExtraField(f[i].getHeaderId()); + existing = getExtraField(element.getHeaderId()); } if (existing == null) { - addExtraField(f[i]); + addExtraField(element); } else { if (local || !(existing instanceof CentralDirectoryParsingZipExtraField)) { - byte[] b = f[i].getLocalFileDataData(); + byte[] b = element.getLocalFileDataData(); existing.parseFromLocalFileData(b, 0, b.length); } else { - byte[] b = f[i].getCentralDirectoryData(); + byte[] b = element.getCentralDirectoryData(); ((CentralDirectoryParsingZipExtraField) existing) .parseFromCentralDirectoryData(b, 0, b.length); } @@ -514,4 +660,54 @@ public class ZipEntry extends java.util. setExtra(); } } + + /** {@inheritDoc} */ + public Date getLastModifiedDate() { + return new Date(getTime()); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + ZipEntry other = (ZipEntry) obj; + String myName = getName(); + String otherName = other.getName(); + if (myName == null) { + if (otherName != null) { + return false; + } + } else if (!myName.equals(otherName)) { + return false; + } + String myComment = getComment(); + String otherComment = other.getComment(); + if (myComment == null) { + myComment = ""; + } + if (otherComment == null) { + otherComment = ""; + } + return getTime() == other.getTime() + && myComment.equals(otherComment) + && getInternalAttributes() == other.getInternalAttributes() + && getPlatform() == other.getPlatform() + && getExternalAttributes() == other.getExternalAttributes() + && getMethod() == other.getMethod() + && getSize() == other.getSize() + && getCrc() == other.getCrc() + && getCompressedSize() == other.getCompressedSize() + && Arrays.equals(getCentralDirectoryExtra(), + other.getCentralDirectoryExtra()) + && Arrays.equals(getLocalFileDataExtra(), + other.getLocalFileDataExtra()) + && gpb.equals(other.gpb); + } }