harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r764843 - in /harmony/enhanced/classlib/trunk/modules/pack200/src: main/java/org/apache/harmony/pack200/ test/java/org/apache/harmony/pack200/tests/
Date Tue, 14 Apr 2009 15:48:49 GMT
Author: sjanuary
Date: Tue Apr 14 15:48:48 2009
New Revision: 764843

URL: http://svn.apache.org/viewvc?rev=764843&view=rev
Log:
Pack200 - code and tests for creating specifiers for non-default BHSD codecs

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java
Tue Apr 14 15:48:48 2009
@@ -37,8 +37,6 @@
 
     private final Map layouts = new HashMap();
 
-    private final SegmentHeader segmentHeader;
-
     private final Map classAttributes = new HashMap();
     private final Map methodAttributes = new HashMap();
     private final Map fieldAttributes = new HashMap();
@@ -50,8 +48,7 @@
     private final Segment segment;
 
     public AttributeDefinitionBands(Segment segment, int effort) {
-        super(effort);
-        this.segmentHeader = segment.getSegmentHeader();
+        super(effort, segment.getSegmentHeader());
         this.cpBands = segment.getCpBands();
         this.segment = segment;
     }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
Tue Apr 14 15:48:48 2009
@@ -441,6 +441,13 @@
     }
 
     /**
+     * @return the s
+     */
+    public int getS() {
+        return s;
+    }
+
+    /**
      * @return the l
      */
     public int getL() {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
Tue Apr 14 15:48:48 2009
@@ -24,9 +24,11 @@
 public abstract class BandSet {
 
     private final int effort;
+    protected final SegmentHeader segmentHeader;
 
-    public BandSet(int effort) {
+    public BandSet(int effort, SegmentHeader header) {
         this.effort = effort;
+        this.segmentHeader = header;
     }
 
     public abstract void pack(OutputStream out) throws IOException, Pack200Exception;
@@ -40,7 +42,32 @@
     }
 
     public byte[] encodeBandInt(String name, int[] ints, BHSDCodec defaultCodec) throws Pack200Exception
{
-        // TODO non-default codecs
+        if(effort > 1 && (ints.length > 99 || effort == 9)) {
+            Codec betterCodec = lookForBetterCodec(name, ints, defaultCodec);
+            if(betterCodec != null) {
+                if(betterCodec instanceof BHSDCodec) {
+                    int[] specifierBand = CodecEncoding.getSpecifier(betterCodec);
+                    int specifier = specifierBand[0];
+                    if(specifierBand.length > 0) {
+                        for (int i = 1; i < specifierBand.length; i++) {
+                            segmentHeader.appendBandCodingSpecifier(specifierBand[i]);
+                        }
+                    }
+                    byte[] specifierEncoded = defaultCodec.encode(new int[] {specifier});
+                    byte[] rest = betterCodec.encode(ints);
+                    byte[] band = new byte[specifierEncoded.length + rest.length];
+                    System.arraycopy(specifierEncoded, 0, band, 0, specifierEncoded.length);
+                    System.arraycopy(rest, 0, band, specifierEncoded.length, rest.length);
+                    return band;
+                } else if (betterCodec instanceof PopulationCodec) {
+
+                } else if (betterCodec instanceof RunCodec) {
+
+                }
+            }
+        }
+
+        // If we get here then we've decided to use the default codec.
         if(ints.length > 0) {
 //            System.out.println("encoding " + name + ", size = " + ints.length);
             int first = ints[0];
@@ -69,6 +96,12 @@
         return new byte[0];
     }
 
+    private Codec lookForBetterCodec(String name, int[] ints,
+            BHSDCodec defaultCodec) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
     public boolean isPredictableSourceFileName(String className, String sourceFileName) {
         if (className.indexOf('.') != -1) {
             className = className.substring(className.lastIndexOf('.') + 1);

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
Tue Apr 14 15:48:48 2009
@@ -34,7 +34,7 @@
     private final Segment segment;
 
     public BcBands(CpBands cpBands, Segment segment, int effort) {
-        super(effort);
+        super(effort, segment.getSegmentHeader());
         this.cpBands = cpBands;
         this.segment = segment;
     }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
Tue Apr 14 15:48:48 2009
@@ -33,7 +33,6 @@
 
 public class ClassBands extends BandSet {
 
-    private final SegmentHeader header;
     private final CpBands cpBands;
     private final AttributeDefinitionBands attrBands;
 
@@ -117,9 +116,8 @@
     private final Map classReferencesInnerClass = new HashMap();
 
     public ClassBands(Segment segment, int numClasses, int effort) {
-        super(effort);
+        super(effort, segment.getSegmentHeader());
         this.segment = segment;
-        this.header = segment.getSegmentHeader();
         this.cpBands = segment.getCpBands();
         this.attrBands = segment.getAttrBands();
         class_this = new CPClass[numClasses];
@@ -136,15 +134,15 @@
         major_versions = new int[numClasses];
         class_flags = new long[numClasses];
 
-        class_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_CLASS, cpBands,
effort);
-        class_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_CLASS, cpBands,
effort);
-        field_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_FIELD, cpBands,
effort);
-        field_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_FIELD, cpBands,
effort);
-        method_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_METHOD,
cpBands, effort);
-        method_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_METHOD,
cpBands, effort);
-        method_RVPA_bands = new MetadataBandGroup("RVPA", MetadataBandGroup.CONTEXT_METHOD,
cpBands, effort);
-        method_RIPA_bands = new MetadataBandGroup("RIPA", MetadataBandGroup.CONTEXT_METHOD,
cpBands, effort);
-        method_AD_bands = new MetadataBandGroup("AD", MetadataBandGroup.CONTEXT_METHOD, cpBands,
effort);
+        class_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_CLASS, cpBands,
segmentHeader, effort);
+        class_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_CLASS, cpBands,
segmentHeader, effort);
+        field_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_FIELD, cpBands,
segmentHeader, effort);
+        field_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_FIELD, cpBands,
segmentHeader, effort);
+        method_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_METHOD,
cpBands, segmentHeader, effort);
+        method_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_METHOD,
cpBands, segmentHeader, effort);
+        method_RVPA_bands = new MetadataBandGroup("RVPA", MetadataBandGroup.CONTEXT_METHOD,
cpBands, segmentHeader, effort);
+        method_RIPA_bands = new MetadataBandGroup("RIPA", MetadataBandGroup.CONTEXT_METHOD,
cpBands, segmentHeader, effort);
+        method_AD_bands = new MetadataBandGroup("AD", MetadataBandGroup.CONTEXT_METHOD, cpBands,
segmentHeader, effort);
     }
 
     private int index = 0;
