ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r738844 - in /ant/core/trunk/src/main/org/apache/tools/zip: ExtraFieldUtils.java ZipEntry.java ZipFile.java ZipOutputStream.java
Date Thu, 29 Jan 2009 12:48:35 GMT
Author: bodewig
Date: Thu Jan 29 12:48:35 2009
New Revision: 738844

URL: http://svn.apache.org/viewvc?rev=738844&view=rev
Log:
Move the zip package into a Java 1.4 world

Modified:
    ant/core/trunk/src/main/org/apache/tools/zip/ExtraFieldUtils.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/ZipOutputStream.java

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=738844&r1=738843&r2=738844&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 Thu Jan 29 12:48:35
2009
@@ -18,8 +18,10 @@
 
 package org.apache.tools.zip;
 
-import java.util.Hashtable;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.zip.ZipException;
 
 /**
@@ -36,10 +38,10 @@
      *
      * @since 1.1
      */
-    private static Hashtable implementations;
+    private static final Map implementations;
 
     static {
-        implementations = new Hashtable();
+        implementations = new HashMap();
         register(AsiExtraField.class);
         register(JarMarker.class);
     }
@@ -95,7 +97,7 @@
      * @throws ZipException on error
      */
     public static ZipExtraField[] parse(byte[] data) throws ZipException {
-        Vector v = new Vector();
+        List v = new ArrayList();
         int start = 0;
         while (start <= data.length - WORD) {
             ZipShort headerId = new ZipShort(data, start);
@@ -107,7 +109,7 @@
             try {
                 ZipExtraField ze = createExtraField(headerId);
                 ze.parseFromLocalFileData(data, start + WORD, length);
-                v.addElement(ze);
+                v.add(ze);
             } catch (InstantiationException ie) {
                 throw new ZipException(ie.getMessage());
             } catch (IllegalAccessException iae) {
@@ -121,8 +123,7 @@
         }
 
         ZipExtraField[] result = new ZipExtraField[v.size()];
-        v.copyInto(result);
-        return result;
+        return (ZipExtraField[]) v.toArray(result);
     }
 
     /**

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=738844&r1=738843&r2=738844&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 Thu Jan 29 12:48:35 2009
@@ -18,7 +18,7 @@
 
 package org.apache.tools.zip;
 
-import java.util.Vector;
+import java.util.LinkedHashMap;
 import java.util.zip.ZipException;
 
 /**
@@ -36,7 +36,7 @@
     private int internalAttributes = 0;
     private int platform = PLATFORM_FAT;
     private long externalAttributes = 0;
-    private Vector/*<ZipExtraField>*/ extraFields = null;
+    private LinkedHashMap/*<ZipShort, ZipExtraField>*/ extraFields = null;
     private String name = null;
 
     /**
@@ -93,7 +93,7 @@
     public Object clone() {
         ZipEntry e = (ZipEntry) super.clone();
 
-        e.extraFields = extraFields != null ? (Vector) extraFields.clone() : null;
+        e.extraFields = extraFields != null ? (LinkedHashMap) extraFields.clone() : null;
         e.setInternalAttributes(getInternalAttributes());
         e.setExternalAttributes(getExternalAttributes());
         e.setExtraFields(getExtraFields());
@@ -192,9 +192,9 @@
      * @since 1.1
      */
     public void setExtraFields(ZipExtraField[] fields) {
-        extraFields = new Vector();
+        extraFields = new LinkedHashMap();
         for (int i = 0; i < fields.length; i++) {
-            extraFields.addElement(fields[i]);
+            extraFields.put(fields[i].getHeaderId(), fields[i]);
         }
         setExtra();
     }
@@ -209,8 +209,7 @@
             return new ZipExtraField[0];
         }
         ZipExtraField[] result = new ZipExtraField[extraFields.size()];
