git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@738844 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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 @@ public class ExtraFieldUtils { | |||
| * | |||
| * @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 @@ public class ExtraFieldUtils { | |||
| * @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 @@ public class ExtraFieldUtils { | |||
| 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 @@ public class ExtraFieldUtils { | |||
| } | |||
| ZipExtraField[] result = new ZipExtraField[v.size()]; | |||
| v.copyInto(result); | |||
| return result; | |||
| return (ZipExtraField[]) v.toArray(result); | |||
| } | |||
| /** | |||
| @@ -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 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { | |||
| 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 class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { | |||
| 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 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { | |||
| * @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 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { | |||
| 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 class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { | |||
| */ | |||
| 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 class ZipEntry extends java.util.zip.ZipEntry implements Cloneable { | |||
| */ | |||
| 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(); | |||
| @@ -24,9 +24,11 @@ import java.io.InputStream; | |||
| 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 @@ public class ZipFile { | |||
| * 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 @@ public class ZipFile { | |||
| * @return all entries as {@link ZipEntry} instances | |||
| */ | |||
| public Enumeration getEntries() { | |||
| return entries.keys(); | |||
| return Collections.enumeration(entries.keySet()); | |||
| } | |||
| /** | |||
| @@ -26,8 +26,11 @@ import java.io.OutputStream; | |||
| 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 @@ public class ZipOutputStream extends FilterOutputStream { | |||
| * | |||
| * @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 @@ public class ZipOutputStream extends FilterOutputStream { | |||
| * | |||
| * @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 class ZipOutputStream extends FilterOutputStream { | |||
| 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 @@ public class ZipOutputStream extends FilterOutputStream { | |||
| closeEntry(); | |||
| entry = ze; | |||
| entries.addElement(entry); | |||
| entries.add(entry); | |||
| if (entry.getMethod() == -1) { // not specified | |||
| entry.setMethod(method); | |||