@@ -237,7 +235,7 @@
     }
 
     public void finaliseBands() {
-        int defaultMajorVersion = header.getDefaultMajorVersion();
+        int defaultMajorVersion = segmentHeader.getDefaultMajorVersion();
         for (int i = 0; i < class_flags.length; i++) {
             int major = major_versions[i];
             if (major != defaultMajorVersion) {
@@ -434,7 +432,7 @@
     private void writeFieldAttributeBands(OutputStream out) throws IOException,
             Pack200Exception {
         out.write(encodeFlags("field_flags", field_flags, Codec.UNSIGNED5,
-                Codec.UNSIGNED5, header.have_field_flags_hi()));
+                Codec.UNSIGNED5, segmentHeader.have_field_flags_hi()));
 //        *field_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
 //        *field_attr_indexes :UNSIGNED5 [SUM(*field_attr_count)]
         out.write(encodeBandInt("field_attr_calls", field_attr_calls, Codec.UNSIGNED5));
@@ -449,7 +447,7 @@
     private void writeMethodAttributeBands(OutputStream out)
             throws IOException, Pack200Exception {
         out.write(encodeFlags("method_flags", method_flags, Codec.UNSIGNED5,
-                Codec.UNSIGNED5, header.have_method_flags_hi()));
+                Codec.UNSIGNED5, segmentHeader.have_method_flags_hi()));
 //        *method_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
 //        *method_attr_indexes :UNSIGNED5 [SUM(*method_attr_count)]
         out.write(encodeBandInt("method_attr_calls", method_attr_calls, Codec.UNSIGNED5));
@@ -469,7 +467,7 @@
     private void writeClassAttributeBands(OutputStream out) throws IOException,
             Pack200Exception {
         out.write(encodeFlags("class_flags", class_flags, Codec.UNSIGNED5,
-                Codec.UNSIGNED5, header.have_class_flags_hi()));
+                Codec.UNSIGNED5, segmentHeader.have_class_flags_hi()));
 //        *class_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
 //        *class_attr_indexes :UNSIGNED5 [SUM(*class_attr_count)]
         out.write(encodeBandInt("class_attr_calls", class_attr_calls, Codec.UNSIGNED5));