-        extraFields.copyInto(result);
-        return result;
+        return (ZipExtraField[]) extraFields.values().toArray(result);
     }
 
     /**
@@ -221,19 +220,9 @@
      */
     public void addExtraField(ZipExtraField ze) {
         if (extraFields == null) {
-            extraFields = new Vector();
-        }
-        ZipShort type = ze.getHeaderId();
-        boolean done = false;
-        for (int i = 0, fieldsSize = extraFields.size(); !done && i < fieldsSize;
i++) {
-            if (((ZipExtraField) extraFields.elementAt(i)).getHeaderId().equals(type)) {
-                extraFields.setElementAt(ze, i);
-                done = true;
-            }
-        }
-        if (!done) {
-            extraFields.addElement(ze);
+            extraFields = new LinkedHashMap();
         }
+        extraFields.put(ze.getHeaderId(), ze);
         setExtra();
     }
 
@@ -244,16 +233,9 @@
      */
     public void removeExtraField(ZipShort type) {
         if (extraFields == null) {
-            extraFields = new Vector();
-        }
-        boolean done = false;
-        for (int i = 0, fieldsSize = extraFields.size(); !done && i < fieldsSize;
i++) {
-            if (((ZipExtraField) extraFields.elementAt(i)).getHeaderId().equals(type)) {
-                extraFields.removeElementAt(i);
-                done = true;
-            }
+            throw new java.util.NoSuchElementException();
         }
-        if (!done) {
+        if (extraFields.remove(type) == null) {
             throw new java.util.NoSuchElementException();
         }
         setExtra();

Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java?rev=738844&r1=738843&r2=738844&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java Thu Jan 29 12:48:35 2009
@@ -24,9 +24,11 @@
 import java.io.RandomAccessFile;
 import java.io.UnsupportedEncodingException;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Date;
 import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.zip.Inflater;
 import java.util.zip.InflaterInputStream;
 import java.util.zip.ZipException;
@@ -73,12 +75,12 @@
      * Maps ZipEntrys to Longs, recording the offsets of the local
      * file headers.
      */
-    private Hashtable entries = new Hashtable(HASH_SIZE);
+    private final Map entries = new HashMap(HASH_SIZE);
 
     /**
      * Maps String to ZipEntrys, name -> actual entry.
      */
-    private Hashtable nameMap = new Hashtable(HASH_SIZE);
+    private final Map nameMap = new HashMap(HASH_SIZE);
 
     private static final class OffsetEntry {
         private long headerOffset = -1;
@@ -198,7 +200,7 @@
      * @return all entries as {@link ZipEntry} instances
      */
     public Enumeration getEntries() {
-        return entries.keys();
+        return Collections.enumeration(entries.keySet());
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java?rev=738844&r1=738843&r2=738844&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipOutputStream.java Thu Jan 29 12:48:35
2009
@@ -26,8 +26,11 @@
 import java.io.RandomAccessFile;
 import java.io.UnsupportedEncodingException;
 import java.util.Date;
-import java.util.Hashtable;
-import java.util.Vector;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
 import java.util.zip.CRC32;
 import java.util.zip.Deflater;
 import java.util.zip.ZipException;
@@ -129,14 +132,14 @@
      *
      * @since 1.1
      */
-    private Vector entries = new Vector();
+    private final List entries = new LinkedList();
 
     /**
      * CRC instance to avoid parsing DEFLATED data twice.
      *
      * @since 1.1
      */
-    private CRC32 crc = new CRC32();
+    private final CRC32 crc = new CRC32();
 
     /**
      * Count the bytes written to out.
@@ -193,7 +196,7 @@
      *
      * @since 1.1
      */
-    private Hashtable offsets = new Hashtable();
+    private final Map offsets = new HashMap();
 
     /**
      * The encoding to use for filenames and the file comment.
@@ -324,13 +327,13 @@
     public void finish() throws IOException {
         closeEntry();
         cdOffset = written;
-        for (int i = 0, entriesSize = entries.size(); i < entriesSize; i++) {
-            writeCentralFileHeader((ZipEntry) entries.elementAt(i));
+        for (Iterator i = entries.iterator(); i.hasNext(); ) {
+            writeCentralFileHeader((ZipEntry) i.next());
         }
         cdLength = written - cdOffset;
         writeCentralDirectoryEnd();
         offsets.clear();
-        entries.removeAllElements();
+        entries.clear();
     }
 
     /**
@@ -410,7 +413,7 @@
         closeEntry();
 
         entry = ze;
-        entries.addElement(entry);
+        entries.add(entry);
 
         if (entry.getMethod() == -1) { // not specified
             entry.setMethod(method);



Mime
View raw message