You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by qi...@apache.org on 2008/08/22 09:15:27 UTC

svn commit: r687988 [8/11] - in /harmony/enhanced/classlib/branches/java6: ./ depends/build/ depends/build/platform/ depends/jars/ depends/jars/icu4jni_3.4/ depends/manifests/bcel-5.2/ depends/manifests/bcel-5.2/META-INF/ make/ modules/accessibility/ m...

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java Fri Aug 22 00:15:00 2008
@@ -20,10 +20,10 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.harmony.pack200.Codec;
+import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.unpack200.bytecode.Attribute;
 import org.apache.harmony.unpack200.bytecode.BCIRenumberedAttribute;
 import org.apache.harmony.unpack200.bytecode.ByteCode;
@@ -69,6 +69,8 @@
     private int[] bcEscSize;
     private int[][] bcEscByte;
 
+    private List wideByteCodes;
+
     /**
      * @param segment
      */
@@ -78,20 +80,15 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
      */
-    public void unpack(InputStream in) throws IOException, Pack200Exception {
+    public void read(InputStream in) throws IOException, Pack200Exception {
 
         AttributeLayoutMap attributeDefinitionMap = segment
                 .getAttrDefinitionBands().getAttributeDefinitionMap();
         int classCount = header.getClassCount();
         long[][] methodFlags = segment.getClassBands().getMethodFlags();
-        int[] codeMaxNALocals = segment.getClassBands().getCodeMaxNALocals();
-        int[] codeMaxStack = segment.getClassBands().getCodeMaxStack();
-        ArrayList[][] methodAttributes = segment.getClassBands()
-                .getMethodAttributes();
-        String[][] methodDescr = segment.getClassBands().getMethodDescr();
 
         int bcCaseCountCount = 0;
         int bcByteCount = 0;
@@ -121,14 +118,12 @@
         AttributeLayout nativeModifier = attributeDefinitionMap
                 .getAttributeLayout(AttributeLayout.ACC_NATIVE,
                         AttributeLayout.CONTEXT_METHOD);
-        AttributeLayout staticModifier = attributeDefinitionMap
-                .getAttributeLayout(AttributeLayout.ACC_STATIC,
-                        AttributeLayout.CONTEXT_METHOD);
+
         methodByteCodePacked = new byte[classCount][][];
         int bcParsed = 0;
 
         List switchIsTableSwitch = new ArrayList();
-        List wideByteCodes = new ArrayList();
+        wideByteCodes = new ArrayList();
         for (int c = 0; c < classCount; c++) {
             int numberOfMethods = methodFlags[c].length;
             methodByteCodePacked[c] = new byte[numberOfMethods][];
@@ -360,6 +355,31 @@
         bcEscSize = decodeBandInt("bc_escsize", in, Codec.UNSIGNED5, bcEscCount);
         bcEscByte = decodeBandInt("bc_escbyte", in, Codec.BYTE1, bcEscSize);
 
+
+    }
+
+    public void unpack() throws Pack200Exception {
+        int classCount = header.getClassCount();
+        long[][] methodFlags = segment.getClassBands().getMethodFlags();
+        int[] codeMaxNALocals = segment.getClassBands().getCodeMaxNALocals();
+        int[] codeMaxStack = segment.getClassBands().getCodeMaxStack();
+        ArrayList[][] methodAttributes = segment.getClassBands()
+                .getMethodAttributes();
+        String[][] methodDescr = segment.getClassBands().getMethodDescr();
+
+        AttributeLayoutMap attributeDefinitionMap = segment
+                .getAttrDefinitionBands().getAttributeDefinitionMap();
+
+        AttributeLayout abstractModifier = attributeDefinitionMap
+                .getAttributeLayout(AttributeLayout.ACC_ABSTRACT,
+                        AttributeLayout.CONTEXT_METHOD);
+        AttributeLayout nativeModifier = attributeDefinitionMap
+                .getAttributeLayout(AttributeLayout.ACC_NATIVE,
+                        AttributeLayout.CONTEXT_METHOD);
+        AttributeLayout staticModifier = attributeDefinitionMap
+                .getAttributeLayout(AttributeLayout.ACC_STATIC,
+                        AttributeLayout.CONTEXT_METHOD);
+
         int[] wideByteCodeArray = new int[wideByteCodes.size()];
         for (int index = 0; index < wideByteCodeArray.length; index++) {
             wideByteCodeArray[index] = ((Integer) wideByteCodes.get(index))
@@ -401,10 +421,10 @@
                     maxLocal += SegmentUtils
                             .countInvokeInterfaceArgs(methodDescr[c][m]);
                     String[] cpClass = segment.getCpBands().getCpClass();
-                    operandManager.setCurrentClass(cpClass[segment.getClassBands()
-                            .getClassThisInts()[c]]);
-                    operandManager.setSuperClass(cpClass[segment.getClassBands()
-                            .getClassSuperInts()[c]]);
+                    operandManager.setCurrentClass(cpClass[segment
+                            .getClassBands().getClassThisInts()[c]]);
+                    operandManager.setSuperClass(cpClass[segment
+                            .getClassBands().getClassSuperInts()[c]]);
                     List exceptionTable = new ArrayList();
                     if (handlerCount != null) {
                         for (int j = 0; j < handlerCount[i]; j++) {
@@ -429,9 +449,8 @@
                     ArrayList methodAttributesList = methodAttributes[c][m];
                     // Make sure we add the code attribute in the right place
                     int indexForCodeAttr = 0;
-                    for (Iterator iterator = methodAttributesList.iterator(); iterator
-                            .hasNext();) {
-                        Attribute attribute = (Attribute) iterator.next();
+                    for (int index = 0; index < methodAttributesList.size(); index++) {
+                        Attribute attribute = (Attribute) methodAttributesList.get(index);
                         if((attribute instanceof NewAttribute && ((NewAttribute)attribute).getLayoutIndex() < 15)) {
                             indexForCodeAttr ++;
                         } else {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java Fri Aug 22 00:15:00 2008
@@ -19,15 +19,14 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.harmony.pack200.Codec;
+import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.unpack200.bytecode.Attribute;
 import org.apache.harmony.unpack200.bytecode.CPClass;
 import org.apache.harmony.unpack200.bytecode.CPNameAndType;
 import org.apache.harmony.unpack200.bytecode.CPUTF8;
-import org.apache.harmony.unpack200.bytecode.ClassConstantPool;
 import org.apache.harmony.unpack200.bytecode.ClassFileEntry;
 import org.apache.harmony.unpack200.bytecode.ConstantValueAttribute;
 import org.apache.harmony.unpack200.bytecode.DeprecatedAttribute;
@@ -90,7 +89,7 @@
     private ArrayList[][] methodAttributes;
 
     private String[][] methodDescr;
-    
+
     private int[][] methodDescrInts;
 
     private long[][] methodFlags;
@@ -133,7 +132,7 @@
      *
      * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
      */
-    public void unpack(InputStream in) throws IOException, Pack200Exception {
+    public void read(InputStream in) throws IOException, Pack200Exception {
         int classCount = header.getClassCount();
         classThisInts = decodeBandInt("class_this", in, Codec.DELTA5, classCount);
         classThis = getReferences(classThisInts, cpBands.getCpClass());
@@ -154,6 +153,10 @@
 
     }
 
+    public void unpack() {
+
+    }
+
     private void parseFieldBands(InputStream in) throws IOException,
             Pack200Exception {
         fieldDescrInts = decodeBandInt("field_descr", in, Codec.DELTA5,
@@ -624,7 +627,7 @@
                         className = className.substring(0, index);
                     }
                     // Add .java to the end
-                    value = cpBands.cpUTF8Value(className + ".java", ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ, true);
+                    value = cpBands.cpUTF8Value(className + ".java", true);
                 }
                 classAttributes[i].add(new SourceFileAttribute((CPUTF8)value));
                 sourceFileIndex++;
@@ -661,7 +664,7 @@
                     int icTupleF = classInnerClassesF[innerClassIndex][j];
                     String icTupleC2 = null;
                     String icTupleN = null;
-                    
+
                     if (icTupleF != 0) {
                         icTupleC2Index = classInnerClassesOuterRCN[innerClassC2NIndex];
                         icTupleNIndex = classInnerClassesNameRUN[innerClassC2NIndex];
@@ -764,9 +767,6 @@
                 Codec.BRANCH5, codeHandlerCount);
         codeHandlerClassRCN = decodeBandInt(
                 "code_handler_class_RCN", in, Codec.UNSIGNED5, codeHandlerCount);
-        // The codeHandlerClassRCN band contains incremented references to
-        // cp_Class so we can't use parseReferences(..) here.
-        String[] cpClass = cpBands.getCpClass();
 
         int codeFlagsCount = segment.getSegmentHeader().getOptions()
                 .hasAllCodeFlags() ? codeCount : codeSpecialHeader;
@@ -850,11 +850,11 @@
                 CPUTF8 element = localVariableTableTypeRS[x][y];
                 // TODO: come up with a better test for native vs nonnative
                 // signatures?
-                if (element.underlyingString().length() > 2) {
-                    element.setDomain(ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
-                } else {
-                    element.setDomain(ClassConstantPool.DOMAIN_NORMALASCIIZ);
-                }
+//                if (element.underlyingString().length() > 2) {
+//                    element.setDomain(ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
+//                } else {
+//                    element.setDomain(ClassConstantPool.DOMAIN_NORMALASCIIZ);
+//                }
             }
         }
 
@@ -986,15 +986,17 @@
         }
         MetadataBandGroup[] mb = parseMetadata(in, RxA, RxACount,
                 backwardsCalls, "field");
-        Iterator rvaAttributesIterator = mb[0].getAttributes().iterator();
-        Iterator riaAttributesIterator = mb[1].getAttributes().iterator();
+        List rvaAttributes = mb[0].getAttributes();
+        List riaAttributes = mb[1].getAttributes();
+        int rvaAttributesIndex = 0;
+        int riaAttributesIndex = 0;
         for (int i = 0; i < fieldFlags.length; i++) {
             for (int j = 0; j < fieldFlags[i].length; j++) {
                 if (rvaLayout.matches(fieldFlags[i][j])) {
-                    fieldAttributes[i][j].add(rvaAttributesIterator.next());
+                    fieldAttributes[i][j].add(rvaAttributes.get(rvaAttributesIndex++));
                 }
                 if (riaLayout.matches(fieldFlags[i][j])) {
-                    fieldAttributes[i][j].add(riaAttributesIterator.next());
+                    fieldAttributes[i][j].add(riaAttributes.get(riaAttributesIndex++));
                 }
             }
         }
@@ -1146,16 +1148,18 @@
         }
         MetadataBandGroup[] mbgs = parseMetadata(in, RxA, rxaCounts,
                 backwardsCalls, "method");
-        Iterator[] attributeIterators = new Iterator[RxA.length];
+        List[] attributeLists = new List[RxA.length];
+        int[] attributeListIndexes = new int[RxA.length];
         for (int i = 0; i < mbgs.length; i++) {
-            attributeIterators[i] = mbgs[i].getAttributes().iterator();
+            attributeLists[i] = mbgs[i].getAttributes();
+            attributeListIndexes[i] = 0;
         }
         for (int i = 0; i < methodFlags.length; i++) {
             for (int j = 0; j < methodFlags[i].length; j++) {
                 for (int k = 0; k < rxaLayouts.length; k++) {
                     if (rxaLayouts[k].matches(methodFlags[i][j])) {
                         methodAttributes[i][j]
-                                .add(attributeIterators[k].next());
+                                .add(attributeLists[k].get(attributeListIndexes[k]++));
                     }
                 }
             }
@@ -1166,7 +1170,7 @@
     /**
      * Parse the class metadata bands and return the number of backwards
      * callables
-     * 
+     *
      * @param in
      * @param classAttrCalls
      * @return
@@ -1201,14 +1205,16 @@
         }
         MetadataBandGroup[] mbgs = parseMetadata(in, RxA, RxACount,
                 backwardsCalls, "class");
-        Iterator rvaAttributesIterator = mbgs[0].getAttributes().iterator();
-        Iterator riaAttributesIterator = mbgs[1].getAttributes().iterator();
+        List rvaAttributes = mbgs[0].getAttributes();
+        List riaAttributes = mbgs[1].getAttributes();
+        int rvaAttributesIndex = 0;
+        int riaAttributesIndex = 0;
         for (int i = 0; i < classFlags.length; i++) {
             if (rvaLayout.matches(classFlags[i])) {
-                classAttributes[i].add(rvaAttributesIterator.next());
+                classAttributes[i].add(rvaAttributes.get(rvaAttributesIndex++));
             }
             if (riaLayout.matches(classFlags[i])) {
-                classAttributes[i].add(riaAttributesIterator.next());
+                classAttributes[i].add(riaAttributes.get(riaAttributesIndex++));
             }
         }
         return numBackwardsCalls;
@@ -1304,16 +1310,16 @@
     /**
      * Answer an ArrayList of ArrayLists which hold the the code attributes
      * corresponding to all classes in order.
-     * 
+     *
      * If a class doesn't have any attributes, the corresponding element in this
      * list will be an empty ArrayList.
-     * 
+     *
      * @return ArrayList
      */
     public ArrayList getOrderedCodeAttributes() {
-        ArrayList orderedAttributeList = new ArrayList();
+        ArrayList orderedAttributeList = new ArrayList(codeAttributes.length);
         for (int classIndex = 0; classIndex < codeAttributes.length; classIndex++) {
-            ArrayList currentAttributes = new ArrayList();
+            ArrayList currentAttributes = new ArrayList(codeAttributes[classIndex].size());
             for (int attributeIndex = 0; attributeIndex < codeAttributes[classIndex]
                     .size(); attributeIndex++) {
                 Attribute attribute = (Attribute) codeAttributes[classIndex]
@@ -1358,7 +1364,7 @@
      * Returns null if all classes should use the default major and minor
      * version or an array of integers containing the major version numberss to
      * use for each class in the segment
-     * 
+     *
      * @return Class file major version numbers, or null if none specified
      */
     public int[] getClassVersionMajor() {
@@ -1369,7 +1375,7 @@
      * Returns null if all classes should use the default major and minor
      * version or an array of integers containing the minor version numberss to
      * use for each class in the segment
-     * 
+     *
      * @return Class file minor version numbers, or null if none specified
      */
     public int[] getClassVersionMinor() {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java Fri Aug 22 00:15:00 2008
@@ -22,6 +22,7 @@
 import java.util.HashMap;
 
 import org.apache.harmony.pack200.Codec;
+import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.unpack200.bytecode.CPClass;
 import org.apache.harmony.unpack200.bytecode.CPDouble;
 import org.apache.harmony.unpack200.bytecode.CPFieldRef;
@@ -33,7 +34,6 @@
 import org.apache.harmony.unpack200.bytecode.CPNameAndType;
 import org.apache.harmony.unpack200.bytecode.CPString;
 import org.apache.harmony.unpack200.bytecode.CPUTF8;
-import org.apache.harmony.unpack200.bytecode.ClassConstantPool;
 
 /**
  * Constant Pool bands
@@ -73,7 +73,7 @@
     private int[] cpStringInts;
     private String[] cpUTF8;
 
-    private final HashMap[] stringsToCPUTF8 = new HashMap[ClassConstantPool.NUM_DOMAINS];
+    private final HashMap stringsToCPUTF8 = new HashMap();
     private final HashMap stringsToCPStrings = new HashMap();
     private final HashMap longsToCPLongs = new HashMap();
     private final HashMap integersToCPIntegers = new HashMap();
@@ -82,6 +82,11 @@
     private final HashMap doublesToCPDoubles = new HashMap();
     private final HashMap descriptorsToCPNameAndTypes = new HashMap();
 
+    private HashMap mapClass = new HashMap();
+    private HashMap mapDescriptor = new HashMap();
+    private HashMap mapUTF8 = new HashMap();
+    private HashMap mapSignature = new HashMap();
+
     private int intOffset;
     private int floatOffset;
     private int longOffset;
@@ -98,7 +103,7 @@
         super(segment);
     }
 
-    public void unpack(InputStream in) throws IOException, Pack200Exception {
+    public void read(InputStream in) throws IOException, Pack200Exception {
         parseCpUtf8(in);
         parseCpInt(in);
         parseCpFloat(in);
@@ -125,10 +130,14 @@
         imethodOffset = methodOffset + cpMethodClass.length;
     }
 
+    public void unpack() {
+
+    }
+
     /**
      * Parses the constant pool class names, using {@link #cpClassCount} to
      * populate {@link #cpClass} from {@link #cpUTF8}.
-     * 
+     *
      * @param in
      *            the input stream to read from
      * @throws IOException
@@ -144,6 +153,7 @@
         cpClass = new String[cpClassCount];
         for (int i = 0; i < cpClassCount; i++) {
             cpClass[i] = cpUTF8[cpClassInts[i]];
+            mapClass.put(cpClass[i], new Integer(i));
         }
     }
 
@@ -154,7 +164,7 @@
      * largely to make it easier for representing field and method descriptors
      * (e.g. <code>out:java.lang.PrintStream</code>) in a way that is
      * compatible with passing String arrays.
-     * 
+     *
      * @param in
      *            the input stream to read from
      * @throws IOException
@@ -176,6 +186,7 @@
         cpDescriptor = new String[cpDescriptorCount];
         for (int i = 0; i < cpDescriptorCount; i++) {
             cpDescriptor[i] = cpDescriptorNames[i] + ":" + cpDescriptorTypes[i]; //$NON-NLS-1$
+            mapDescriptor.put(cpDescriptor[i], new Integer(i));
         }
     }
 
@@ -193,7 +204,7 @@
     /**
      * Parses the constant pool field definitions, using {@link #cpFieldCount}
      * to populate {@link #cpFieldClass} and {@link #cpFieldDescriptor}.
-     * 
+     *
      * @param in
      *            the input stream to read from
      * @throws IOException
@@ -232,7 +243,7 @@
      * Parses the constant pool interface method definitions, using
      * {@link #cpIMethodCount} to populate {@link #cpIMethodClass} and
      * {@link #cpIMethodDescriptor}.
-     * 
+     *
      * @param in
      *            the input stream to read from
      * @throws IOException
@@ -272,7 +283,7 @@
     /**
      * Parses the constant pool method definitions, using {@link #cpMethodCount}
      * to populate {@link #cpMethodClass} and {@link #cpMethodDescriptor}.
-     * 
+     *
      * @param in
      *            the input stream to read from
      * @throws IOException
@@ -309,7 +320,7 @@
      * representation identical to the bytecode equivalent
      * <code>[Ljava/lang/String;(V)</code> TODO Check that the form is as
      * above and update other types e.g. J
-     * 
+     *
      * @param in
      *            the input stream to read from
      * @throws IOException
@@ -356,17 +367,17 @@
             }
             cpSignature[i] = signature.toString();
         }
-        for (int i = 0; i < cpSignatureInts.length; i++) {
-            if(cpSignatureInts[i] == -1) {
-                cpSignatureInts[i] = search(cpUTF8, cpSignature[i]);
-            }
-        }
+//        for (int i = 0; i < cpSignatureInts.length; i++) {
+//            if(cpSignatureInts[i] == -1) {
+//                cpSignatureInts[i] = search(cpUTF8, cpSignature[i]);
+//            }
+//        }
     }
 
     /**
      * Parses the constant pool strings, using {@link #cpStringCount} to
      * populate {@link #cpString} from indexes into {@link #cpUTF8}.
-     * 
+     *
      * @param in
      *            the input stream to read from
      * @throws IOException
@@ -391,6 +402,7 @@
         int cpUTF8Count = header.getCpUTF8Count();
         cpUTF8 = new String[cpUTF8Count];
         cpUTF8[0] = ""; //$NON-NLS-1$
+        mapUTF8.put("", new Integer(0));
         int[] prefix = decodeBandInt("cpUTF8Prefix", in, Codec.DELTA5,
                 cpUTF8Count - 2);
         int charCount = 0;
@@ -439,10 +451,12 @@
                 // surprised if it works first time w/o errors ...
                 cpUTF8[i] = lastString.substring(0, i > 1 ? prefix[i - 2] : 0)
                         + new String(bigSuffixData[bigSuffixCount++]);
+                mapUTF8.put(cpUTF8[i], new Integer(i));
             } else {
                 cpUTF8[i] = lastString.substring(0, i > 1 ? prefix[i - 2] : 0)
                         + new String(data, charCount, suffix[i - 1]);
                 charCount += suffix[i - 1];
+                mapUTF8.put(cpUTF8[i], new Integer(i));
             }
         }
     }
@@ -507,44 +521,40 @@
         return cpUTF8;
     }
 
-    public CPUTF8 cpUTF8Value(int index, int domain) {
+    public CPUTF8 cpUTF8Value(int index) {
         String string = cpUTF8[index];
-        if (stringsToCPUTF8[domain] == null) {
-            stringsToCPUTF8[domain] = new HashMap();
-        }
-        CPUTF8 cputf8 = (CPUTF8) stringsToCPUTF8[domain].get(string);
+        CPUTF8 cputf8 = (CPUTF8) stringsToCPUTF8.get(string);
         if (cputf8 == null) {
-            cputf8 = new CPUTF8(string, domain, index);
-            stringsToCPUTF8[domain].put(string, cputf8);
+            cputf8 = new CPUTF8(string, index);
+            stringsToCPUTF8.put(string, cputf8);
+        } else if(cputf8.getGlobalIndex() > index) {
+            cputf8.setGlobalIndex(index);
         }
         return cputf8;
     }
-    
-    public CPUTF8 cpUTF8Value(String string, int domain) {
-        return cpUTF8Value(string, domain, true);
+
+    public CPUTF8 cpUTF8Value(String string) {
+        return cpUTF8Value(string, true);
     }
 
-    public CPUTF8 cpUTF8Value(String string, int domain, boolean searchForIndex) {
-        if (stringsToCPUTF8[domain] == null) {
-            stringsToCPUTF8[domain] = new HashMap();
-        }
-        CPUTF8 cputf8 = (CPUTF8) stringsToCPUTF8[domain].get(string);
+    public CPUTF8 cpUTF8Value(String string, boolean searchForIndex) {
+        CPUTF8 cputf8 = (CPUTF8) stringsToCPUTF8.get(string);
         if (cputf8 == null) {
-            int index = -1;
+        	Integer index = null;
             if(searchForIndex) {
-                index = search(cpUTF8, string);
+            	index = (Integer)mapUTF8.get(string);
             }
-            if(index != -1) {
-                return cpUTF8Value(index, domain);
+            if(index != null) {
+            	return cpUTF8Value(index.intValue());
             }
             if(searchForIndex) {
-                index = search(cpSignature, string);
+            	index = (Integer)mapSignature.get(string);
             }
-            if(index != -1) {
-                return cpSignatureValue(index);
+            if(index != null) {
+            	return cpSignatureValue(index.intValue());
             }
-            cputf8 = new CPUTF8(string, domain, -1);
-            stringsToCPUTF8[domain].put(string, cputf8);
+            cputf8 = new CPUTF8(string, -1);
+            stringsToCPUTF8.put(string, cputf8);
         }
         return cputf8;
     }
@@ -555,8 +565,7 @@
         int globalIndex = stringOffset + index;
         CPString cpString = (CPString) stringsToCPStrings.get(string);
         if (cpString == null) {
-            cpString = new CPString(cpUTF8Value(utf8Index,
-                    ClassConstantPool.DOMAIN_NORMALASCIIZ), globalIndex);
+            cpString = new CPString(cpUTF8Value(utf8Index), globalIndex);
             stringsToCPStrings.put(string, cpString);
         }
         return cpString;
@@ -598,8 +607,7 @@
         int globalIndex = classOffset + index;
         CPClass cpString = (CPClass) stringsToCPClass.get(string);
         if (cpString == null) {
-            cpString = new CPClass(cpUTF8Value(utf8Index,
-                    ClassConstantPool.DOMAIN_NORMALASCIIZ), globalIndex);
+            cpString = new CPClass(cpUTF8Value(utf8Index), globalIndex);
             stringsToCPClass.put(string, cpString);
         }
         return cpString;
@@ -608,26 +616,16 @@
     public CPClass cpClassValue(String string) {
         CPClass cpString = (CPClass) stringsToCPClass.get(string);
         if (cpString == null) {
-            int index = search(cpClass, string);
-            if(index != -1) {
-                return cpClassValue(index);
+        	Integer index = (Integer)mapClass.get(string);
+        	if(index != null) {
+        		return cpClassValue(index.intValue());
             }
-            cpString = new CPClass(cpUTF8Value(string,
-                    ClassConstantPool.DOMAIN_NORMALASCIIZ, false), -1);
+            cpString = new CPClass(cpUTF8Value(string, false), -1);
             stringsToCPClass.put(string, cpString);
         }
         return cpString;
     }
 
-    private int search(String[] array, String string) {
-        for (int i = 0; i < array.length; i++) {
-            if(array[i].equals(string)) {
-                return i;
-            }
-        }
-        return -1;
-    }
-
     public CPDouble cpDoubleValue(int index) {
         Double dbl = new Double(cpDouble[index]);
         CPDouble cpDouble = (CPDouble) doublesToCPDoubles.get(dbl);
@@ -643,11 +641,10 @@
         CPNameAndType cpNameAndType = (CPNameAndType) descriptorsToCPNameAndTypes
                 .get(descriptor);
         if (cpNameAndType == null) {
-            int descriptorDomain = ClassConstantPool.DOMAIN_UNDEFINED;
             int nameIndex = cpDescriptorNameInts[index];
             int descriptorIndex = cpDescriptorTypeInts[index];
             String descriptorString = cpSignature[descriptorIndex];
-                
+
             // For some reason, descriptors which have just plain
             // native types are stored in DOMAIN_NORMALASCIIZ rather
             // than in DOMAIN_SIGNATUREASCIIZ. This might indicate
@@ -662,18 +659,9 @@
                     break;
                 }
             }
-            int domain = ClassConstantPool.DOMAIN_NAMEANDTYPE;
-            CPUTF8 name = cpUTF8Value(nameIndex,
-                    ClassConstantPool.DOMAIN_NORMALASCIIZ);
-            if (nativeDescriptor) {
-                // Native signatures are stored in DOMAIN_NORMALASCIIZ, not
-                // DOMAIN_SIGNATUREASCIIZ for some reason.
-                descriptorDomain = ClassConstantPool.DOMAIN_NORMALASCIIZ;
-            } else {
-                descriptorDomain = ClassConstantPool.DOMAIN_SIGNATUREASCIIZ;
-            }
-            CPUTF8 descriptorU = cpSignatureValue(descriptorIndex, descriptorDomain);
-            cpNameAndType = new CPNameAndType(name, descriptorU, domain, index + descrOffset);
+            CPUTF8 name = cpUTF8Value(nameIndex);
+            CPUTF8 descriptorU = cpSignatureValue(descriptorIndex);
+            cpNameAndType = new CPNameAndType(name, descriptorU, index + descrOffset);
             descriptorsToCPNameAndTypes.put(descriptor, cpNameAndType);
         }
         return cpNameAndType;
@@ -698,24 +686,17 @@
     }
 
     public CPUTF8 cpSignatureValue(int index) {
-        return cpSignatureValue(index, ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
-    }
-
-    public CPUTF8 cpSignatureValue(int index, int domain) {
         int globalIndex;
         if(cpSignatureInts[index] != -1) {
             globalIndex = cpSignatureInts[index];
         } else {
             globalIndex = index + signatureOffset;
         }
-        if (stringsToCPUTF8[domain] == null) {
-            stringsToCPUTF8[domain] = new HashMap();
-        }
         String string = cpSignature[index];
-        CPUTF8 cpUTF8 = (CPUTF8) stringsToCPUTF8[domain].get(string);
+        CPUTF8 cpUTF8 = (CPUTF8) stringsToCPUTF8.get(string);
         if(cpUTF8 == null) {
-            cpUTF8 = new CPUTF8(string, domain, globalIndex);
-            stringsToCPUTF8[domain].put(string, cpUTF8);
+            cpUTF8 = new CPUTF8(string, globalIndex);
+            stringsToCPUTF8.put(string, cpUTF8);
         }
         return cpUTF8;
     }
@@ -724,11 +705,10 @@
         CPNameAndType cpNameAndType = (CPNameAndType) descriptorsToCPNameAndTypes
             .get(descriptor);
         if (cpNameAndType == null) {
-            int index = search(cpDescriptor, descriptor);
-            if(index != -1) {
-                return cpNameAndTypeValue(index);
+        	Integer index = (Integer)mapDescriptor.get(descriptor);
+        	if(index != null) {
+        		return cpNameAndTypeValue(index.intValue());
             }
-            int descriptorDomain = ClassConstantPool.DOMAIN_UNDEFINED;
             int colon = descriptor.indexOf(':');
             String nameString = descriptor.substring(0, colon);
             String descriptorString = descriptor.substring(colon + 1);
@@ -746,18 +726,9 @@
                     break;
                 }
             }
-            int domain = ClassConstantPool.DOMAIN_NAMEANDTYPE;
-            CPUTF8 name = cpUTF8Value(nameString,
-                    ClassConstantPool.DOMAIN_NORMALASCIIZ, true);
-            if (nativeDescriptor) {
-                // Native signatures are stored in DOMAIN_NORMALASCIIZ, not
-                // DOMAIN_SIGNATUREASCIIZ for some reason.
-                descriptorDomain = ClassConstantPool.DOMAIN_NORMALASCIIZ;
-            } else {
-                descriptorDomain = ClassConstantPool.DOMAIN_SIGNATUREASCIIZ;
-            }
-            CPUTF8 descriptorU = cpUTF8Value(descriptorString, descriptorDomain, true);
-            cpNameAndType = new CPNameAndType(name, descriptorU, domain, index + descrOffset);
+            CPUTF8 name = cpUTF8Value(nameString, true);
+            CPUTF8 descriptorU = cpUTF8Value(descriptorString, true);
+            cpNameAndType = new CPNameAndType(name, descriptorU, -1 + descrOffset);
             descriptorsToCPNameAndTypes.put(descriptor, cpNameAndType);
         }
         return cpNameAndType;

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/FileBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/FileBands.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/FileBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/FileBands.java Fri Aug 22 00:15:00 2008
@@ -20,6 +20,7 @@
 import java.io.InputStream;
 
 import org.apache.harmony.pack200.Codec;
+import org.apache.harmony.pack200.Pack200Exception;
 
 /**
  * Parses the file band headers (not including the actual bits themselves). At
@@ -54,10 +55,10 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
      */
-    public void unpack(InputStream in) throws IOException, Pack200Exception {
+    public void read(InputStream in) throws IOException, Pack200Exception {
         int numberOfFiles = header.getNumberOfFiles();
         SegmentOptions options = header.getOptions();
 
@@ -92,13 +93,17 @@
             // not the right choice, and we should just serialize it here?
             fileBits[i] = new byte[size];
             int read = in.read(fileBits[i]);
-            if (read < size) {
+            if (size != 0 && read < size) {
                 throw new Pack200Exception("Expected to read " + size
                         + " bytes but read " + read);
             }
         }
     }
 
+    public void unpack() {
+
+    }
+
     public byte[][] getFileBits() {
         return fileBits;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java Fri Aug 22 00:15:00 2008
@@ -19,10 +19,12 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.harmony.pack200.Codec;
+import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.unpack200.bytecode.CPClass;
 import org.apache.harmony.unpack200.bytecode.ClassConstantPool;
 
@@ -48,10 +50,10 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
      */
-    public void unpack(InputStream in) throws IOException, Pack200Exception {
+    public void read(InputStream in) throws IOException, Pack200Exception {
         // Read IC bands
         int innerClassCount = header.getInnerClassCount();
         int[] icThisClassInts = decodeBandInt("ic_this_class", in,
@@ -103,6 +105,11 @@
         }
     }
 
+    public void unpack() throws IOException, Pack200Exception {
+
+    }
+
+
     public IcTuple[] getIcTuples() {
         return icAll;
     }
@@ -110,7 +117,7 @@
     /**
      * Answer the relevant IcTuples for the specified className and class
      * constant pool.
-     * 
+     *
      * @param className
      *            String name of the class X for ic_relevant(X)
      * @param cp
@@ -118,11 +125,13 @@
      * @return array of IcTuple
      */
     public IcTuple[] getRelevantIcTuples(String className, ClassConstantPool cp) {
+        Set relevantTuplesContains = new HashSet();
         List relevantTuples = new ArrayList();
         IcTuple[] allTuples = getIcTuples();
         int allTuplesSize = allTuples.length;
         for (int index = 0; index < allTuplesSize; index++) {
             if (allTuples[index].shouldAddToRelevantForClassName(className)) {
+                relevantTuplesContains.add(allTuples[index]);
                 relevantTuples.add(allTuples[index]);
             }
         }
@@ -136,14 +145,13 @@
         while (changed) {
             changed = false;
             for (int allTupleIndex = 0; allTupleIndex < allTuplesSize; allTupleIndex++) {
-                Iterator it = classPoolClasses.iterator();
-                while (it.hasNext()) {
-                    CPClass classInPool = (CPClass) it.next();
+                for(int cpcIndex = 0; cpcIndex < classPoolClasses.size(); cpcIndex++) {
+                    CPClass classInPool = (CPClass) classPoolClasses.get(cpcIndex);
                     String poolClassName = classInPool.name;
                     if (poolClassName.equals(allTuples[allTupleIndex]
                             .thisClassString())) {
                         // If the tuple isn't already in there, then add it
-                        if (relevantTuples.indexOf(allTuples[allTupleIndex]) == -1) {
+                        if (relevantTuplesContains.add(allTuples[allTupleIndex])) {
                             relevantTuples.add(allTuples[allTupleIndex]);
                             changed = true;
                         }
@@ -174,10 +182,9 @@
                 }
             }
             if (tuplesToAdd.size() > 0) {
-                Iterator it = tuplesToAdd.iterator();
-                while (it.hasNext()) {
-                    IcTuple tuple = (IcTuple) it.next();
-                    if (!relevantTuples.contains(tuple)) {
+                for(int index = 0; index < tuplesToAdd.size(); index++) {
+                    IcTuple tuple = (IcTuple) tuplesToAdd.get(index);
+                    if (relevantTuplesContains.add(tuple)) {
                         changedFixup = true;
                         relevantTuples.add(tuple);
                     }
@@ -191,7 +198,7 @@
         IcTuple[] orderedRelevantTuples = new IcTuple[relevantTuples.size()];
         int orderedRelevantIndex = 0;
         for (int index = 0; index < allTuplesSize; index++) {
-            if (relevantTuples.contains(allTuples[index])) {
+            if (relevantTuplesContains.contains(allTuples[index])) {
                 orderedRelevantTuples[orderedRelevantIndex] = allTuples[index];
                 orderedRelevantIndex++;
             }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcTuple.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcTuple.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcTuple.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcTuple.java Fri Aug 22 00:15:00 2008
@@ -20,7 +20,7 @@
 
 /**
  * An IcTuple is the set of information that describes an inner class.
- * 
+ *
  * C is the fully qualified class name<br>
  * F is the flags<br>
  * C2 is the outer class name, or null if it can be inferred from C<br>
@@ -33,7 +33,7 @@
     private final int nIndex;
 
     /**
-     * 
+     *
      * @param C
      * @param F
      * @param C2
@@ -69,12 +69,13 @@
     protected String C2; // outer class
     protected String N; // name
 
-    private boolean predictSimple = false;
-    private boolean predictOuter = false;
-    private String cachedOuterClassString = null;
-    private String cachedSimpleClassName = null;
-    private boolean initialized = false;
-    private boolean anonymous = false;
+    private boolean predictSimple;
+    private boolean predictOuter;
+    private String cachedOuterClassString;
+    private String cachedSimpleClassName;
+    private boolean initialized;
+    private boolean anonymous;
+    private boolean outerIsAnonymous;
     private boolean member = true;
     private int cachedOuterClassIndex = -1;
     private int cachedSimpleClassNameIndex = -1;
@@ -115,7 +116,7 @@
     /**
      * Answer the outer class name for the receiver. This may either be
      * specified or inferred from inner class name.
-     * 
+     *
      * @return String name of outer class
      */
     public String outerClassString() {
@@ -124,7 +125,7 @@
 
     /**
      * Answer the inner class name for the receiver.
-     * 
+     *
      * @return String name of inner class
      */
     public String simpleClassName() {
@@ -134,7 +135,7 @@
     /**
      * Answer the full name of the inner class represented by this tuple
      * (including its outer component)
-     * 
+     *
      * @return String full name of inner class
      */
     public String thisClassString() {
@@ -155,7 +156,12 @@
         return anonymous;
     }
 
+
     public boolean outerIsAnonymous() {
+        return outerIsAnonymous;
+    }
+
+    private boolean computeOuterIsAnonymous() {
         String[] result = innerBreakAtDollar(cachedOuterClassString);
         if (result.length == 0) {
             throw new Error(
@@ -250,6 +256,8 @@
                 member = true;
             }
         }
+
+        outerIsAnonymous = computeOuterIsAnonymous();
     }
 
     private boolean isAllDigits(String nameString) {
@@ -303,8 +311,21 @@
         return true;
     }
 
+    private boolean hashcodeComputed;
+    private int cachedHashCode;
+
+    private void generateHashCode() {
+        hashcodeComputed = true;
+        cachedHashCode = 17;
+        if(C != null) { cachedHashCode =+ C.hashCode(); }
+        if(C2 != null) { cachedHashCode =+ C2.hashCode(); }
+        if(N != null) { cachedHashCode =+ N.hashCode(); }
+    }
+
     public int hashCode() {
-        return 17 + C.hashCode() + C2.hashCode() + N.hashCode();
+        if (!hashcodeComputed)
+            generateHashCode();
+        return cachedHashCode;
     }
 
     public String getC() {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/MetadataBandGroup.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/MetadataBandGroup.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/MetadataBandGroup.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/MetadataBandGroup.java Fri Aug 22 00:15:00 2008
@@ -28,7 +28,6 @@
 import org.apache.harmony.unpack200.bytecode.CPInteger;
 import org.apache.harmony.unpack200.bytecode.CPLong;
 import org.apache.harmony.unpack200.bytecode.CPUTF8;
-import org.apache.harmony.unpack200.bytecode.ClassConstantPool;
 import org.apache.harmony.unpack200.bytecode.RuntimeVisibleorInvisibleAnnotationsAttribute;
 import org.apache.harmony.unpack200.bytecode.RuntimeVisibleorInvisibleParameterAnnotationsAttribute;
 import org.apache.harmony.unpack200.bytecode.AnnotationsAttribute.Annotation;
@@ -42,17 +41,13 @@
 
     private final String type;
     private final CpBands cpBands;
-    
-    private final CPUTF8 rvaUTF8 = new CPUTF8("RuntimeVisibleAnnotations",
-            ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
-    private final CPUTF8 riaUTF8 = new CPUTF8("RuntimeInvisibleAnnotations",
-            ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
+
+    private final CPUTF8 rvaUTF8 = new CPUTF8("RuntimeVisibleAnnotations");
+    private final CPUTF8 riaUTF8 = new CPUTF8("RuntimeInvisibleAnnotations");
     private final CPUTF8 rvpaUTF8 = new CPUTF8(
-            "RuntimeVisibleParameterAnnotations",
-            ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
+            "RuntimeVisibleParameterAnnotations");
     private final CPUTF8 ripaUTF8 = new CPUTF8(
-            "RuntimeInvisibleParameterAnnotations",
-            ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
+            "RuntimeInvisibleParameterAnnotations");
 
     public MetadataBandGroup(String type, CpBands cpBands) {
         this.type = type;
@@ -80,59 +75,58 @@
     public int[] nestpair_N;
     public CPUTF8[] nestname_RU;
 
-    private Iterator caseI_Iterator;
+    private int caseI_KI_Index;
 
-    private Iterator caseD_Iterator;
+    private int caseD_KD_Index;
 
-    private Iterator caseF_Iterator;
+    private int caseF_KF_Index;
 
-    private Iterator caseJ_Iterator;
+    private int caseJ_KJ_Index;
 
-    private Iterator casec_Iterator;
+    private int casec_RS_Index;
 
-    private Iterator caseet_Iterator;
+    private int caseet_RS_Index;
 
-    private Iterator caseec_Iterator;
+    private int caseec_RU_Index;
 
-    private Iterator cases_Iterator;
+    private int cases_RU_Index;
 
-    private Iterator casearray_Iterator;
+    private int casearray_N_Index;
 
-    private Iterator T_iterator;
+    private int T_index;
 
-    private Iterator nesttype_RS_Iterator;
+    private int nesttype_RS_Index;
 
-    private Iterator nestpair_N_Iterator;
+    private int nestpair_N_Index;
 
     private Iterator nestname_RU_Iterator;
 
-    private Iterator anno_N_Iterator;
+    private int anno_N_Index;
 
     private Iterator type_RS_Iterator;
 
-    private Iterator pair_N_Iterator;
+    private int pair_N_Index;
 
     public List getAttributes() {
+        // TODO: Optimize iterators!
         if (attributes == null) {
             attributes = new ArrayList();
             if (name_RU != null) {
                 Iterator name_RU_Iterator = Arrays.asList(name_RU).iterator();
                 if (!type.equals("AD")) {
-                    T_iterator = Arrays.asList(boxArray(T)).iterator();
+                    T_index = 0;
                 }
-                caseI_Iterator = Arrays.asList(caseI_KI).iterator();
-                caseD_Iterator = Arrays.asList(caseD_KD).iterator();
-                caseF_Iterator = Arrays.asList(caseF_KF).iterator();
-                caseJ_Iterator = Arrays.asList(caseJ_KJ).iterator();
-                casec_Iterator = Arrays.asList(casec_RS).iterator();
-                caseet_Iterator = Arrays.asList(caseet_RS).iterator();
-                caseec_Iterator = Arrays.asList(caseec_RU).iterator();
-                cases_Iterator = Arrays.asList(cases_RU).iterator();
-                casearray_Iterator = Arrays.asList(boxArray(casearray_N))
-                        .iterator();
-                nesttype_RS_Iterator = Arrays.asList(nesttype_RS).iterator();
-                nestpair_N_Iterator = Arrays.asList(boxArray(nestpair_N))
-                        .iterator();
+                caseI_KI_Index = 0;
+                caseD_KD_Index = 0;
+                caseF_KF_Index = 0;
+                caseJ_KJ_Index = 0;
+                casec_RS_Index = 0;
+                caseet_RS_Index = 0;
+                caseec_RU_Index = 0;
+                cases_RU_Index = 0;
+                casearray_N_Index = 0;
+                nesttype_RS_Index = 0;
+                nestpair_N_Index = 0;
                 nestname_RU_Iterator = Arrays.asList(nestname_RU).iterator();
                 if (type.equals("RVA") || type.equals("RIA")) {
                     for (int i = 0; i < anno_N.length; i++) {
@@ -140,10 +134,9 @@
                                 pair_N[i], name_RU_Iterator));
                     }
                 } else if (type.equals("RVPA") || type.equals("RIPA")) {
-                    anno_N_Iterator = Arrays.asList(boxArray(anno_N))
-                            .iterator();
+                    anno_N_Index = 0;
                     type_RS_Iterator = Arrays.asList(type_RS).iterator();
-                    pair_N_Iterator = Arrays.asList(pair_N).iterator();
+                    pair_N_Index = 0;
                     for (int i = 0; i < param_NB.length; i++) {
                         attributes.add(getParameterAttribute(param_NB[i],
                                 name_RU_Iterator));
@@ -174,8 +167,8 @@
             Iterator namesIterator) {
         ParameterAnnotation[] parameter_annotations = new ParameterAnnotation[numParameters];
         for (int i = 0; i < numParameters; i++) {
-            int numAnnotations = ((Integer) anno_N_Iterator.next()).intValue();
-            int[] pairCounts = (int[]) pair_N_Iterator.next();
+            int numAnnotations = anno_N[anno_N_Index++];
+            int[] pairCounts = pair_N[pair_N_Index++];
             Annotation[] annotations = new Annotation[numAnnotations];
             for (int j = 0; j < annotations.length; j++) {
                 annotations[j] = getAnnotation(
@@ -195,7 +188,7 @@
         ElementValue[] elementValues = new ElementValue[pairCount];
         for (int j = 0; j < elementNames.length; j++) {
             elementNames[j] = (CPUTF8) namesIterator.next();
-            int t = ((Integer) T_iterator.next()).intValue();
+            int t = T[T_index++];
             elementValues[j] = new ElementValue(t, getNextValue(t));
         }
         return new Annotation(pairCount, type, elementNames, elementValues);
@@ -208,46 +201,38 @@
         case 'I':
         case 'S':
         case 'Z':
-            return caseI_Iterator.next();
+            return caseI_KI[caseI_KI_Index++];
         case 'D':
-            return caseD_Iterator.next();
+            return caseD_KD[caseD_KD_Index++];
         case 'F':
-            return caseF_Iterator.next();
+            return caseF_KF[caseF_KF_Index++];
         case 'J':
-            return caseJ_Iterator.next();
+            return caseJ_KJ[caseJ_KJ_Index++];
         case 'c':
-            return casec_Iterator.next();
+            return casec_RS[casec_RS_Index++];
         case 'e':
             // TODO: check this - it may not work if the first string already
             // has a colon in it
-            String enumString = caseet_Iterator.next() + ":"
-                    + caseec_Iterator.next();
+            String enumString = caseet_RS[caseet_RS_Index++] + ":"
+                    + caseec_RU[caseec_RU_Index++];
             return cpBands.cpNameAndTypeValue(enumString);
         case 's':
-            return cases_Iterator.next();
+            return cases_RU[cases_RU_Index++];
         case '[':
-            int arraySize = ((Integer) casearray_Iterator.next()).intValue();
+            int arraySize = casearray_N[casearray_N_Index++];
             ElementValue[] nestedArray = new ElementValue[arraySize];
             for (int i = 0; i < arraySize; i++) {
-                int nextT = ((Integer) T_iterator.next()).intValue();
+                int nextT = T[T_index++];
                 nestedArray[i] = new ElementValue(nextT, getNextValue(nextT));
             }
             return nestedArray;
         case '@':
-            CPUTF8 type = (CPUTF8) nesttype_RS_Iterator.next();
-            int numPairs = ((Integer) nestpair_N_Iterator.next()).intValue();
+            CPUTF8 type = (CPUTF8) nesttype_RS[nesttype_RS_Index++];
+            int numPairs = nestpair_N[nestpair_N_Index++];
 
             return getAnnotation(type, numPairs, nestname_RU_Iterator);
         }
         return null;
     }
 
-    private Integer[] boxArray(int[] unboxed) {
-        Integer[] boxed = new Integer[unboxed.length];
-        for (int i = 0; i < boxed.length; i++) {
-            boxed[i] = new Integer(unboxed[i]);
-        }
-        return boxed;
-    }
-
 }
\ No newline at end of file

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java Fri Aug 22 00:15:00 2008
@@ -20,11 +20,11 @@
 import java.io.InputStream;
 import java.io.StringReader;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.harmony.pack200.BHSDCodec;
 import org.apache.harmony.pack200.Codec;
+import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.unpack200.bytecode.Attribute;
 import org.apache.harmony.unpack200.bytecode.CPClass;
 import org.apache.harmony.unpack200.bytecode.CPDouble;
@@ -37,7 +37,6 @@
 import org.apache.harmony.unpack200.bytecode.CPNameAndType;
 import org.apache.harmony.unpack200.bytecode.CPString;
 import org.apache.harmony.unpack200.bytecode.CPUTF8;
-import org.apache.harmony.unpack200.bytecode.ClassConstantPool;
 import org.apache.harmony.unpack200.bytecode.NewAttribute;
 
 /**
@@ -61,28 +60,27 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
      */
-    public void unpack(InputStream in) throws IOException, Pack200Exception {
+    public void read(InputStream in) throws IOException, Pack200Exception {
         // does nothing - use parseAttributes instead
     }
 
     /**
      * Parse the bands relating to this AttributeLayout and return the correct
      * class file attributes as a List of {@link Attribute}
-     * 
+     *
      * @throws Pack200Exception
      */
     public List parseAttributes(InputStream in, int occurrenceCount)
             throws IOException, Pack200Exception {
-        for (Iterator iter = attributeLayoutElements.iterator(); iter.hasNext();) {
-            AttributeLayoutElement element = (AttributeLayoutElement) iter
-                    .next();
+        for(int i = 0; i < attributeLayoutElements.size(); i++) {
+            AttributeLayoutElement element = (AttributeLayoutElement) attributeLayoutElements.get(i);
             element.readBands(in, occurrenceCount);
         }
 
-        List attributes = new ArrayList();
+        List attributes = new ArrayList(occurrenceCount);
         for (int i = 0; i < occurrenceCount; i++) {
             attributes.add(getOneAttribute(i, attributeLayoutElements));
         }
@@ -92,19 +90,17 @@
     /**
      * Get one attribute at the given index from the various bands. The correct
      * bands must have already been read in.
-     * 
+     *
      * @param index
      * @param elements
      * @return
      */
     private Attribute getOneAttribute(int index, List elements) {
         NewAttribute attribute = new NewAttribute(segment.getCpBands()
-                .cpUTF8Value(attributeLayout.getName(),
-                        ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ),
+                .cpUTF8Value(attributeLayout.getName()),
                 attributeLayout.getIndex());
-        for (Iterator iter = elements.iterator(); iter.hasNext();) {
-            AttributeLayoutElement element = (AttributeLayoutElement) iter
-                    .next();
+        for(int i = 0; i < elements.size(); i++) {
+            AttributeLayoutElement element = (AttributeLayoutElement) elements.get(i);
             element.addToAttribute(index, attribute);
         }
         return attribute;
@@ -112,7 +108,7 @@
 
     /**
      * Tokenise the layout into AttributeElements
-     * 
+     *
      * @throws IOException
      */
     private void parseLayout() throws IOException {
@@ -130,7 +126,7 @@
     /**
      * Resolve calls in the attribute layout and returns the number of backwards
      * calls
-     * 
+     *
      * @param tokens -
      *            the attribute layout as a List of AttributeElements
      */
@@ -142,8 +138,8 @@
             if (element instanceof Callable) {
                 Callable callable = (Callable) element;
                 List body = callable.body; // Look for calls in the body
-                for (Iterator iter = body.iterator(); iter.hasNext();) {
-                    LayoutElement layoutElement = (LayoutElement) iter.next();
+                for(int iIndex = 0; iIndex < body.size(); iIndex++) {
+                    LayoutElement layoutElement = (LayoutElement) body.get(iIndex);
                     if (layoutElement instanceof Call) {
                         // Set the callable for each call
                         Call call = (Call) layoutElement;
@@ -283,7 +279,7 @@
 
     /**
      * Read a UnionCase from the stream
-     * 
+     *
      * @param stream
      * @return
      * @throws IOException
@@ -322,7 +318,7 @@
 
         /**
          * Read the bands associated with this part of the layout
-         * 
+         *
          * @param in
          * @param count
          * @throws Pack200Exception
@@ -334,7 +330,7 @@
         /**
          * Add the band data for this element at the given index to the
          * attribute
-         * 
+         *
          * @param index
          * @param attribute
          */
@@ -454,8 +450,8 @@
             for (int i = 0; i < count; i++) {
                 arrayCount += countElement.getValue(i);
             }
-            for (Iterator iter = layoutElements.iterator(); iter.hasNext();) {
-                LayoutElement element = (LayoutElement) iter.next();
+            for(int i = 0; i < layoutElements.size(); i++) {
+                LayoutElement element = (LayoutElement) layoutElements.get(i);
                 element.readBands(in, arrayCount);
             }
         }
@@ -471,8 +467,8 @@
             }
             long numElements = countElement.getValue(index);
             for (int i = offset; i < offset + numElements; i++) {
-                for (Iterator iter = layoutElements.iterator(); iter.hasNext();) {
-                    LayoutElement element = (LayoutElement) iter.next();
+                for (int it = 0; it < layoutElements.size(); it++) {
+                    LayoutElement element = (LayoutElement) layoutElements.get(it);
                     element.addToAttribute(i, attribute);
                 }
             }
@@ -515,8 +511,8 @@
             // Count number of default cases then read the default bands
             for (int i = 0; i < values.length; i++) {
                 boolean found = false;
-                for (Iterator iter = unionCases.iterator(); iter.hasNext();) {
-                    UnionCase unionCase = (UnionCase) iter.next();
+                for(int it = 0; it < unionCases.size(); it++) {
+                    UnionCase unionCase = (UnionCase) unionCases.get(it);
                     if (unionCase.hasTag(values[i])) {
                         found = true;
                     }
@@ -526,8 +522,8 @@
                 }
             }
             if (defaultCaseBody != null) {
-                for (Iterator iter = defaultCaseBody.iterator(); iter.hasNext();) {
-                    LayoutElement element = (LayoutElement) iter.next();
+                for(int i = 0; i < defaultCaseBody.size(); i++) {
+                    LayoutElement element = (LayoutElement) defaultCaseBody.get(i);
                     element.readBands(in, defaultCount);
                 }
             }
@@ -539,8 +535,8 @@
             long[] tagBand = unionTag.band;
             long tag = unionTag.getValue(n);
             boolean defaultCase = true;
-            for (Iterator iter = unionCases.iterator(); iter.hasNext();) {
-                UnionCase element = (UnionCase) iter.next();
+            for(int i = 0; i < unionCases.size(); i++) {
+                UnionCase element = (UnionCase) unionCases.get(i);
                 if (element.hasTag(tag)) {
                     defaultCase = false;
                     for (int j = 0; j < n; j++) {
@@ -556,8 +552,8 @@
                 int defaultOffset = 0;
                 for (int j = 0; j < n; j++) {
                     boolean found = false;
-                    for (Iterator iter = unionCases.iterator(); iter.hasNext();) {
-                        UnionCase element = (UnionCase) iter.next();
+                    for(int i = 0; i < unionCases.size(); i++) {
+                        UnionCase element = (UnionCase) unionCases.get(i);
                         if (element.hasTag(tagBand[j])) {
                             found = true;
                         }
@@ -567,9 +563,8 @@
                     }
                 }
                 if (defaultCaseBody != null) {
-                    for (Iterator iter = defaultCaseBody.iterator(); iter
-                            .hasNext();) {
-                        LayoutElement element = (LayoutElement) iter.next();
+                    for(int i = 0; i < defaultCaseBody.size(); i++) {
+                        LayoutElement element = (LayoutElement) defaultCaseBody.get(i);
                         element.addToAttribute(defaultOffset, attribute);
                     }
                 }
@@ -715,12 +710,12 @@
         /**
          * Used by calls when adding band contents to attributes so they don't
          * have to keep track of the internal index of the callable
-         * 
+         *
          * @param attribute
          */
         public void addNextToAttribute(NewAttribute attribute) {
-            for (Iterator iter = body.iterator(); iter.hasNext();) {
-                LayoutElement element = (LayoutElement) iter.next();
+            for(int i = 0; i < body.size(); i++) {
+                LayoutElement element = (LayoutElement) body.get(i);
                 element.addToAttribute(index, attribute);
             }
             index++;
@@ -728,7 +723,7 @@
 
         /**
          * Adds the count of a call to this callable (ie the number of calls)
-         * 
+         *
          * @param count
          */
         public void addCount(int count) {
@@ -738,16 +733,16 @@
         public void readBands(InputStream in, int count) throws IOException,
                 Pack200Exception {
             count += this.count;
-            for (Iterator iter = body.iterator(); iter.hasNext();) {
-                LayoutElement element = (LayoutElement) iter.next();
+            for(int i = 0; i < body.size(); i++) {
+                LayoutElement element = (LayoutElement) body.get(i);
                 element.readBands(in, count);
             }
         }
 
         public void addToAttribute(int n, NewAttribute attribute) {
             // Ignore n because bands also contain element parts from calls
-            for (Iterator iter = body.iterator(); iter.hasNext();) {
-                LayoutElement element = (LayoutElement) iter.next();
+            for(int i = 0; i < body.size(); i++) {
+                LayoutElement element = (LayoutElement) body.get(i);
                 element.addToAttribute(index, attribute);
             }
             index++;
@@ -790,8 +785,8 @@
         public void readBands(InputStream in, int count) throws IOException,
                 Pack200Exception {
             if (body != null) {
-                for (Iterator iter = body.iterator(); iter.hasNext();) {
-                    LayoutElement element = (LayoutElement) iter.next();
+                for(int i = 0; i < body.size(); i++) {
+                    LayoutElement element = (LayoutElement) body.get(i);
                     element.readBands(in, count);
                 }
             }
@@ -799,8 +794,8 @@
 
         public void addToAttribute(int index, NewAttribute attribute) {
             if (body != null) {
-                for (Iterator iter = body.iterator(); iter.hasNext();) {
-                    LayoutElement element = (LayoutElement) iter.next();
+                for(int i = 0; i < body.size(); i++) {
+                    LayoutElement element = (LayoutElement) body.get(i);
                     element.addToAttribute(index, attribute);
                 }
             }
@@ -810,7 +805,7 @@
     /**
      * Utility method to get the contents of the given stream, up to the next
      * ']', (ignoring pairs of brackets '[' and ']')
-     * 
+     *
      * @param stream
      * @return
      * @throws IOException
@@ -837,7 +832,7 @@
     /**
      * Returns the {@link BHSDCodec} that should be used for the given layout
      * element
-     * 
+     *
      * @param layoutElement
      */
     public BHSDCodec getCodec(String layoutElement) {
@@ -858,7 +853,7 @@
     /**
      * Utility method to get the contents of the given stream, up to the next
      * ']', (ignoring pairs of brackets '[' and ']')
-     * 
+     *
      * @param stream
      * @return
      * @throws IOException
@@ -884,7 +879,7 @@
 
     /**
      * Read a number from the stream and return it
-     * 
+     *
      * @param stream
      * @return
      * @throws IOException
@@ -913,7 +908,7 @@
 
     /**
      * Read a 'body' section of the layout from the given stream
-     * 
+     *
      * @param stream
      * @return List of LayoutElements
      * @throws IOException
@@ -935,7 +930,7 @@
      * Once the attribute bands have been read the callables can be informed
      * about the number of times each is subject to a backwards call. This
      * method is used to set this information.
-     * 
+     *
      * @param backwardsCalls
      *            one int for each backwards callable, which contains the number
      *            of times that callable is subject to a backwards call.
@@ -944,9 +939,8 @@
     public void setBackwardsCalls(int[] backwardsCalls) throws IOException {
         int index = 0;
         parseLayout();
-        for (Iterator iter = attributeLayoutElements.iterator(); iter.hasNext();) {
-            AttributeLayoutElement element = (AttributeLayoutElement) iter
-                    .next();
+        for(int i = 0; i < attributeLayoutElements.size(); i++) {
+            AttributeLayoutElement element = (AttributeLayoutElement) attributeLayoutElements.get(i);
             if (element instanceof Callable
                     && ((Callable) element).isBackwardsCallable()) {
                 ((Callable) element).addCount(backwardsCalls[index]);
@@ -955,4 +949,8 @@
         }
     }
 
+    public void unpack() throws IOException, Pack200Exception {
+
+    }
+
 }
\ No newline at end of file

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java?rev=687988&r1=687987&r2=687988&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java Fri Aug 22 00:15:00 2008
@@ -17,13 +17,14 @@
 package org.apache.harmony.unpack200;
 
 import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
@@ -31,6 +32,7 @@
 import java.util.zip.ZipEntry;
 
 import org.apache.harmony.pack200.Codec;
+import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.unpack200.bytecode.Attribute;
 import org.apache.harmony.unpack200.bytecode.CPClass;
 import org.apache.harmony.unpack200.bytecode.CPField;
@@ -49,14 +51,14 @@
  * combine (non-GZipped) archives into a single large archive by concatenation
  * alone. Thus all the hard work in unpacking an archive falls to understanding
  * a segment.
- * 
+ *
  * The first component of a segment is the header; this contains (amongst other
  * things) the expected counts of constant pool entries, which in turn defines
  * how many values need to be read from the stream. Because values are variable
  * width (see {@link Codec}), it is not possible to calculate the start of the
  * next segment, although one of the header values does hint at the size of the
  * segment if non-zero, which can be used for buffering purposes.
- * 
+ *
  * Note that this does not perform any buffering of the input stream; each value
  * will be read on a byte-by-byte basis. It does not perform GZip decompression
  * automatically; both of these are expected to be done by the caller if the
@@ -91,10 +93,20 @@
 
     private boolean deflateHint;
 
+    private boolean doPreRead;
+
     private int logLevel;
 
     private PrintWriter logStream;
 
+    private byte[][] classFilesContents;
+
+    private boolean[] fileDeflate;
+
+    private boolean[] fileIsClass;
+
+    private InputStream internalBuffer;
+
     private ClassFile buildClassFile(int classNum) throws Pack200Exception {
         ClassFile classFile = new ClassFile();
         classFile.major = header.getDefaultClassMajorVersion(); // TODO If
@@ -140,8 +152,7 @@
                     fileName = fullName.substring(i) + ".java";
                 }
                 sourceFileAttribute = new SourceFileAttribute(cpBands
-                        .cpUTF8Value(fileName,
-                                ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ, false));
+                        .cpUTF8Value(fileName, false));
                 classFile.attributes = new Attribute[] { (Attribute) cp
                         .add(sourceFileAttribute) };
             } else {
@@ -156,7 +167,7 @@
         // that will
         // be written out. Keep SourceFileAttributes out since we just
         // did them above.
-        ArrayList classAttributesWithoutSourceFileAttribute = new ArrayList();
+        ArrayList classAttributesWithoutSourceFileAttribute = new ArrayList(classAttributes.size());
         for (int index = 0; index < classAttributes.size(); index++) {
             Attribute attrib = (Attribute) classAttributes.get(index);
             if (!attrib.isSourceFileAttribute()) {
@@ -195,10 +206,8 @@
             int descriptorIndex = classBands.getFieldDescrInts()[classNum][i];
             int nameIndex = cpBands.getCpDescriptorNameInts()[descriptorIndex];
             int typeIndex = cpBands.getCpDescriptorTypeInts()[descriptorIndex];
-            CPUTF8 name = cpBands.cpUTF8Value(nameIndex,
-                    ClassConstantPool.DOMAIN_NORMALASCIIZ);
-            CPUTF8 descriptor = cpBands.cpSignatureValue(typeIndex,
-                    ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
+            CPUTF8 name = cpBands.cpUTF8Value(nameIndex);
+            CPUTF8 descriptor = cpBands.cpSignatureValue(typeIndex);
             cfFields[i] = cp.add(new CPField(name, descriptor, classBands
                     .getFieldFlags()[classNum][i], classBands
                     .getFieldAttributes()[classNum][i]));
@@ -212,10 +221,8 @@
 //            int colon = descriptorStr.indexOf(':');
             int nameIndex = cpBands.getCpDescriptorNameInts()[descriptorIndex];
             int typeIndex = cpBands.getCpDescriptorTypeInts()[descriptorIndex];
-            CPUTF8 name = cpBands.cpUTF8Value(nameIndex,
-                    ClassConstantPool.DOMAIN_NORMALASCIIZ);
-            CPUTF8 descriptor = cpBands.cpSignatureValue(typeIndex,
-                    ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
+            CPUTF8 name = cpBands.cpUTF8Value(nameIndex);
+            CPUTF8 descriptor = cpBands.cpSignatureValue(typeIndex);
             cfMethods[i] = cp.add(new CPMethod(name, descriptor, classBands
                     .getMethodFlags()[classNum][i], classBands
                     .getMethodAttributes()[classNum][i]));
@@ -234,7 +241,7 @@
             int innerClassIndex = ic_stored[index].thisClassIndex();
             int outerClassIndex = ic_stored[index].outerClassIndex();
             int simpleClassNameIndex = ic_stored[index].simpleClassNameIndex();
-            
+
             String innerClassString = ic_stored[index].thisClassString();
             String outerClassString = ic_stored[index].outerClassString();
             String simpleClassName = ic_stored[index].simpleClassName();
@@ -248,10 +255,8 @@
                     .cpClassValue(innerClassString);
             if (!ic_stored[index].isAnonymous()) {
                 innerName = simpleClassNameIndex != -1 ? cpBands.cpUTF8Value(
-                        simpleClassNameIndex,
-                        ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ) : cpBands
-                        .cpUTF8Value(simpleClassName,
-                                ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
+                        simpleClassNameIndex) : cpBands
+                        .cpUTF8Value(simpleClassName);
             }
 
             if (ic_stored[index].isMember()) {
@@ -308,7 +313,7 @@
     /**
      * Given an ic_local and an ic_relevant, use them to calculate what should
      * be added as ic_stored.
-     * 
+     *
      * @param ic_local
      *            IcTuple[] array of local transmitted tuples
      * @param ic_relevant
@@ -318,10 +323,10 @@
      *         have to determine if this is the case.
      */
     private IcTuple[] computeIcStored(IcTuple[] ic_local, IcTuple[] ic_relevant) {
-        List result = new ArrayList();
-        List resultCopy = new ArrayList();
-        List localList = new ArrayList();
-        List relevantList = new ArrayList();
+        List result = new ArrayList(ic_relevant.length);
+        List resultCopy = new ArrayList(ic_relevant.length);
+        List localList = new ArrayList(ic_relevant.length);
+        List relevantList = new ArrayList(ic_relevant.length);
         if (ic_local != null) {
             // If ic_local is null, this code doesn't get
             // executed - which means the list ends up being
@@ -340,14 +345,10 @@
 
         // Since we're removing while iterating, iterate over
         // a copy.
-        Iterator it = resultCopy.iterator();
-
-        while (it.hasNext()) {
-            IcTuple tuple = (IcTuple) it.next();
+        for(int i = 0; i < resultCopy.size(); i++) {
+            IcTuple tuple = (IcTuple) resultCopy.get(i);
             if (localList.contains(tuple) && relevantList.contains(tuple)) {
-                while (result.remove(tuple)) {
-                }
-                ;
+                while (result.remove(tuple));
             }
         }
         IcTuple[] resultArray = new IcTuple[result.size()];
@@ -358,9 +359,9 @@
     }
 
     /**
-     * This performs the actual work of parsing against a non-static instance of
-     * Segment.
-     * 
+     * This performs reading the data from the stream into non-static instance of
+     * Segment. After the completion of this method stream can be freed.
+     *
      * @param in
      *            the input stream to read from
      * @throws IOException
@@ -369,29 +370,93 @@
      *             if a problem occurs with an unexpected value or unsupported
      *             codec
      */
-    private void parseSegment(InputStream in) throws IOException,
+    private void readSegment(InputStream in) throws IOException,
             Pack200Exception {
         log(LOG_LEVEL_VERBOSE, "-------");
-        header = new SegmentHeader(this);
-        header.unpack(in);
         cpBands = new CpBands(this);
-        cpBands.unpack(in);
+        cpBands.read(in);
         attrDefinitionBands = new AttrDefinitionBands(this);
-        attrDefinitionBands.unpack(in);
+        attrDefinitionBands.read(in);
         icBands = new IcBands(this);
-        icBands.unpack(in);
+        icBands.read(in);
         classBands = new ClassBands(this);
-        classBands.unpack(in);
+        classBands.read(in);
         bcBands = new BcBands(this);
-        bcBands.unpack(in);
+        bcBands.read(in);
         fileBands = new FileBands(this);
-        fileBands.unpack(in);
+        fileBands.read(in);
+
+        fileBands.processFileBits();
+    }
+
+   /**
+     * This performs the actual work of parsing against a non-static instance of
+     * Segment. This method is intended to run concurrently for multiple segments.
+     *
+     * @throws IOException
+     *             if a problem occurs during reading from the underlying stream
+     * @throws Pack200Exception
+     *             if a problem occurs with an unexpected value or unsupported
+     *             codec
+     */
+    private void parseSegment() throws IOException, Pack200Exception {
+
+        header.unpack();
+        cpBands.unpack();
+        attrDefinitionBands.unpack();
+        icBands.unpack();
+        classBands.unpack();
+        bcBands.unpack();
+        fileBands.unpack();
+
+        int classNum = 0;
+        int numberOfFiles = header.getNumberOfFiles();
+        String[] fileName = fileBands.getFileName();
+        long[] fileOptions = fileBands.getFileOptions();
+        SegmentOptions options = header.getOptions();
+
+        classFilesContents = new byte[numberOfFiles][];
+        fileDeflate = new boolean[numberOfFiles];
+        fileIsClass = new boolean[numberOfFiles];
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        DataOutputStream dos = new DataOutputStream(bos);
+
+        for (int i = 0; i < numberOfFiles; i++) {
+            String name = fileName[i];
+
+            boolean nameIsEmpty = (name == null) || name.equals("");
+            boolean isClass = (fileOptions[i] & 2) == 2 || nameIsEmpty;
+            if (isClass && nameIsEmpty) {
+                name = cpBands.getCpClass()[classBands.getClassThisInts()[classNum]] + ".class";
+                fileName[i] = name;
+            }
+
+            if (!overrideDeflateHint) {
+                fileDeflate[i] = (fileOptions[i] & 1) == 1 || options.shouldDeflate();
+            } else {
+                fileDeflate[i] = deflateHint;
+            }
+
+            fileIsClass[i] = isClass;
+
+            if (isClass) {
+                ClassFile classFile = buildClassFile(classNum);
+                classFile.write(dos);
+                dos.flush();
+
+                classFilesContents[classNum] = bos.toByteArray();
+                bos.reset();
+
+                classNum++;
+            }
+        }
     }
 
     /**
      * Unpacks a packed stream (either .pack. or .pack.gz) into a corresponding
      * JarOuputStream.
-     * 
+     *
      * @throws Pack200Exception
      *             if there is a problem unpacking
      * @throws IOException
@@ -399,9 +464,40 @@
      */
     public void unpack(InputStream in, JarOutputStream out) throws IOException,
             Pack200Exception {
+        unpackRead(in);
+        unpackProcess();
+        unpackWrite(out);
+    }
+
+    /*
+     * Package-private accessors for unpacking stages
+     */
+    void unpackRead(InputStream in) throws IOException, Pack200Exception {
         if (!in.markSupported())
             in = new BufferedInputStream(in);
-        parseSegment(in);
+
+        header = new SegmentHeader(this);
+        header.read(in);
+
+        int size = (int)header.getArchiveSize() - header.getArchiveSizeOffset();
+
+        if (doPreRead && header.getArchiveSize() != 0) {
+            byte[] data = new byte[size];
+            in.read(data);
+            internalBuffer = new BufferedInputStream(new ByteArrayInputStream(data));
+        } else {
+            readSegment(in);
+        }
+    }
+
+    void unpackProcess() throws IOException, Pack200Exception {
+        if(internalBuffer != null) {
+            readSegment(internalBuffer);
+        }
+        parseSegment();
+    }
+
+    void unpackWrite(JarOutputStream out) throws IOException, Pack200Exception {
         writeJar(out);
     }
 
@@ -411,7 +507,7 @@
      * reading, since the file bits may not be loaded and thus just copied from
      * one stream to another. Doesn't close the output stream when finished, in
      * case there are more entries (e.g. further segments) to be written.
-     * 
+     *
      * @param out
      *            the JarOutputStream to write data to
      * @throws IOException
@@ -421,11 +517,8 @@
      */
     public void writeJar(JarOutputStream out) throws IOException,
             Pack200Exception {
-        fileBands.processFileBits();
-        DataOutputStream dos = new DataOutputStream(out);
         String[] fileName = fileBands.getFileName();
         long[] fileModtime = fileBands.getFileModtime();
-        long[] fileOptions = fileBands.getFileOptions();
         long[] fileSize = fileBands.getFileSize();
         byte[][] fileBits = fileBands.getFileBits();
 
@@ -434,44 +527,31 @@
         int classNum = 0;
         int numberOfFiles = header.getNumberOfFiles();
         long archiveModtime = header.getArchiveModtime();
-        SegmentOptions options = header.getOptions();
+
         for (int i = 0; i < numberOfFiles; i++) {
             String name = fileName[i];
             long modtime = archiveModtime + fileModtime[i];
-            boolean deflate = (fileOptions[i] & 1) == 1
-                    || options.shouldDeflate();
-            if (overrideDeflateHint) { // Overridden by a command line argument
-                deflate = deflateHint;
-            }
-            boolean isClass = (fileOptions[i] & 2) == 2 || name == null
-                    || name.equals("");
-            if (isClass) {
-                // pull from headers
-                if (name == null || name.equals(""))
-                    name = cpBands.getCpClass()[classBands.getClassThisInts()[classNum]] + ".class";
-            }
+            boolean deflate = fileDeflate[i];
+
             JarEntry entry = new JarEntry(name);
             if (deflate)
                 entry.setMethod(ZipEntry.DEFLATED);
             entry.setTime(modtime);
             out.putNextEntry(entry);
 
-            if (isClass) {
+            if (fileIsClass[i]) {
                 // write to dos
-                ClassFile classFile = buildClassFile(classNum);
-                classFile.write(dos);
-                dos.flush();
+                entry.setSize(classFilesContents[classNum].length);
+                out.write(classFilesContents[classNum]);
                 classNum++;
             } else {
                 long size = fileSize[i];
                 entry.setSize(size);
-                // TODO pull from in
+
                 byte[] data = fileBits[i];
                 out.write(data);
             }
         }
-        dos.flush();
-        out.flush();
     }
 
     public SegmentConstantPool getConstantPool() {
@@ -482,6 +562,10 @@
         return header;
     }
 
+    public void setPreRead(boolean value) {
+        doPreRead = value;
+    }
+
     protected AttrDefinitionBands getAttrDefinitionBands() {
         return attrDefinitionBands;
     }
@@ -522,7 +606,7 @@
 
     /**
      * Override the archive's deflate hint with the given boolean
-     * 
+     *
      * @param deflateHint -
      *            the deflate hint to use
      */