@@ -527,7 +525,7 @@
     private void writeCodeAttributeBands(OutputStream out) throws IOException,
             Pack200Exception {
         out.write(encodeFlags("codeFlags", longListToArray(codeFlags),
-                Codec.UNSIGNED5, Codec.UNSIGNED5, header.have_code_flags_hi()));
+                Codec.UNSIGNED5, Codec.UNSIGNED5, segmentHeader.have_code_flags_hi()));
 
         // *code_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
         // *code_attr_indexes :UNSIGNED5 [SUM(*code_attr_count)]

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java
Tue Apr 14 15:48:48 2009
@@ -215,12 +215,31 @@
     }
 
     public static int getSpecifierForDefaultCodec(BHSDCodec defaultCodec) {
+        return getSpecifier(defaultCodec)[0];
+    }
+
+    public static int[] getSpecifier(Codec codec) {
+        // lazy initialization
         if(canonicalCodecsToSpecifiers == null) {
             canonicalCodecsToSpecifiers = new HashMap();
             for (int i = 0; i < canonicalCodec.length; i++) {
                 canonicalCodecsToSpecifiers.put(canonicalCodec[i], new Integer(i));
             }
         }
-        return ((Integer)canonicalCodecsToSpecifiers.get(defaultCodec)).intValue();
+
+        if(canonicalCodecsToSpecifiers.containsKey(codec)) {
+            return new int[] {((Integer)canonicalCodecsToSpecifiers.get(codec)).intValue()};
+        } else if (codec instanceof BHSDCodec) {
+            // Cache these?
+            BHSDCodec bhsdCodec = (BHSDCodec)codec;
+            int[] specifiers = new int[3];
+            specifiers[0] = 116;
+            specifiers[1] = (bhsdCodec.isDelta() ? 1 : 0) + 2
+                    * bhsdCodec.getS() + 8 * (bhsdCodec.getB()-1);
+            specifiers[2] = bhsdCodec.getH() - 1;
+            return specifiers;
+        }
+
+        return null;
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
Tue Apr 14 15:48:48 2009
@@ -34,8 +34,6 @@
  */
 public class CpBands extends BandSet {
 
-    private final SegmentHeader segmentHeader;
-
     // Don't need to include default attribute names in the constant pool bands
     private final Set defaultAttributeNames = new HashSet();
 
@@ -65,8 +63,7 @@
     private final Segment segment;
 
     public CpBands(Segment segment, int effort) {
-        super(effort);
-        this.segmentHeader = segment.getSegmentHeader();
+        super(effort, segment.getSegmentHeader());
         this.segment = segment;
         defaultAttributeNames.add("AnnotationDefault");
         defaultAttributeNames.add("RuntimeVisibleAnnotations");

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
Tue Apr 14 15:48:48 2009
@@ -24,7 +24,6 @@
 
 public class FileBands extends BandSet {
 
-    private final SegmentHeader segmentHeader;
     private final CPUTF8[] fileName;
     private int[] file_name;
     private final long[] file_modtime;
@@ -34,8 +33,7 @@
 
     public FileBands(CpBands cpBands, SegmentHeader segmentHeader,
             List files, int effort) {
-        super(effort);
-        this.segmentHeader = segmentHeader;
+        super(effort, segmentHeader);
         int size =  files.size();
         fileName = new CPUTF8[size];
         file_modtime = new long[size];

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
Tue Apr 14 15:48:48 2009
@@ -29,15 +29,13 @@
 public class IcBands extends BandSet {
 
     private final Set innerClasses = new TreeSet();
-    private final SegmentHeader segmentHeader;
     private final CpBands cpBands;
     private int bit16Count = 0;
 
     private final Map outerToInner = new HashMap();
 
     public IcBands(SegmentHeader segmentHeader, CpBands cpBands, int effort) {
-        super(effort);
-        this.segmentHeader = segmentHeader;
+        super(effort, segmentHeader);
         this.cpBands = cpBands;
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
Tue Apr 14 15:48:48 2009
@@ -61,8 +61,8 @@
      * Constructs a new MetadataBandGroup
      * @param type - must be either AD, RVA, RIA, RVPA or RIPA.
      */
-    public MetadataBandGroup(String type, int context, CpBands cpBands, int effort) {
-        super(effort);
+    public MetadataBandGroup(String type, int context, CpBands cpBands, SegmentHeader segmentHeader,
int effort) {
+        super(effort, segmentHeader);
         this.type = type;
         this.cpBands = cpBands;
         this.context = context;

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
Tue Apr 14 15:48:48 2009
@@ -25,7 +25,7 @@
 public class SegmentHeader extends BandSet {
 
     public SegmentHeader() {
-        super(1); // Don't do anything special for the header
+        super(1, null); // Don't do anything special for the header
     }
 
     private static final int[] magic = { 0xCA, 0xFE, 0xD0, 0x0D };
@@ -48,7 +48,7 @@
     private int cp_Imethod_count;
 
     private int attribute_definition_count;
-    private final byte[] band_headers = new byte[0];
+    private final IntList band_headers = new IntList();
 
     private boolean have_all_code_flags = true; // true by default
 
@@ -84,13 +84,13 @@
         writeArchiveSpecialCounts(out);
         writeCpCounts(out);
         writeClassCounts(out);
-        if (band_headers.length > 0) {
-            out.write(band_headers);
+        if (band_headers.size()> 0) {
+            out.write(encodeScalar(band_headers.toArray(), BHSDCodec.BYTE1));
         }
     }
 
     private void calculateArchiveOptions() {
-        if (attribute_definition_count > 0 || band_headers.length > 0) {
+        if (attribute_definition_count > 0 || band_headers.size() > 0) {
             archive_options |= 1;
         }
         if (cp_Int_count > 0 || cp_Float_count > 0 || cp_Long_count > 0
@@ -292,10 +292,9 @@
     private void writeArchiveSpecialCounts(OutputStream out)
             throws IOException, Pack200Exception {
         if ((archive_options & 1) > 0) { // have_special_formats
-            out.write(encodeScalar(band_headers.length, Codec.UNSIGNED5));
-            out
-                    .write(encodeScalar(attribute_definition_count,
-                            Codec.UNSIGNED5));
+            out.write(encodeScalar(band_headers.size(), Codec.UNSIGNED5));
+            out.write(encodeScalar(attribute_definition_count,
+                    Codec.UNSIGNED5));
         }
     }
 
@@ -377,4 +376,8 @@
         return have_all_code_flags;
     }
 
+    public void appendBandCodingSpecifier(int specifier) {
+        band_headers.add(specifier);
+    }
+
 }
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java?rev=764843&r1=764842&r2=764843&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java
Tue Apr 14 15:48:48 2009
@@ -18,6 +18,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -29,7 +30,7 @@
 import org.apache.harmony.pack200.Pack200Exception;
 
 /**
- * 
+ *
  */
 public class CodecEncodingTest extends TestCase {
 
@@ -172,4 +173,52 @@
                 null).toString());
     }
 
+    public void testGetSpecifier() throws IOException, Pack200Exception {
+        // Test canonical codecs
+        for (int i = 1; i <= 115; i++) {
+            assertEquals(i, CodecEncoding.getSpecifier(CodecEncoding.getCodec(i, null, null))[0]);
+        }
+
+        // Test a range of non-canonical codecs
+        Codec c1 = new BHSDCodec(2, 125, 0, 1);
+        int[] specifiers = CodecEncoding.getSpecifier(c1);
+        assertEquals(3, specifiers.length);
+        assertEquals(116, specifiers[0]);
+        byte[] bytes = new byte[] {(byte) specifiers[1], (byte) specifiers[2]};
+        InputStream in = new ByteArrayInputStream(bytes);
+        assertEquals(c1, CodecEncoding.getCodec(116, in, null));
+
+        c1 = new BHSDCodec(3, 125, 2, 1);
+        specifiers = CodecEncoding.getSpecifier(c1);
+        assertEquals(3, specifiers.length);
+        assertEquals(116, specifiers[0]);
+        bytes = new byte[] {(byte) specifiers[1], (byte) specifiers[2]};
+        in = new ByteArrayInputStream(bytes);
+        assertEquals(c1, CodecEncoding.getCodec(116, in, null));
+
+        c1 = new BHSDCodec(4, 125);
+        specifiers = CodecEncoding.getSpecifier(c1);
+        assertEquals(3, specifiers.length);
+        assertEquals(116, specifiers[0]);
+        bytes = new byte[] {(byte) specifiers[1], (byte) specifiers[2]};
+        in = new ByteArrayInputStream(bytes);
+        assertEquals(c1, CodecEncoding.getCodec(116, in, null));
+
+        c1 = new BHSDCodec(5, 125, 2, 0);
+        specifiers = CodecEncoding.getSpecifier(c1);
+        assertEquals(3, specifiers.length);
+        assertEquals(116, specifiers[0]);
+        bytes = new byte[] {(byte) specifiers[1], (byte) specifiers[2]};
+        in = new ByteArrayInputStream(bytes);
+        assertEquals(c1, CodecEncoding.getCodec(116, in, null));
+
+        c1 = new BHSDCodec(3, 5, 2, 1);
+        specifiers = CodecEncoding.getSpecifier(c1);
+        assertEquals(3, specifiers.length);
+        assertEquals(116, specifiers[0]);
+        bytes = new byte[] {(byte) specifiers[1], (byte) specifiers[2]};
+        in = new ByteArrayInputStream(bytes);
+        assertEquals(c1, CodecEncoding.getCodec(116, in, null));
+    }
+
 }



Mime
View raw message