commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r740657 - in /commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip: ./ ExtraFieldUtils.java ZipEntry.java ZipFile.java ZipOutputStream.java
Date Wed, 04 Feb 2009 08:45:31 GMT
Author: bodewig
Date: Wed Feb  4 08:45:31 2009
New Revision: 740657

URL: http://svn.apache.org/viewvc?rev=740657&view=rev
Log:
[SANDBOX-256] - merge revision 738844 from Ant - use JDK 1.4+ collections

Modified:
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/
  (props changed)
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEntry.java
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
  (contents, props changed)
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipOutputStream.java

Propchange: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb  4 08:45:31 2009
@@ -1 +1 @@
-/ant/core/trunk/src/main/org/apache/tools/zip:739300
+/ant/core/trunk/src/main/org/apache/tools/zip:738844,739300

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java?rev=740657&r1=740656&r2=740657&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
Wed Feb  4 08:45:31 2009
@@ -17,8 +17,10 @@
  */
 package org.apache.commons.compress.archivers.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;
 
 /**
@@ -35,10 +37,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);
     }
@@ -94,7 +96,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);
@@ -106,7 +108,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) {
@@ -116,8 +118,7 @@
         }
 
         ZipExtraField[] result = new ZipExtraField[v.size()];
-        v.copyInto(result);
-        return result;
+        return (ZipExtraField[]) v.toArray(result);
     }
 
     /**

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEntry.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEntry.java?rev=740657&r1=740656&r2=740657&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEntry.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEntry.java
Wed Feb  4 08:45:31 2009
@@ -17,7 +17,7 @@
  */
 package org.apache.commons.compress.archivers.zip;
 
-import java.util.Vector;
+import java.util.LinkedHashMap;
 import java.util.zip.ZipException;
 
 /**
@@ -35,7 +35,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;
 
     /**
@@ -92,7 +92,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());
@@ -191,9 +191,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();
     }
@@ -208,8 +208,7 @@
             return new ZipExtraField[0];
         }
         ZipExtraField[] result = new ZipExtraField[extraFields.size()];
-        extraFields.copyInto(result);
-        return result;
+        return (ZipExtraField[]) extraFields.values().toArray(result);
     }
 
     /**
@@ -220,19 +219,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();
     }
 
@@ -243,16 +232,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: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java?rev=740657&r1=740656&r2=740657&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Wed Feb  4 08:45:31 2009
@@ -23,9 +23,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;
@@ -72,12 +74,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;
@@ -200,7 +202,7 @@
      * @return all entries as {@link ZipEntry} instances
      */
     public Enumeration getEntries() {
-        return entries.keys();
+        return Collections.enumeration(entries.keySet());
     }
 
     /**

Propchange: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb  4 08:45:31 2009
@@ -1 +1 @@
-/ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java:738853,739300
+/ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java:738844,738853,739300

Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipOutputStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipOutputStream.java?rev=740657&r1=740656&r2=740657&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipOutputStream.java
(original)
+++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipOutputStream.java
Wed Feb  4 08:45:31 2009
@@ -25,8 +25,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;
@@ -128,14 +131,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.
@@ -192,7 +195,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.
@@ -323,13 +326,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();
     }
 
     /**
@@ -409,7 +412,7 @@
         closeEntry();
 
         entry = ze;
-        entries.addElement(entry);
+        entries.add(entry);
 
         if (entry.getMethod() == -1) { // not specified
             entry.setMethod(method);



Mime
View raw message