harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r647100 [4/9] - in /harmony/enhanced/classlib/trunk/modules/pack200/src: main/java/org/apache/harmony/pack200/ main/java/org/apache/harmony/pack200/bytecode/ main/java/org/apache/harmony/pack200/bytecode/forms/ test/java/org/apache/harmony/...
Date Fri, 11 Apr 2008 10:10:00 GMT
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java?rev=647100&r1=647099&r2=647100&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java Fri Apr 11 03:09:38 2008
@@ -49,7 +49,8 @@
 
     private List attributeLayoutElements;
 
-    public NewAttributeBands(Segment segment, AttributeLayout attributeLayout) throws IOException {
+    public NewAttributeBands(Segment segment, AttributeLayout attributeLayout)
+            throws IOException {
         super(segment);
         this.attributeLayout = attributeLayout;
         parseLayout();
@@ -58,7 +59,7 @@
 
     /*
      * (non-Javadoc)
-     *
+     * 
      * @see org.apache.harmony.pack200.BandSet#unpack(java.io.InputStream)
      */
     public void unpack(InputStream in) throws IOException, Pack200Exception {
@@ -68,12 +69,14 @@
     /**
      * 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();
+            AttributeLayoutElement element = (AttributeLayoutElement) iter
+                    .next();
             element.readBands(in, occurrenceCount);
         }
 
@@ -85,8 +88,9 @@
     }
 
     /**
-     * Get one attribute at the given index from the various bands.
-     * The correct bands must have already been read in.
+     * 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
@@ -96,7 +100,8 @@
                 .cpUTF8Value(attributeLayout.getName(),
                         ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ));
         for (Iterator iter = elements.iterator(); iter.hasNext();) {
-            AttributeLayoutElement element = (AttributeLayoutElement) iter.next();
+            AttributeLayoutElement element = (AttributeLayoutElement) iter
+                    .next();
             element.addToAttribute(index, attribute);
         }
         return attribute;
@@ -104,10 +109,11 @@
 
     /**
      * Tokenise the layout into AttributeElements
+     * 
      * @throws IOException
      */
     private void parseLayout() throws IOException {
-        if(attributeLayoutElements == null) {
+        if (attributeLayoutElements == null) {
             attributeLayoutElements = new ArrayList();
             StringReader stream = new StringReader(attributeLayout.getLayout());
             AttributeLayoutElement e;
@@ -119,15 +125,17 @@
     }
 
     /**
-     * Resolve calls in the attribute layout and returns the number of backwards calls
-     *
+     * Resolve calls in the attribute layout and returns the number of backwards
+     * calls
+     * 
      * @param tokens -
      *            the attribute layout as a List of AttributeElements
      */
     private void resolveCalls() {
         int backwardsCalls = 0;
         for (int i = 0; i < attributeLayoutElements.size(); i++) {
-            AttributeLayoutElement element = (AttributeLayoutElement) attributeLayoutElements.get(i);
+            AttributeLayoutElement element = (AttributeLayoutElement) attributeLayoutElements
+                    .get(i);
             if (element instanceof Callable) {
                 Callable callable = (Callable) element;
                 List body = callable.body; // Look for calls in the body
@@ -272,6 +280,7 @@
 
     /**
      * Read a UnionCase from the stream
+     * 
      * @param stream
      * @return
      * @throws IOException
@@ -302,25 +311,27 @@
     }
 
     /**
-     * An AttributeLayoutElement is a part of an attribute layout and has one or more
-     * bands associated with it, which transmit the AttributeElement data for
-     * successive Attributes of this type.
+     * An AttributeLayoutElement is a part of an attribute layout and has one or
+     * more bands associated with it, which transmit the AttributeElement data
+     * for successive Attributes of this type.
      */
     private interface AttributeLayoutElement {
 
         /**
          * Read the bands associated with this part of the layout
-         *
+         * 
          * @param in
          * @param count
          * @throws Pack200Exception
          * @throws IOException
          */
-        public void readBands(InputStream in, int count) throws IOException, Pack200Exception;
+        public void readBands(InputStream in, int count) throws IOException,
+                Pack200Exception;
 
         /**
-         * Add the band data for this element at the given index to the attribute
-         *
+         * Add the band data for this element at the given index to the
+         * attribute
+         * 
          * @param index
          * @param attribute
          */
@@ -331,8 +342,9 @@
     private abstract class LayoutElement implements AttributeLayoutElement {
 
         protected int getLength(char uint_type) {
-            int length = 0;;
-            switch(uint_type) {
+            int length = 0;
+            ;
+            switch (uint_type) {
             case 'B':
                 length = 1;
                 break;
@@ -359,26 +371,29 @@
             this.tag = tag;
         }
 
-        public void readBands(InputStream in, int count) throws IOException, Pack200Exception {
-            band = decodeBandLong(attributeLayout.getName() + "_" + tag, in, getCodec(tag), count);
+        public void readBands(InputStream in, int count) throws IOException,
+                Pack200Exception {
+            band = decodeBandLong(attributeLayout.getName() + "_" + tag, in,
+                    getCodec(tag), count);
         }
 
         public void addToAttribute(int n, NewAttribute attribute) {
             long value = band[n];
-            if(tag.equals("B") || tag.equals("FB")) {
+            if (tag.equals("B") || tag.equals("FB")) {
                 attribute.addInteger(1, value);
             } else if (tag.equals("SB")) {
-                attribute.addInteger(1, (byte)value);
-            } else if(tag.equals("H") || tag.equals("FH")) {
-                attribute.addInteger(2,  value);
+                attribute.addInteger(1, (byte) value);
+            } else if (tag.equals("H") || tag.equals("FH")) {
+                attribute.addInteger(2, value);
             } else if (tag.equals("SH")) {
-                attribute.addInteger(2, (short)value);
+                attribute.addInteger(2, (short) value);
             } else if (tag.equals("I") || tag.equals("FI")) {
                 attribute.addInteger(4, value);
             } else if (tag.equals("SI")) {
                 attribute.addInteger(4, (int) value);
             } else if (tag.equals("V") || tag.equals("FV") || tag.equals("SV")) {
-                // Don't add V's - they shouldn't be written out to the class file
+                // Don't add V's - they shouldn't be written out to the class
+                // file
             } else if (tag.startsWith("PO")) {
                 char uint_type = tag.substring(2).toCharArray()[0];
                 int length = getLength(uint_type);
@@ -390,12 +405,12 @@
             } else if (tag.startsWith("OS")) {
                 char uint_type = tag.substring(1).toCharArray()[0];
                 int length = getLength(uint_type);
-                if(length == 1) {
-                    value = (byte)value;
-                } else if(length == 2) {
-                    value = (short)value;
-                } else if(length == 4) {
-                    value = (int)value;
+                if (length == 1) {
+                    value = (byte) value;
+                } else if (length == 2) {
+                    value = (short) value;
+                } else if (length == 4) {
+                    value = (int) value;
                 }
                 attribute.addBCLength(length, (int) value);
             } else if (tag.startsWith("O")) {
@@ -429,7 +444,8 @@
             }
         }
 
-        public void readBands(InputStream in, int count) throws IOException, Pack200Exception {
+        public void readBands(InputStream in, int count) throws IOException,
+                Pack200Exception {
             countElement.readBands(in, count);
             int arrayCount = 0;
             for (int i = 0; i < count; i++) {
@@ -460,7 +476,6 @@
         }
     }
 
-
     /**
      * A Union is a type of layout element where the tag value acts as a
      * selector for one of the union cases
@@ -479,7 +494,8 @@
             this.defaultCaseBody = body;
         }
 
-        public void readBands(InputStream in, int count) throws IOException, Pack200Exception {
+        public void readBands(InputStream in, int count) throws IOException,
+                Pack200Exception {
             unionTag.readBands(in, count);
             long[] values = unionTag.band;
             // Count the band size for each union case then read the bands
@@ -487,7 +503,7 @@
             for (int i = 0; i < caseCounts.length; i++) {
                 UnionCase unionCase = (UnionCase) unionCases.get(i);
                 for (int j = 0; j < values.length; j++) {
-                    if(unionCase.hasTag(values[j])) {
+                    if (unionCase.hasTag(values[j])) {
                         caseCounts[i]++;
                     }
                 }
@@ -498,15 +514,15 @@
                 boolean found = false;
                 for (Iterator iter = unionCases.iterator(); iter.hasNext();) {
                     UnionCase unionCase = (UnionCase) iter.next();
-                    if(unionCase.hasTag(values[i])) {
+                    if (unionCase.hasTag(values[i])) {
                         found = true;
                     }
                 }
-                if(!found) {
+                if (!found) {
                     defaultCount++;
                 }
             }
-            if(defaultCaseBody != null) {
+            if (defaultCaseBody != null) {
                 for (Iterator iter = defaultCaseBody.iterator(); iter.hasNext();) {
                     LayoutElement element = (LayoutElement) iter.next();
                     element.readBands(in, defaultCount);
@@ -522,33 +538,34 @@
             boolean defaultCase = true;
             for (Iterator iter = unionCases.iterator(); iter.hasNext();) {
                 UnionCase element = (UnionCase) iter.next();
-                if(element.hasTag(tag)) {
+                if (element.hasTag(tag)) {
                     defaultCase = false;
                     for (int j = 0; j < n; j++) {
-                        if(element.hasTag(tagBand[j])) {
+                        if (element.hasTag(tagBand[j])) {
                             offset++;
                         }
                     }
                     element.addToAttribute(offset, attribute);
                 }
             }
-            if(defaultCase) {
+            if (defaultCase) {
                 // default case
                 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();
-                        if(element.hasTag(tagBand[j])) {
+                        if (element.hasTag(tagBand[j])) {
                             found = true;
                         }
                     }
-                    if(!found) {
+                    if (!found) {
                         defaultOffset++;
                     }
                 }
-                if(defaultCaseBody != null) {
-                    for (Iterator iter = defaultCaseBody.iterator(); iter.hasNext();) {
+                if (defaultCaseBody != null) {
+                    for (Iterator iter = defaultCaseBody.iterator(); iter
+                            .hasNext();) {
                         LayoutElement element = (LayoutElement) iter.next();
                         element.addToAttribute(defaultOffset, attribute);
                     }
@@ -569,7 +586,7 @@
 
         public void setCallable(Callable callable) {
             this.callable = callable;
-            if(callableIndex < 1) {
+            if (callableIndex < 1) {
                 callable.setBackwardsCallable();
             }
         }
@@ -578,10 +595,10 @@
             /*
              * We don't read anything here, but we need to pass the extra count
              * to the callable if it's a forwards call. For backwards callables
-             * the count is transmitted directly in the attribute bands and
-             * so it is added later.
+             * the count is transmitted directly in the attribute bands and so
+             * it is added later.
              */
-            if(callableIndex > 0) {
+            if (callableIndex > 0) {
                 callable.addCount(count);
             }
         }
@@ -607,59 +624,73 @@
             length = getLength(tag.charAt(tag.length()));
         }
 
-        public void readBands(InputStream in, int count) throws IOException, Pack200Exception {
-            if(tag.startsWith("KI")) { // Integer
-                band = parseCPIntReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("KJ")) { // Long
-                band = parseCPLongReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("KF")) { // Float
-                band = parseCPFloatReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("KD")) { // Double
-                band = parseCPDoubleReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("KS")) { // String
-                band = parseCPStringReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("RC")) { // Class
-                band = parseCPClassReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("RS")) { // Signature
-                band = parseCPSignatureReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("RD")) { // Descriptor
-                band = parseCPDescriptorReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("RF")) { // Field Reference
-                band = parseCPFieldRefReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("RM")) { // Method Reference
-                band = parseCPMethodRefReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("RI")) { // Interface Method Reference
-                band = parseCPInterfaceMethodRefReferences(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
-            } else if(tag.startsWith("RU")) { // UTF8 String
-                band = parseCPUTF8References(attributeLayout.getName(), in, Codec.UNSIGNED5, count);
+        public void readBands(InputStream in, int count) throws IOException,
+                Pack200Exception {
+            if (tag.startsWith("KI")) { // Integer
+                band = parseCPIntReferences(attributeLayout.getName(), in,
+                        Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("KJ")) { // Long
+                band = parseCPLongReferences(attributeLayout.getName(), in,
+                        Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("KF")) { // Float
+                band = parseCPFloatReferences(attributeLayout.getName(), in,
+                        Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("KD")) { // Double
+                band = parseCPDoubleReferences(attributeLayout.getName(), in,
+                        Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("KS")) { // String
+                band = parseCPStringReferences(attributeLayout.getName(), in,
+                        Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("RC")) { // Class
+                band = parseCPClassReferences(attributeLayout.getName(), in,
+                        Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("RS")) { // Signature
+                band = parseCPSignatureReferences(attributeLayout.getName(),
+                        in, Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("RD")) { // Descriptor
+                band = parseCPDescriptorReferences(attributeLayout.getName(),
+                        in, Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("RF")) { // Field Reference
+                band = parseCPFieldRefReferences(attributeLayout.getName(), in,
+                        Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("RM")) { // Method Reference
+                band = parseCPMethodRefReferences(attributeLayout.getName(),
+                        in, Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("RI")) { // Interface Method Reference
+                band = parseCPInterfaceMethodRefReferences(attributeLayout
+                        .getName(), in, Codec.UNSIGNED5, count);
+            } else if (tag.startsWith("RU")) { // UTF8 String
+                band = parseCPUTF8References(attributeLayout.getName(), in,
+                        Codec.UNSIGNED5, count);
             }
         }
 
         public void addToAttribute(int n, NewAttribute attribute) {
-            if(tag.startsWith("KI")) { // Integer
-                attribute.addCPConstant(length, ((CPInteger[])band)[n]);
-            } else if(tag.startsWith("KJ")) { // Long
-                attribute.addCPConstant(length, ((CPLong[])band)[n]);
-            } else if(tag.startsWith("KF")) { // Float
-                attribute.addCPConstant(length, ((CPFloat[])band)[n]);
-            } else if(tag.startsWith("KD")) { // Double
-                attribute.addCPConstant(length, ((CPDouble[])band)[n]);
-            } else if(tag.startsWith("KS")) { // String
-                attribute.addCPConstant(length, ((CPString[])band)[n]);
-            } else if(tag.startsWith("RC")) { // Class
-                attribute.addCPClass(length, ((CPClass[])band)[n]);
-            } else if(tag.startsWith("RS")) { // Signature
-                attribute.addCPUTF8(length, ((CPUTF8[])band)[n]);
-            } else if(tag.startsWith("RD")) { // Descriptor
-                attribute.addCPNameAndType(length, ((CPNameAndType[])band)[n]);
-            } else if(tag.startsWith("RF")) { // Field Reference
-                attribute.addCPFieldRef(length, ((CPFieldRef[])band)[n]);
-            } else if(tag.startsWith("RM")) { // Method Reference
-                attribute.addCPMethodRef(length, ((CPMethodRef[])band)[n]);
-            } else if(tag.startsWith("RI")) { // Interface Method Reference
-                attribute.addCPIMethodRef(length, ((CPInterfaceMethodRef[])band)[n]);
-            } else if(tag.startsWith("RU")) { // UTF8 String
-                attribute.addCPUTF8(length, ((CPUTF8[])band)[n]);
+            if (tag.startsWith("KI")) { // Integer
+                attribute.addCPConstant(length, ((CPInteger[]) band)[n]);
+            } else if (tag.startsWith("KJ")) { // Long
+                attribute.addCPConstant(length, ((CPLong[]) band)[n]);
+            } else if (tag.startsWith("KF")) { // Float
+                attribute.addCPConstant(length, ((CPFloat[]) band)[n]);
+            } else if (tag.startsWith("KD")) { // Double
+                attribute.addCPConstant(length, ((CPDouble[]) band)[n]);
+            } else if (tag.startsWith("KS")) { // String
+                attribute.addCPConstant(length, ((CPString[]) band)[n]);
+            } else if (tag.startsWith("RC")) { // Class
+                attribute.addCPClass(length, ((CPClass[]) band)[n]);
+            } else if (tag.startsWith("RS")) { // Signature
+                attribute.addCPUTF8(length, ((CPUTF8[]) band)[n]);
+            } else if (tag.startsWith("RD")) { // Descriptor
+                attribute.addCPNameAndType(length, ((CPNameAndType[]) band)[n]);
+            } else if (tag.startsWith("RF")) { // Field Reference
+                attribute.addCPFieldRef(length, ((CPFieldRef[]) band)[n]);
+            } else if (tag.startsWith("RM")) { // Method Reference
+                attribute.addCPMethodRef(length, ((CPMethodRef[]) band)[n]);
+            } else if (tag.startsWith("RI")) { // Interface Method Reference
+                attribute.addCPIMethodRef(length,
+                        ((CPInterfaceMethodRef[]) band)[n]);
+            } else if (tag.startsWith("RU")) { // UTF8 String
+                attribute.addCPUTF8(length, ((CPUTF8[]) band)[n]);
             }
         }
 
@@ -679,9 +710,9 @@
         private int index;
 
         /**
-         * Used by calls when adding band contents to attributes
-         * so they don't have to keep track of the internal index
-         * of the callable
+         * 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) {
@@ -694,13 +725,15 @@
 
         /**
          * Adds the count of a call to this callable (ie the number of calls)
+         * 
          * @param count
          */
         public void addCount(int count) {
             this.count += count;
         }
 
-        public void readBands(InputStream in, int count) throws IOException, Pack200Exception {
+        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();
@@ -751,8 +784,9 @@
             this.body = body;
         }
 
-        public void readBands(InputStream in, int count) throws IOException, Pack200Exception {
-            if(body != null) {
+        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();
                     element.readBands(in, count);
@@ -761,7 +795,7 @@
         }
 
         public void addToAttribute(int index, NewAttribute attribute) {
-            if(body != null) {
+            if (body != null) {
                 for (Iterator iter = body.iterator(); iter.hasNext();) {
                     LayoutElement element = (LayoutElement) iter.next();
                     element.addToAttribute(index, attribute);
@@ -771,8 +805,9 @@
     }
 
     /**
-     * Utility method to get the contents of the given stream, up to the next ']',
-     * (ignoring pairs of brackets '[' and ']')
+     * Utility method to get the contents of the given stream, up to the next
+     * ']', (ignoring pairs of brackets '[' and ']')
+     * 
      * @param stream
      * @return
      * @throws IOException
@@ -797,7 +832,9 @@
     }
 
     /**
-     * Returns the {@link BHSDCodec} that should be used for the given layout element
+     * Returns the {@link BHSDCodec} that should be used for the given layout
+     * element
+     * 
      * @param layoutElement
      */
     public BHSDCodec getCodec(String layoutElement) {
@@ -816,8 +853,9 @@
     }
 
     /**
-     * Utility method to get the contents of the given stream, up to the next ']',
-     * (ignoring pairs of brackets '[' and ']')
+     * Utility method to get the contents of the given stream, up to the next
+     * ']', (ignoring pairs of brackets '[' and ']')
+     * 
      * @param stream
      * @return
      * @throws IOException
@@ -843,6 +881,7 @@
 
     /**
      * Read a number from the stream and return it
+     * 
      * @param stream
      * @return
      * @throws IOException
@@ -864,13 +903,14 @@
         char[] digits = new char[length];
         int read = stream.read(digits);
         if (read != digits.length) {
-        	throw new IOException("Error reading from the input stream");
+            throw new IOException("Error reading from the input stream");
         }
         return Integer.parseInt((negative ? "-" : "") + new String(digits));
     }
 
     /**
      * Read a 'body' section of the layout from the given stream
+     * 
      * @param stream
      * @return List of LayoutElements
      * @throws IOException
@@ -892,7 +932,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.
@@ -902,9 +942,11 @@
         int index = 0;
         parseLayout();
         for (Iterator iter = attributeLayoutElements.iterator(); iter.hasNext();) {
-            AttributeLayoutElement element = (AttributeLayoutElement) iter.next();
-            if(element instanceof Callable && ((Callable)element).isBackwardsCallable()) {
-                ((Callable)element).addCount(backwardsCalls[index]);
+            AttributeLayoutElement element = (AttributeLayoutElement) iter
+                    .next();
+            if (element instanceof Callable
+                    && ((Callable) element).isBackwardsCallable()) {
+                ((Callable) element).addCount(backwardsCalls[index]);
                 index++;
             }
         }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java?rev=647100&r1=647099&r2=647100&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java Fri Apr 11 03:09:38 2008
@@ -23,36 +23,36 @@
 
     private static final long serialVersionUID = 5168177401552611803L;
 
-	/**
-	 * Create a new Pack200 exception with the given message and cause
-	 *
-	 * @param message
-	 *            the text message to display
-	 */
-	public Pack200Exception(String message) {
-		super(message);
-	}
+    /**
+     * Create a new Pack200 exception with the given message and cause
+     * 
+     * @param message
+     *            the text message to display
+     */
+    public Pack200Exception(String message) {
+        super(message);
+    }
 
-	/**
-	 * Create a new Pack200 exception with the given message and cause
-	 *
-	 * @param message
-	 *            the text message to display
-	 * @param cause
-	 *            the {@link Throwable} that caused this problem
-	 */
-	public Pack200Exception(String message, Throwable cause) {
-		super(message, cause);
-	}
+    /**
+     * Create a new Pack200 exception with the given message and cause
+     * 
+     * @param message
+     *            the text message to display
+     * @param cause
+     *            the {@link Throwable} that caused this problem
+     */
+    public Pack200Exception(String message, Throwable cause) {
+        super(message, cause);
+    }
 
-	/**
-	 * Create a new Pack200 exception with the given message and cause
-	 *
-	 * @param cause
-	 *            the {@link Throwable} that caused this problem
-	 */
-	public Pack200Exception(Throwable cause) {
-		super(cause);
-	}
+    /**
+     * Create a new Pack200 exception with the given message and cause
+     * 
+     * @param cause
+     *            the {@link Throwable} that caused this problem
+     */
+    public Pack200Exception(Throwable cause) {
+        super(cause);
+    }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java?rev=647100&r1=647099&r2=647100&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java Fri Apr 11 03:09:38 2008
@@ -33,48 +33,50 @@
     private int l;
     private long[] favoured;
 
-    public PopulationCodec(Codec favouredCodec, Codec tableCodec, Codec unvafouredCodec) {
+    public PopulationCodec(Codec favouredCodec, Codec tableCodec,
+            Codec unvafouredCodec) {
         this.favouredCodec = favouredCodec;
         this.tokenCodec = tableCodec;
         this.unvafouredCodec = unvafouredCodec;
     }
 
     public PopulationCodec(Codec favouredCodec, int l, Codec unvafouredCodec) {
-        if (l >= 256 || l <=0)
+        if (l >= 256 || l <= 0)
             throw new IllegalArgumentException("L must be between 1..255");
         this.favouredCodec = favouredCodec;
         this.l = l;
         this.unvafouredCodec = unvafouredCodec;
     }
 
-
     public long decode(InputStream in) throws IOException, Pack200Exception {
-        throw new Pack200Exception("Population encoding does not work unless the number of elements are known");
+        throw new Pack200Exception(
+                "Population encoding does not work unless the number of elements are known");
     }
 
-
     public long decode(InputStream in, long last) throws IOException,
             Pack200Exception {
-        throw new Pack200Exception("Population encoding does not work unless the number of elements are known");
+        throw new Pack200Exception(
+                "Population encoding does not work unless the number of elements are known");
     }
 
-
-    public long[] decode(int n, InputStream in) throws IOException, Pack200Exception {
-        favoured = new long[n]; // there must be <= n  values, but probably a lot less
+    public long[] decode(int n, InputStream in) throws IOException,
+            Pack200Exception {
+        favoured = new long[n]; // there must be <= n values, but probably a lot
+        // less
         long result[];
         // read table of favorites first
         long smallest = Long.MAX_VALUE;
         long last = 0;
         long value = 0;
         int k = -1;
-        while( true ) {
-            value = favouredCodec.decode(in,last);
+        while (true) {
+            value = favouredCodec.decode(in, last);
             if (k > -1 && (value == smallest || value == last))
                 break;
             favoured[++k] = value;
             if (Math.abs(smallest) > Math.abs(value)) {
                 smallest = value;
-            } else if (Math.abs(smallest) == Math.abs(value) ) {
+            } else if (Math.abs(smallest) == Math.abs(value)) {
                 // ensure that -X and +X -> +X
                 smallest = Math.abs(smallest);
             }
@@ -87,36 +89,38 @@
             } else {
                 // if k >= 256, b >= 2
                 int b = 1;
-                while(++b < 5 && tokenCodec == null) {
-                    BHSDCodec codec = new BHSDCodec(b,256-l,0);
+                while (++b < 5 && tokenCodec == null) {
+                    BHSDCodec codec = new BHSDCodec(b, 256 - l, 0);
                     if (codec.encodes(k))
                         tokenCodec = codec;
                 }
                 if (tokenCodec == null)
-                    throw new Pack200Exception("Cannot calculate token codec from " + k + " and " + l);
+                    throw new Pack200Exception(
+                            "Cannot calculate token codec from " + k + " and "
+                                    + l);
             }
         }
         // read favorites
         result = tokenCodec.decode(n, in);
         // read unfavorites
         last = 0;
-        for(int i = 0; i < n; i++) {
+        for (int i = 0; i < n; i++) {
             int index = (int) result[i];
             if (index == 0) {
                 result[i] = last = unvafouredCodec.decode(in, last);
             } else {
-                result[i] = favoured[index-1];
+                result[i] = favoured[index - 1];
             }
         }
         return result;
     }
 
-
-    public int[] decodeInts(int n, InputStream in) throws IOException, Pack200Exception {
+    public int[] decodeInts(int n, InputStream in) throws IOException,
+            Pack200Exception {
         long[] result = decode(n, in);
         int[] intRes = new int[result.length];
         for (int i = 0; i < intRes.length; i++) {
-            intRes[i] = (int)result[i];
+            intRes[i] = (int) result[i];
         }
         return intRes;
     }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java?rev=647100&r1=647099&r2=647100&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java Fri Apr 11 03:09:38 2008
@@ -21,46 +21,49 @@
 import java.util.Arrays;
 
 /**
- * A run codec is a grouping of two nested codecs; K values are decoded from
- * the first codec, and the remaining codes are decoded from the remaining
- * codec. Note that since this codec maintains state, the instances are
- * not reusable.
+ * A run codec is a grouping of two nested codecs; K values are decoded from the
+ * first codec, and the remaining codes are decoded from the remaining codec.
+ * Note that since this codec maintains state, the instances are not reusable.
  */
 public class RunCodec extends Codec {
-	private int k;
-	private final Codec aCodec;
-	private final Codec bCodec;
-	private long last;
-
-	public RunCodec(int k, Codec aCodec, Codec bCodec) throws Pack200Exception {
-		if (k <= 0)
-			throw new Pack200Exception("Cannot have a RunCodec for a negative number of numbers");
-		if (aCodec == null || bCodec == null)
-			throw new Pack200Exception("Must supply both codecs for a RunCodec");
-		this.k = k;
-		this.aCodec = aCodec;
-		this.bCodec = bCodec;
-	}
-	public long decode(InputStream in) throws IOException, Pack200Exception {
-		return decode(in,this.last);
-	}
-
-	public long decode(InputStream in, long last) throws IOException, Pack200Exception {
-		if(--k>=0) {
-			long value = aCodec.decode(in, this.last);
-			this.last = (k == 0 ? 0 : value);
-			return normalise(aCodec, value);
-		} else {
-			this.last = bCodec.decode(in, this.last);
-			return normalise(bCodec, this.last);
-		}
-	}
+
+    private int k;
+    private final Codec aCodec;
+    private final Codec bCodec;
+    private long last;
+
+    public RunCodec(int k, Codec aCodec, Codec bCodec) throws Pack200Exception {
+        if (k <= 0)
+            throw new Pack200Exception(
+                    "Cannot have a RunCodec for a negative number of numbers");
+        if (aCodec == null || bCodec == null)
+            throw new Pack200Exception("Must supply both codecs for a RunCodec");
+        this.k = k;
+        this.aCodec = aCodec;
+        this.bCodec = bCodec;
+    }
+
+    public long decode(InputStream in) throws IOException, Pack200Exception {
+        return decode(in, this.last);
+    }
+
+    public long decode(InputStream in, long last) throws IOException,
+            Pack200Exception {
+        if (--k >= 0) {
+            long value = aCodec.decode(in, this.last);
+            this.last = (k == 0 ? 0 : value);
+            return normalise(aCodec, value);
+        } else {
+            this.last = bCodec.decode(in, this.last);
+            return normalise(bCodec, this.last);
+        }
+    }
 
     private long normalise(Codec codecUsed, long value) {
-        if(codecUsed instanceof BHSDCodec && ((BHSDCodec)codecUsed).isDelta()) {
-            BHSDCodec bhsd = (BHSDCodec)codecUsed;
+        if (codecUsed instanceof BHSDCodec && ((BHSDCodec) codecUsed).isDelta()) {
+            BHSDCodec bhsd = (BHSDCodec) codecUsed;
             long cardinality = bhsd.cardinality();
-           while (value > bhsd.largest()) {
+            while (value > bhsd.largest()) {
                 value -= cardinality;
             }
             while (value < bhsd.smallest()) {
@@ -68,22 +71,23 @@
             }
         }
         return value;
-	}
+    }
 
-	public int[] decodeInts(int n, InputStream in) throws IOException, Pack200Exception {
+    public int[] decodeInts(int n, InputStream in) throws IOException,
+            Pack200Exception {
         int[] band = new int[n];
         int[] aValues = aCodec.decodeInts(k, in);
         normalise(aValues, aCodec);
-        int[] bValues = bCodec.decodeInts(n-k, in);
+        int[] bValues = bCodec.decodeInts(n - k, in);
         normalise(bValues, bCodec);
         System.arraycopy(aValues, 0, band, 0, k);
-        System.arraycopy(bValues, 0, band, k, n-k);
+        System.arraycopy(bValues, 0, band, k, n - k);
         return band;
     }
 
-	private void normalise(int[] band, Codec codecUsed) {
-        if(codecUsed instanceof BHSDCodec && ((BHSDCodec)codecUsed).isDelta()) {
-            BHSDCodec bhsd = (BHSDCodec)codecUsed;
+    private void normalise(int[] band, Codec codecUsed) {
+        if (codecUsed instanceof BHSDCodec && ((BHSDCodec) codecUsed).isDelta()) {
+            BHSDCodec bhsd = (BHSDCodec) codecUsed;
             long cardinality = bhsd.cardinality();
             for (int i = 0; i < band.length; i++) {
                 while (band[i] > bhsd.largest()) {
@@ -98,12 +102,12 @@
             long[] favoured = (long[]) popCodec.getFavoured().clone();
             Arrays.sort(favoured);
             for (int i = 0; i < band.length; i++) {
-                boolean favouredValue = Arrays.binarySearch(favoured,
-                        band[i]) > -1;
-                Codec theCodec = favouredValue ? popCodec
-                        .getFavouredCodec() : popCodec.getUnvafouredCodec();
-                if (theCodec instanceof BHSDCodec && ((BHSDCodec) theCodec).isDelta()) {
-                    BHSDCodec bhsd = (BHSDCodec)theCodec;
+                boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
+                Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
+                        : popCodec.getUnvafouredCodec();
+                if (theCodec instanceof BHSDCodec
+                        && ((BHSDCodec) theCodec).isDelta()) {
+                    BHSDCodec bhsd = (BHSDCodec) theCodec;
                     long cardinality = bhsd.cardinality();
                     while (band[i] > bhsd.largest()) {
                         band[i] -= cardinality;
@@ -117,6 +121,7 @@
     }
 
     public String toString() {
-		return "RunCodec[k="+k+";aCodec="+aCodec+"bCodec="+bCodec+"]";
-	}
+        return "RunCodec[k=" + k + ";aCodec=" + aCodec + "bCodec=" + bCodec
+                + "]";
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=647100&r1=647099&r2=647100&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java Fri Apr 11 03:09:38 2008
@@ -28,6 +28,7 @@
 import java.util.jar.JarEntry;
 import java.util.jar.JarOutputStream;
 import java.util.zip.GZIPInputStream;
+import java.util.zip.ZipEntry;
 
 import org.apache.harmony.pack200.bytecode.Attribute;
 import org.apache.harmony.pack200.bytecode.CPClass;
@@ -47,14 +48,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
@@ -89,250 +90,281 @@
 
     private boolean deflateHint;
 
-	private int logLevel;
+    private int logLevel;
 
-	private PrintWriter logStream;
+    private PrintWriter logStream;
 
-	private ClassFile buildClassFile(int classNum) throws Pack200Exception {
-		ClassFile classFile = new ClassFile();
-		classFile.major = header.getDefaultClassMajorVersion(); // TODO If
-		// classVersionMajor[] use
-		// that instead
-		classFile.minor = header.getDefaultClassMinorVersion(); // TODO if
-		// classVersionMinor[] use
-		// that instead
-		// build constant pool
-		ClassConstantPool cp = classFile.pool;
-		String fullName = classBands.getClassThis()[classNum];
-		// SourceFile attribute
-		int i = fullName.lastIndexOf("/") + 1; // if lastIndexOf==-1, then
-		// -1+1=0, so str.substring(0)
-		// == str
+    private ClassFile buildClassFile(int classNum) throws Pack200Exception {
+        ClassFile classFile = new ClassFile();
+        classFile.major = header.getDefaultClassMajorVersion(); // TODO If
+        // classVersionMajor[] use
+        // that instead
+        classFile.minor = header.getDefaultClassMinorVersion(); // TODO if
+        // classVersionMinor[] use
+        // that instead
+        // build constant pool
+        ClassConstantPool cp = classFile.pool;
+        String fullName = classBands.getClassThis()[classNum];
+        // SourceFile attribute
+        int i = fullName.lastIndexOf("/") + 1; // if lastIndexOf==-1, then
+        // -1+1=0, so str.substring(0)
+        // == str
 
-		// Get the source file attribute
+        // Get the source file attribute
         ArrayList classAttributes = classBands.getClassAttributes()[classNum];
         SourceFileAttribute sourceFileAttribute = null;
-        for(int index=0; index < classAttributes.size(); index++) {
-            if(((Attribute)classAttributes.get(index)).isSourceFileAttribute()) {
-                sourceFileAttribute = ((SourceFileAttribute)classAttributes.get(index));
+        for (int index = 0; index < classAttributes.size(); index++) {
+            if (((Attribute) classAttributes.get(index))
+                    .isSourceFileAttribute()) {
+                sourceFileAttribute = ((SourceFileAttribute) classAttributes
+                        .get(index));
             }
         }
 
-        if(sourceFileAttribute == null) {
+        if (sourceFileAttribute == null) {
             // If we don't have a source file attribute yet, we need
             // to infer it from the class.
-            AttributeLayout SOURCE_FILE = attrDefinitionBands.getAttributeDefinitionMap()
-    				.getAttributeLayout(AttributeLayout.ATTRIBUTE_SOURCE_FILE,
-    						AttributeLayout.CONTEXT_CLASS);
-    		if (SOURCE_FILE.matches(classBands.getRawClassFlags()[classNum])) {
-    		    int firstDollar = SegmentUtils.indexOfFirstDollar(fullName);
-    		    String fileName = null;
-
-    		    if(firstDollar > -1 && (i <= firstDollar)) {
-    		        fileName = fullName.substring(i, firstDollar) + ".java";
-    		    } else {
-    		        fileName = fullName.substring(i) + ".java";
-    		    }
-    		    sourceFileAttribute = new SourceFileAttribute(cpBands.cpUTF8Value(fileName, ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ));
-    			classFile.attributes = new Attribute[] { (Attribute) cp
-    					.add(sourceFileAttribute) };
-    		} else {
+            AttributeLayout SOURCE_FILE = attrDefinitionBands
+                    .getAttributeDefinitionMap().getAttributeLayout(
+                            AttributeLayout.ATTRIBUTE_SOURCE_FILE,
+                            AttributeLayout.CONTEXT_CLASS);
+            if (SOURCE_FILE.matches(classBands.getRawClassFlags()[classNum])) {
+                int firstDollar = SegmentUtils.indexOfFirstDollar(fullName);
+                String fileName = null;
+
+                if (firstDollar > -1 && (i <= firstDollar)) {
+                    fileName = fullName.substring(i, firstDollar) + ".java";
+                } else {
+                    fileName = fullName.substring(i) + ".java";
+                }
+                sourceFileAttribute = new SourceFileAttribute(cpBands
+                        .cpUTF8Value(fileName,
+                                ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ));
+                classFile.attributes = new Attribute[] { (Attribute) cp
+                        .add(sourceFileAttribute) };
+            } else {
                 classFile.attributes = new Attribute[] {};
             }
         } else {
-            classFile.attributes = new Attribute[] { (Attribute) cp.add(sourceFileAttribute)};
+            classFile.attributes = new Attribute[] { (Attribute) cp
+                    .add(sourceFileAttribute) };
         }
 
-		// If we see any class attributes, add them to the class's attributes that will
-		// be written out. Keep SourceFileAttributes out since we just
-		// did them above.
-	    ArrayList classAttributesWithoutSourceFileAttribute = new ArrayList();
-	    for(int index=0; index < classAttributes.size(); index++) {
-	        Attribute attrib = (Attribute)classAttributes.get(index);
-	        if(!attrib.isSourceFileAttribute()) {
-	            classAttributesWithoutSourceFileAttribute.add(attrib);
-	        }
-	    }
+        // If we see any class attributes, add them to the class's attributes
+        // that will
+        // be written out. Keep SourceFileAttributes out since we just
+        // did them above.
+        ArrayList classAttributesWithoutSourceFileAttribute = new ArrayList();
+        for (int index = 0; index < classAttributes.size(); index++) {
+            Attribute attrib = (Attribute) classAttributes.get(index);
+            if (!attrib.isSourceFileAttribute()) {
+                classAttributesWithoutSourceFileAttribute.add(attrib);
+            }
+        }
         Attribute[] originalAttributes = classFile.attributes;
-        classFile.attributes = new Attribute[originalAttributes.length + classAttributesWithoutSourceFileAttribute.size()];
-        System.arraycopy(originalAttributes, 0, classFile.attributes, 0, originalAttributes.length);
-	    for(int index=0; index < classAttributesWithoutSourceFileAttribute.size(); index++) {
-	        Attribute attrib = ((Attribute)classAttributesWithoutSourceFileAttribute.get(index));
-	        cp.add(attrib);
-	        classFile.attributes[originalAttributes.length + index] = attrib;
-	    }
-
-		// this/superclass
-		ClassFileEntry cfThis = cp.add(cpBands.cpClassValue(fullName));
-		ClassFileEntry cfSuper = cp.add(cpBands.cpClassValue(classBands.getClassSuper()[classNum]));
-		// add interfaces
-		ClassFileEntry cfInterfaces[] = new ClassFileEntry[classBands.getClassInterfaces()[classNum].length];
-		for (i = 0; i < cfInterfaces.length; i++) {
-			cfInterfaces[i] = cp.add(cpBands.cpClassValue(classBands.getClassInterfaces()[classNum][i]));
-		}
-		// add fields
-		ClassFileEntry cfFields[] = new ClassFileEntry[classBands.getClassFieldCount()[classNum]];
-		// fieldDescr and fieldFlags used to create this
-		for (i = 0; i < cfFields.length; i++) {
+        classFile.attributes = new Attribute[originalAttributes.length
+                + classAttributesWithoutSourceFileAttribute.size()];
+        System.arraycopy(originalAttributes, 0, classFile.attributes, 0,
+                originalAttributes.length);
+        for (int index = 0; index < classAttributesWithoutSourceFileAttribute
+                .size(); index++) {
+            Attribute attrib = ((Attribute) classAttributesWithoutSourceFileAttribute
+                    .get(index));
+            cp.add(attrib);
+            classFile.attributes[originalAttributes.length + index] = attrib;
+        }
+
+        // this/superclass
+        ClassFileEntry cfThis = cp.add(cpBands.cpClassValue(fullName));
+        ClassFileEntry cfSuper = cp.add(cpBands.cpClassValue(classBands
+                .getClassSuper()[classNum]));
+        // add interfaces
+        ClassFileEntry cfInterfaces[] = new ClassFileEntry[classBands
+                .getClassInterfaces()[classNum].length];
+        for (i = 0; i < cfInterfaces.length; i++) {
+            cfInterfaces[i] = cp.add(cpBands.cpClassValue(classBands
+                    .getClassInterfaces()[classNum][i]));
+        }
+        // add fields
+        ClassFileEntry cfFields[] = new ClassFileEntry[classBands
+                .getClassFieldCount()[classNum]];
+        // fieldDescr and fieldFlags used to create this
+        for (i = 0; i < cfFields.length; i++) {
             String descriptorStr = classBands.getFieldDescr()[classNum][i];
             int colon = descriptorStr.indexOf(':');
-            CPUTF8 name = cpBands.cpUTF8Value(descriptorStr.substring(0,colon), ClassConstantPool.DOMAIN_NORMALASCIIZ);
-            CPUTF8 descriptor = cpBands.cpUTF8Value(descriptorStr.substring(colon+1), ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
-            cfFields[i] = cp.add(new CPField(name, descriptor,
-                    classBands.getFieldFlags()[classNum][i], classBands.getFieldAttributes()[classNum][i]));
-		}
-		// add methods
-		ClassFileEntry cfMethods[] = new ClassFileEntry[classBands.getClassMethodCount()[classNum]];
-		// methodDescr and methodFlags used to create this
-		for (i = 0; i < cfMethods.length; i++) {
+            CPUTF8 name = cpBands.cpUTF8Value(
+                    descriptorStr.substring(0, colon),
+                    ClassConstantPool.DOMAIN_NORMALASCIIZ);
+            CPUTF8 descriptor = cpBands.cpUTF8Value(descriptorStr
+                    .substring(colon + 1),
+                    ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
+            cfFields[i] = cp.add(new CPField(name, descriptor, classBands
+                    .getFieldFlags()[classNum][i], classBands
+                    .getFieldAttributes()[classNum][i]));
+        }
+        // add methods
+        ClassFileEntry cfMethods[] = new ClassFileEntry[classBands
+                .getClassMethodCount()[classNum]];
+        // methodDescr and methodFlags used to create this
+        for (i = 0; i < cfMethods.length; i++) {
             String descriptorStr = classBands.getMethodDescr()[classNum][i];
             int colon = descriptorStr.indexOf(':');
-            CPUTF8 name = cpBands.cpUTF8Value(descriptorStr.substring(0,colon), ClassConstantPool.DOMAIN_NORMALASCIIZ);
-            CPUTF8 descriptor = cpBands.cpUTF8Value(descriptorStr.substring(colon+1), ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
+            CPUTF8 name = cpBands.cpUTF8Value(
+                    descriptorStr.substring(0, colon),
+                    ClassConstantPool.DOMAIN_NORMALASCIIZ);
+            CPUTF8 descriptor = cpBands.cpUTF8Value(descriptorStr
+                    .substring(colon + 1),
+                    ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
             cfMethods[i] = cp.add(new CPMethod(name, descriptor, classBands
                     .getMethodFlags()[classNum][i], classBands
                     .getMethodAttributes()[classNum][i]));
-		}
+        }
 
-		// add inner class attribute (if required)
-		boolean addInnerClassesAttr = false;
+        // add inner class attribute (if required)
+        boolean addInnerClassesAttr = false;
         IcTuple[] ic_local = getClassBands().getIcLocal()[classNum];
-		boolean ic_local_sent = false;
-		if(ic_local != null) {
-		    ic_local_sent = true;
-		}
-		InnerClassesAttribute innerClassesAttribute = new InnerClassesAttribute("InnerClasses");
-		IcTuple[] ic_relevant = getIcBands().getRelevantIcTuples(fullName, cp);
-		IcTuple[] ic_stored = computeIcStored(ic_local, ic_relevant);
-		for(int index = 0; index < ic_stored.length; index++) {
-		    String innerClassString = ic_stored[index].thisClassString();
-		    String outerClassString = ic_stored[index].outerClassString();
-		    String simpleClassName = ic_stored[index].simpleClassName();
-
-		    CPClass innerClass = null;
-		    CPUTF8 innerName = null;
-		    CPClass outerClass = null;
-
-		    if(ic_stored[index].isAnonymous()) {
-		        innerClass = cpBands.cpClassValue(innerClassString);
-		    } else {
-	            innerClass = cpBands.cpClassValue(innerClassString);
-	            innerName = cpBands.cpUTF8Value(simpleClassName, ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
-		    }
-
-		    if(ic_stored[index].isMember()) {
-		        outerClass = cpBands.cpClassValue(outerClassString);
-		    }
-
-	        int flags = ic_stored[index].F;
-	        innerClassesAttribute.addInnerClassesEntry(innerClass, outerClass, innerName, flags);
-	        addInnerClassesAttr = true;
-		}
-		// If ic_local is sent and it's empty, don't add
-		// the inner classes attribute.
-		if(ic_local_sent && (ic_local.length == 0)) {
-		    addInnerClassesAttr = false;
-		}
-
-		// If ic_local is not sent and ic_relevant is empty,
-		// don't add the inner class attribute.
-		if(!ic_local_sent && (ic_relevant.length == 0)) {
-		    addInnerClassesAttr = false;
-		}
-
-		if(addInnerClassesAttr) {
-		    // Need to add the InnerClasses attribute to the
-		    // existing classFile attributes.
-		    Attribute[] originalAttrs = classFile.attributes;
-		    Attribute[] newAttrs = new Attribute[originalAttrs.length + 1];
-		    for(int index=0; index < originalAttrs.length; index++) {
-		        newAttrs[index] = originalAttrs[index];
-		    }
-		    newAttrs[newAttrs.length - 1] = innerClassesAttribute;
-		    classFile.attributes = newAttrs;
-		    cp.add(innerClassesAttribute);
-		}
-		// sort CP according to cp_All
-		cp.resolve(this);
-		// NOTE the indexOf is only valid after the cp.resolve()
-		// build up remainder of file
-		classFile.accessFlags = (int) classBands.getClassFlags()[classNum];
-		classFile.thisClass = cp.indexOf(cfThis);
-		classFile.superClass = cp.indexOf(cfSuper);
-		// TODO placate format of file for writing purposes
-		classFile.interfaces = new int[cfInterfaces.length];
-		for (i = 0; i < cfInterfaces.length; i++) {
-			classFile.interfaces[i] = cp.indexOf(cfInterfaces[i]);
-		}
-		classFile.fields = cfFields;
-		classFile.methods = cfMethods;
-		return classFile;
-	}
-
-
-	/**
-	 * 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 IcTuple[] array of relevant tuples
-	 * @return IcTuple[] array of tuples to be stored. If ic_local
-	 *     is null or empty, the values returned may not be correct.
-	 *     The caller will 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();
-	    if(ic_local != null) {
-	        // If ic_local is null, this code doesn't get
-	        // executed - which means the list ends up being
-	        // ic_relevant.
-	        for(int index=0; index < ic_local.length; index++) {
-	            result.add(ic_local[index]);
-	            resultCopy.add(ic_local[index]);
-	            localList.add(ic_local[index]);
-	        }
-	    }
-	    for(int index=0; index < ic_relevant.length; index++) {
-	        result.add(ic_relevant[index]);
-	        resultCopy.add(ic_relevant[index]);
-	        relevantList.add(ic_relevant[index]);
-	    }
-
-	    // Since we're removing while iterating, iterate over
-	    // a copy.
-	    Iterator it = resultCopy.iterator();
-
-	    while(it.hasNext()) {
-	        IcTuple tuple = (IcTuple)it.next();
-	        if(localList.contains(tuple) && relevantList.contains(tuple)) {
-	            while(result.remove(tuple)) {};
-	        }
-	    }
-	    IcTuple[] resultArray = new IcTuple[result.size()];
-	    for(int index=0; index < resultArray.length; index++) {
-	        resultArray[index] = (IcTuple)result.get(index);
-	    }
-	    return resultArray;
+        boolean ic_local_sent = false;
+        if (ic_local != null) {
+            ic_local_sent = true;
+        }
+        InnerClassesAttribute innerClassesAttribute = new InnerClassesAttribute(
+                "InnerClasses");
+        IcTuple[] ic_relevant = getIcBands().getRelevantIcTuples(fullName, cp);
+        IcTuple[] ic_stored = computeIcStored(ic_local, ic_relevant);
+        for (int index = 0; index < ic_stored.length; index++) {
+            String innerClassString = ic_stored[index].thisClassString();
+            String outerClassString = ic_stored[index].outerClassString();
+            String simpleClassName = ic_stored[index].simpleClassName();
+
+            CPClass innerClass = null;
+            CPUTF8 innerName = null;
+            CPClass outerClass = null;
+
+            if (ic_stored[index].isAnonymous()) {
+                innerClass = cpBands.cpClassValue(innerClassString);
+            } else {
+                innerClass = cpBands.cpClassValue(innerClassString);
+                innerName = cpBands.cpUTF8Value(simpleClassName,
+                        ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
+            }
+
+            if (ic_stored[index].isMember()) {
+                outerClass = cpBands.cpClassValue(outerClassString);
+            }
+
+            int flags = ic_stored[index].F;
+            innerClassesAttribute.addInnerClassesEntry(innerClass, outerClass,
+                    innerName, flags);
+            addInnerClassesAttr = true;
+        }
+        // If ic_local is sent and it's empty, don't add
+        // the inner classes attribute.
+        if (ic_local_sent && (ic_local.length == 0)) {
+            addInnerClassesAttr = false;
+        }
+
+        // If ic_local is not sent and ic_relevant is empty,
+        // don't add the inner class attribute.
+        if (!ic_local_sent && (ic_relevant.length == 0)) {
+            addInnerClassesAttr = false;
+        }
+
+        if (addInnerClassesAttr) {
+            // Need to add the InnerClasses attribute to the
+            // existing classFile attributes.
+            Attribute[] originalAttrs = classFile.attributes;
+            Attribute[] newAttrs = new Attribute[originalAttrs.length + 1];
+            for (int index = 0; index < originalAttrs.length; index++) {
+                newAttrs[index] = originalAttrs[index];
+            }
+            newAttrs[newAttrs.length - 1] = innerClassesAttribute;
+            classFile.attributes = newAttrs;
+            cp.add(innerClassesAttribute);
+        }
+        // sort CP according to cp_All
+        cp.resolve(this);
+        // NOTE the indexOf is only valid after the cp.resolve()
+        // build up remainder of file
+        classFile.accessFlags = (int) classBands.getClassFlags()[classNum];
+        classFile.thisClass = cp.indexOf(cfThis);
+        classFile.superClass = cp.indexOf(cfSuper);
+        // TODO placate format of file for writing purposes
+        classFile.interfaces = new int[cfInterfaces.length];
+        for (i = 0; i < cfInterfaces.length; i++) {
+            classFile.interfaces[i] = cp.indexOf(cfInterfaces[i]);
+        }
+        classFile.fields = cfFields;
+        classFile.methods = cfMethods;
+        return classFile;
     }
 
+    /**
+     * 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
+     *            IcTuple[] array of relevant tuples
+     * @return IcTuple[] array of tuples to be stored. If ic_local is null or
+     *         empty, the values returned may not be correct. The caller will
+     *         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();
+        if (ic_local != null) {
+            // If ic_local is null, this code doesn't get
+            // executed - which means the list ends up being
+            // ic_relevant.
+            for (int index = 0; index < ic_local.length; index++) {
+                result.add(ic_local[index]);
+                resultCopy.add(ic_local[index]);
+                localList.add(ic_local[index]);
+            }
+        }
+        for (int index = 0; index < ic_relevant.length; index++) {
+            result.add(ic_relevant[index]);
+            resultCopy.add(ic_relevant[index]);
+            relevantList.add(ic_relevant[index]);
+        }
+
+        // Since we're removing while iterating, iterate over
+        // a copy.
+        Iterator it = resultCopy.iterator();
+
+        while (it.hasNext()) {
+            IcTuple tuple = (IcTuple) it.next();
+            if (localList.contains(tuple) && relevantList.contains(tuple)) {
+                while (result.remove(tuple)) {
+                }
+                ;
+            }
+        }
+        IcTuple[] resultArray = new IcTuple[result.size()];
+        for (int index = 0; index < resultArray.length; index++) {
+            resultArray[index] = (IcTuple) result.get(index);
+        }
+        return resultArray;
+    }
 
     /**
-	 * This performs the actual work of parsing against a non-static instance of
-	 * Segment.
-	 *
-	 * @param in
-	 *            the input stream to read from
-	 * @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(InputStream in) throws IOException,
-			Pack200Exception {
-		log(LOG_LEVEL_VERBOSE, "-------");
+     * This performs the actual work of parsing against a non-static instance of
+     * Segment.
+     * 
+     * @param in
+     *            the input stream to read from
+     * @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(InputStream in) throws IOException,
+            Pack200Exception {
+        log(LOG_LEVEL_VERBOSE, "-------");
         header = new SegmentHeader(this);
         header.unpack(in);
         cpBands = new CpBands(this);
@@ -347,12 +379,12 @@
         bcBands.unpack(in);
         fileBands = new FileBands(this);
         fileBands.unpack(in);
-	}
+    }
 
     /**
      * Unpacks a packed stream (either .pack. or .pack.gz) into a corresponding
      * JarOuputStream.
-     *
+     * 
      * @throws Pack200Exception
      *             if there is a problem unpacking
      * @throws IOException
@@ -366,100 +398,95 @@
         writeJar(out);
     }
 
-	/**
-	 * Writes the segment to an output stream. The output stream should be
-	 * pre-buffered for efficiency. Also takes the same input stream for
-	 * 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
-	 *             if an error occurs while reading or writing to the streams
-	 * @throws Pack200Exception
-	 *             if an error occurs while processing data
-	 */
-	public void writeJar(JarOutputStream out)
-			throws IOException, Pack200Exception {
-		fileBands.processFileBits();
-		DataOutputStream dos = new DataOutputStream(out);
+    /**
+     * Writes the segment to an output stream. The output stream should be
+     * pre-buffered for efficiency. Also takes the same input stream for
+     * 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
+     *             if an error occurs while reading or writing to the streams
+     * @throws Pack200Exception
+     *             if an error occurs while processing data
+     */
+    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();
 
-		// out.setLevel(JarEntry.DEFLATED)
-		// now write the files out
-		int classNum = 0;
+        // out.setLevel(JarEntry.DEFLATED)
+        // now write the files out
+        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();
+        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 = classBands.getClassThis()[classNum] + ".class";
-			}
-			JarEntry entry = new JarEntry(name);
-			if (deflate)
-				entry.setMethod(JarEntry.DEFLATED);
-			entry.setTime(modtime);
-			out.putNextEntry(entry);
-
-			if (isClass) {
-				// write to dos
-				ClassFile classFile = buildClassFile(classNum);
-				classFile.write(dos);
-				dos.flush();
-				classNum++;
-			} else {
-				long size = fileSize[i];
-				entry.setSize(size);
-				// TODO pull from in
-				byte[] data = fileBits[i];
-				out.write(data);
-			}
-		}
-		dos.flush();
-		out.flush();
-	}
+            boolean isClass = (fileOptions[i] & 2) == 2 || name == null
+                    || name.equals("");
+            if (isClass) {
+                // pull from headers
+                if (name == null || name.equals(""))
+                    name = classBands.getClassThis()[classNum] + ".class";
+            }
+            JarEntry entry = new JarEntry(name);
+            if (deflate)
+                entry.setMethod(ZipEntry.DEFLATED);
+            entry.setTime(modtime);
+            out.putNextEntry(entry);
+
+            if (isClass) {
+                // write to dos
+                ClassFile classFile = buildClassFile(classNum);
+                classFile.write(dos);
+                dos.flush();
+                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() {
         return cpBands.getConstantPool();
     }
 
-
     public SegmentHeader getSegmentHeader() {
         return header;
     }
 
-
     protected AttrDefinitionBands getAttrDefinitionBands() {
         return attrDefinitionBands;
     }
 
-
     protected BcBands getBcBands() {
         return bcBands;
     }
 
-
     protected ClassBands getClassBands() {
         return classBands;
     }
 
-
     protected CpBands getCpBands() {
         return cpBands;
     }
@@ -472,24 +499,25 @@
         return icBands;
     }
 
-
     public void setLogLevel(int logLevel) {
-    	this.logLevel = logLevel;
+        this.logLevel = logLevel;
     }
 
     public void setLogStream(OutputStream logStream) {
-    	this.logStream = new PrintWriter(logStream);
+        this.logStream = new PrintWriter(logStream);
     }
 
     public void log(int logLevel, String message) {
-    	if (this.logLevel >= logLevel) {
-    		logStream.println(message);
-    	}
+        if (this.logLevel >= logLevel) {
+            logStream.println(message);
+        }
     }
 
     /**
      * Override the archive's deflate hint with the given boolean
-     * @param deflateHint - the deflate hint to use
+     * 
+     * @param deflateHint -
+     *            the deflate hint to use
      */
     public void overrideDeflateHint(boolean deflateHint) {
         this.overrideDeflateHint = true;

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java?rev=647100&r1=647099&r2=647100&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentConstantPool.java Fri Apr 11 03:09:38 2008
@@ -87,174 +87,199 @@
     }
 
     /**
-     * Subset the constant pool of the specified type
-     * to be just that which has the specified class
-     * name. Answer the ConstantPoolEntry at the
+     * Subset the constant pool of the specified type to be just that which has
+     * the specified class name. Answer the ConstantPoolEntry at the
      * desiredIndex of the subsetted pool.
-     *
-     * @param cp type of constant pool array to search
-     * @param desiredIndex index of the constant pool
-     * @param desiredClassName class to use to generate a
-     * 		subset of the pool
+     * 
+     * @param cp
+     *            type of constant pool array to search
+     * @param desiredIndex
+     *            index of the constant pool
+     * @param desiredClassName
+     *            class to use to generate a subset of the pool
      * @return ConstantPoolEntry
      * @throws Pack200Exception
      */
-    public ConstantPoolEntry getClassSpecificPoolEntry(int cp, long desiredIndex, String desiredClassName) throws Pack200Exception {
-    	int index = (int)desiredIndex;
-    	int realIndex = -1;
-    	String array[] = null;
-    	if (cp == CP_FIELD) {
-    		array = bands.getCpFieldClass();
-    	} else if (cp == CP_METHOD) {
-    		array = bands.getCpMethodClass();
-    	} else if (cp == CP_IMETHOD) {
-    		array = bands.getCpIMethodClass();
-    	} else {
-    		throw new Error("Don't know how to handle " + cp);
-    	}
-    	realIndex = matchSpecificPoolEntryIndex(array, desiredClassName, index);
-    	return getConstantPoolEntry(cp, realIndex);
+    public ConstantPoolEntry getClassSpecificPoolEntry(int cp,
+            long desiredIndex, String desiredClassName) throws Pack200Exception {
+        int index = (int) desiredIndex;
+        int realIndex = -1;
+        String array[] = null;
+        if (cp == CP_FIELD) {
+            array = bands.getCpFieldClass();
+        } else if (cp == CP_METHOD) {
+            array = bands.getCpMethodClass();
+        } else if (cp == CP_IMETHOD) {
+            array = bands.getCpIMethodClass();
+        } else {
+            throw new Error("Don't know how to handle " + cp);
+        }
+        realIndex = matchSpecificPoolEntryIndex(array, desiredClassName, index);
+        return getConstantPoolEntry(cp, realIndex);
     }
 
     /**
-     * Given the name of a class, answer the CPClass associated
-     * with that class. Answer null if the class doesn't exist.
-     * @param name Class name to look for (form: java/lang/Object)
+     * Given the name of a class, answer the CPClass associated with that class.
+     * Answer null if the class doesn't exist.
+     * 
+     * @param name
+     *            Class name to look for (form: java/lang/Object)
      * @return CPClass for that class name, or null if not found.
      */
     public ConstantPoolEntry getClassPoolEntry(String name) {
-    	String classes[] = bands.getCpClass();
-    	int index = matchSpecificPoolEntryIndex(classes, name, 0);
-    	if(index == -1) {
-    		return null;
-    	}
-    	try {
-    		return getConstantPoolEntry(CP_CLASS, index);
-    	}
-    	catch (Pack200Exception ex) {
-    		throw new Error("Error getting class pool entry");
-    	}
+        String classes[] = bands.getCpClass();
+        int index = matchSpecificPoolEntryIndex(classes, name, 0);
+        if (index == -1) {
+            return null;
+        }
+        try {
+            return getConstantPoolEntry(CP_CLASS, index);
+        } catch (Pack200Exception ex) {
+            throw new Error("Error getting class pool entry");
+        }
     }
 
     /**
      * Answer the init method for the specified class.
-     * @param cp constant pool to search (must be CP_METHOD)
-     * @param value index of init method
-     * @param desiredClassName String class name of the init method
+     * 
+     * @param cp
+     *            constant pool to search (must be CP_METHOD)
+     * @param value
+     *            index of init method
+     * @param desiredClassName
+     *            String class name of the init method
      * @return CPMethod init method
      * @throws Pack200Exception
      */
-    public ConstantPoolEntry getInitMethodPoolEntry(int cp, long value, String desiredClassName) throws Pack200Exception {
-    	int realIndex = -1;
-    	String desiredRegex = REGEX_MATCH_INIT;
-    	if (cp == CP_METHOD) {
-    		realIndex = matchSpecificPoolEntryIndex(bands.getCpMethodClass(), bands.getCpMethodDescriptor(), desiredClassName, desiredRegex, (int)value);
-    	} else {
-    		throw new Error("Nothing but CP_METHOD can be an <init>");
-    	}
-    	return getConstantPoolEntry(cp, realIndex);
+    public ConstantPoolEntry getInitMethodPoolEntry(int cp, long value,
+            String desiredClassName) throws Pack200Exception {
+        int realIndex = -1;
+        String desiredRegex = REGEX_MATCH_INIT;
+        if (cp == CP_METHOD) {
+            realIndex = matchSpecificPoolEntryIndex(bands.getCpMethodClass(),
+                    bands.getCpMethodDescriptor(), desiredClassName,
+                    desiredRegex, (int) value);
+        } else {
+            throw new Error("Nothing but CP_METHOD can be an <init>");
+        }
+        return getConstantPoolEntry(cp, realIndex);
     }
 
     /**
-     * A number of things make use of subsets of structures.
-     * In one particular example, _super bytecodes will use a subset
-     * of method or field classes which have just those methods /
-     * fields defined in the superclass. Similarly, _this bytecodes
-     * use just those methods/fields defined in this class, and _init
-     * bytecodes use just those methods that start with <init>.
-     *
-     * This method takes an array of names, a String to match for,
-     * an index and a boolean as parameters, and answers the array
-     * position in the array of the indexth element which matches
-     * (or equals) the String (depending on the state of the boolean)
-     *
-     * In other words, if the class array consists of:
-     *  Object [position 0, 0th instance of Object]
-     *  String [position 1, 0th instance of String]
-     *  String [position 2, 1st instance of String]
-     *  Object [position 3, 1st instance of Object]
-     *  Object [position 4, 2nd instance of Object]
-     * then matchSpecificPoolEntryIndex(..., "Object", 2, false) will
-     * answer 4. matchSpecificPoolEntryIndex(..., "String", 0, false)
-     * will answer 1.
-     *
-     * @param nameArray Array of Strings against which the compareString is tested
-     * @param compareString String for which to search
-     * @param desiredIndex nth element with that match (counting from 0)
+     * A number of things make use of subsets of structures. In one particular
+     * example, _super bytecodes will use a subset of method or field classes
+     * which have just those methods / fields defined in the superclass.
+     * Similarly, _this bytecodes use just those methods/fields defined in this
+     * class, and _init bytecodes use just those methods that start with <init>.
+     * 
+     * This method takes an array of names, a String to match for, an index and
+     * a boolean as parameters, and answers the array position in the array of
+     * the indexth element which matches (or equals) the String (depending on
+     * the state of the boolean)
+     * 
+     * In other words, if the class array consists of: Object [position 0, 0th
+     * instance of Object] String [position 1, 0th instance of String] String
+     * [position 2, 1st instance of String] Object [position 3, 1st instance of
+     * Object] Object [position 4, 2nd instance of Object] then
+     * matchSpecificPoolEntryIndex(..., "Object", 2, false) will answer 4.
+     * matchSpecificPoolEntryIndex(..., "String", 0, false) will answer 1.
+     * 
+     * @param nameArray
+     *            Array of Strings against which the compareString is tested
+     * @param compareString
+     *            String for which to search
+     * @param desiredIndex
+     *            nth element with that match (counting from 0)
      * @return int index into nameArray, or -1 if not found.
      */
-    protected int matchSpecificPoolEntryIndex(String[] nameArray, String compareString, int desiredIndex) {
-    	return matchSpecificPoolEntryIndex(nameArray, nameArray, compareString, REGEX_MATCH_ALL, desiredIndex);
+    protected int matchSpecificPoolEntryIndex(String[] nameArray,
+            String compareString, int desiredIndex) {
+        return matchSpecificPoolEntryIndex(nameArray, nameArray, compareString,
+                REGEX_MATCH_ALL, desiredIndex);
     }
 
     /**
-     * This method's function is to look through pairs of arrays.
-     * It keeps track of the number of hits it finds using the
-     * following basis of comparison for a hit:
-     *  - the primaryArray[index] must be .equals() to the primaryCompareString
-     *  - the secondaryArray[index] .matches() the secondaryCompareString
-     * When the desiredIndex number of hits has been reached, the index
-     * into the original two arrays of the element hit is returned.
-     *
-     * @param primaryArray The first array to search
-     * @param secondaryArray The second array (must be same .length as primaryArray)
-     * @param primaryCompareString The String to compare against primaryArray using .equals()
-     * @param secondaryCompareRegex The String to compare against secondaryArray using .matches()
-     * @param desiredIndex The nth hit whose position we're seeking
-     * @return int index that represents the position of the nth hit in primaryArray and secondaryArray
-     */
-    protected int matchSpecificPoolEntryIndex(String[] primaryArray, String[] secondaryArray, String primaryCompareString, String secondaryCompareRegex, int desiredIndex) {
-    	int instanceCount = -1;
-    	for(int index=0; index < primaryArray.length; index++) {
-    		if((primaryArray[index].equals(primaryCompareString)) &&
-    				regexMatches(secondaryCompareRegex, secondaryArray[index]) ) {
-    			instanceCount++;
-    			if(instanceCount == desiredIndex) {
-    				return index;
-    			}
-    		}
-    	}
-    	// We didn't return in the for loop, so the desiredMatch
-    	// with desiredIndex must not exist in the array.
-    	return -1;
+     * This method's function is to look through pairs of arrays. It keeps track
+     * of the number of hits it finds using the following basis of comparison
+     * for a hit: - the primaryArray[index] must be .equals() to the
+     * primaryCompareString - the secondaryArray[index] .matches() the
+     * secondaryCompareString When the desiredIndex number of hits has been
+     * reached, the index into the original two arrays of the element hit is
+     * returned.
+     * 
+     * @param primaryArray
+     *            The first array to search
+     * @param secondaryArray
+     *            The second array (must be same .length as primaryArray)
+     * @param primaryCompareString
+     *            The String to compare against primaryArray using .equals()
+     * @param secondaryCompareRegex
+     *            The String to compare against secondaryArray using .matches()
+     * @param desiredIndex
+     *            The nth hit whose position we're seeking
+     * @return int index that represents the position of the nth hit in
+     *         primaryArray and secondaryArray
+     */
+    protected int matchSpecificPoolEntryIndex(String[] primaryArray,
+            String[] secondaryArray, String primaryCompareString,
+            String secondaryCompareRegex, int desiredIndex) {
+        int instanceCount = -1;
+        for (int index = 0; index < primaryArray.length; index++) {
+            if ((primaryArray[index].equals(primaryCompareString))
+                    && regexMatches(secondaryCompareRegex,
+                            secondaryArray[index])) {
+                instanceCount++;
+                if (instanceCount == desiredIndex) {
+                    return index;
+                }
+            }
+        }
+        // We didn't return in the for loop, so the desiredMatch
+        // with desiredIndex must not exist in the array.
+        return -1;
     }
 
     /**
-     * We don't want a dependency on regex in Pack200. The
-     * only place one exists is in matchSpecificPoolEntryIndex().
-     * To eliminate this dependency, we've implemented the
-     * world's stupidest regexMatch. It knows about the two
-     * forms we care about:
-     *  .* (aka REGEX_MATCH_ALL)
-     *  ^<init>.* (aka REGEX_MATCH_INIT)
-     * and will answer correctly if those are passed as the
+     * We don't want a dependency on regex in Pack200. The only place one exists
+     * is in matchSpecificPoolEntryIndex(). To eliminate this dependency, we've
+     * implemented the world's stupidest regexMatch. It knows about the two
+     * forms we care about: .* (aka REGEX_MATCH_ALL) ^<init>.* (aka
+     * REGEX_MATCH_INIT) and will answer correctly if those are passed as the
      * regexString.
-     * @param regexString String against which the compareString will be matched
-     * @param compareString String to match against the regexString
+     * 
+     * @param regexString
+     *            String against which the compareString will be matched
+     * @param compareString
+     *            String to match against the regexString
      * @return boolean true if the compareString matches the regexString;
-     *  otherwise false.
+     *         otherwise false.
      */
-    protected static boolean regexMatches(String regexString, String compareString) {
-        if(REGEX_MATCH_ALL.equals(regexString)) {
+    protected static boolean regexMatches(String regexString,
+            String compareString) {
+        if (REGEX_MATCH_ALL.equals(regexString)) {
             return true;
         }
-        if(REGEX_MATCH_INIT.equals(regexString)) {
-            if(compareString.length() < (INITSTRING.length())) {
+        if (REGEX_MATCH_INIT.equals(regexString)) {
+            if (compareString.length() < (INITSTRING.length())) {
                 return false;
             }
-            return(INITSTRING.equals(compareString.substring(0, INITSTRING.length())));
+            return (INITSTRING.equals(compareString.substring(0, INITSTRING
+                    .length())));
         }
-        throw new Error("regex trying to match a pattern I don't know: " + regexString);
+        throw new Error("regex trying to match a pattern I don't know: "
+                + regexString);
     }
 
-    public ConstantPoolEntry getConstantPoolEntry(int cp, long value) throws Pack200Exception {
+    public ConstantPoolEntry getConstantPoolEntry(int cp, long value)
+            throws Pack200Exception {
         int index = (int) value;
         if (index == -1) {
             return null;
         } else if (index < 0) {
             throw new Pack200Exception("Cannot have a negative range");
         } else if (cp == UTF_8) {
-            return bands.cpUTF8Value(bands.getCpUTF8()[index], ClassConstantPool.DOMAIN_NORMALASCIIZ);
+            return bands.cpUTF8Value(bands.getCpUTF8()[index],
+                    ClassConstantPool.DOMAIN_NORMALASCIIZ);
         } else if (cp == CP_INT) {
             return bands.cpIntegerValue(new Integer(bands.getCpInt()[index]));
         } else if (cp == CP_FLOAT) {
@@ -268,11 +293,12 @@
         } else if (cp == CP_CLASS) {
             return bands.cpClassValue(bands.getCpClass()[index]);
         } else if (cp == SIGNATURE) {
-        	throw new Error("I don't know what to do with signatures yet");
-//            return null /* new CPSignature(bands.getCpSignature()[index]) */;
+            throw new Error("I don't know what to do with signatures yet");
+            // return null /* new CPSignature(bands.getCpSignature()[index]) */;
         } else if (cp == CP_DESCR) {
-        	throw new Error("I don't know what to do with descriptors yet");
-//            return null /* new CPDescriptor(bands.getCpDescriptor()[index]) */;
+            throw new Error("I don't know what to do with descriptors yet");
+            // return null /* new CPDescriptor(bands.getCpDescriptor()[index])
+            // */;
         } else if (cp == CP_FIELD) {
             return new CPFieldRef(bands
                     .cpClassValue(bands.getCpFieldClass()[index]), bands
@@ -283,8 +309,8 @@
                     .cpNameAndTypeValue(bands.getCpMethodDescriptor()[index]));
         } else if (cp == CP_IMETHOD) {
             return new CPInterfaceMethodRef(bands.cpClassValue(bands
-                    .getCpIMethodClass()[index]), bands.cpNameAndTypeValue(bands
-                    .getCpIMethodDescriptor()[index]));
+                    .getCpIMethodClass()[index]), bands
+                    .cpNameAndTypeValue(bands.getCpIMethodDescriptor()[index]));
         } else {
             // etc
             throw new Error("Get value incomplete");



Mime
View raw message