harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From qi...@apache.org
Subject svn commit: r766448 [3/4] - in /harmony/enhanced/classlib/branches/java6: ./ depends/files/ depends/jars/icu4j_3.8/ depends/jars/icu4j_4.0/ depends/manifests/icu4j_3.8/META-INF/ depends/manifests/icu4j_4.0/ depends/manifests/icu4j_4.0/META-INF/ make/ m...
Date Sun, 19 Apr 2009 11:15:34 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/common/org/apache/harmony/nio/internal/SocketChannelImpl.java Sun Apr 19 11:15:28 2009
@@ -47,6 +47,7 @@
 import org.apache.harmony.luni.platform.INetworkSystem;
 import org.apache.harmony.luni.platform.Platform;
 import org.apache.harmony.luni.util.ErrorCodeException;
+import org.apache.harmony.luni.util.Msg;
 import org.apache.harmony.nio.AddressUtil;
 import org.apache.harmony.nio.internal.nls.Messages;
 
@@ -845,6 +846,81 @@
                     .booleanValue();
         }
 
+        @Override
+        public void setKeepAlive(boolean value) throws SocketException {
+            checkOpen();
+            socketImpl.setOption(SocketOptions.SO_KEEPALIVE, value ? Boolean.TRUE
+                    : Boolean.FALSE);
+        }
+
+        @Override
+        public void setOOBInline(boolean oobinline) throws SocketException {
+            checkOpen();
+            socketImpl.setOption(SocketOptions.SO_OOBINLINE, oobinline ? Boolean.TRUE
+                    : Boolean.FALSE);
+        }
+
+        @Override
+        public synchronized void setReceiveBufferSize(int size)
+                throws SocketException {
+            checkOpen();
+            if (size < 1) {
+                throw new IllegalArgumentException(Msg.getString("K0035")); //$NON-NLS-1$
+            }
+            socketImpl
+                    .setOption(SocketOptions.SO_RCVBUF, Integer.valueOf(size));
+        }
+
+        @Override
+        public void setReuseAddress(boolean reuse) throws SocketException {
+            checkOpen();
+            socketImpl.setOption(SocketOptions.SO_REUSEADDR, reuse ? Boolean.TRUE
+                    : Boolean.FALSE);
+        }
+
+        @Override
+        public synchronized void setSendBufferSize(int size) throws SocketException {
+            checkOpen();
+            if (size < 1) {
+                throw new IllegalArgumentException(Msg.getString("K0035")); //$NON-NLS-1$
+            }
+            socketImpl.setOption(SocketOptions.SO_SNDBUF, Integer.valueOf(size));
+        }
+
+        @Override
+        public void setSoLinger(boolean on, int timeout) throws SocketException {
+            checkOpen();
+            if (on && timeout < 0) {
+                throw new IllegalArgumentException(Msg.getString("K0045")); //$NON-NLS-1$
+            }
+            int val = on ? (65535 < timeout ? 65535 : timeout) : -1;
+            socketImpl.setOption(SocketOptions.SO_LINGER, Integer.valueOf(val));
+        }
+
+        @Override
+        public synchronized void setSoTimeout(int timeout) throws SocketException {
+            checkOpen();
+            if (timeout < 0) {
+                throw new IllegalArgumentException(Msg.getString("K0036")); //$NON-NLS-1$
+            }
+            socketImpl.setOption(SocketOptions.SO_TIMEOUT, Integer.valueOf(timeout));
+        }
+
+        @Override
+        public void setTcpNoDelay(boolean on) throws SocketException {
+            checkOpen();
+            socketImpl.setOption(SocketOptions.TCP_NODELAY, Boolean.valueOf(on));
+        }
+
+        @Override
+        public void setTrafficClass(int value) throws SocketException {
+            checkOpen();
+            if (value < 0 || value > 255) {
+                throw new IllegalArgumentException();
+            }
+            socketImpl.setOption(SocketOptions.IP_TOS, Integer.valueOf(value));
+        }
+
         /**
          * @see java.net.Socket#getOutputStream()
          */

Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/channels/SocketChannelTest.java Sun Apr 19 11:15:28 2009
@@ -3085,6 +3085,39 @@
         }
     }
 
+    public void testSocket_setOptions() throws IOException {
+        channel1.connect(localAddr1);
+        Socket socket = channel1.socket();
+
+        ByteBuffer buffer = ByteBuffer.wrap(new byte[] {1, 2, 3});
+        socket.setKeepAlive(true);
+        channel1.write(buffer);
+
+        socket.setOOBInline(true);
+        channel1.write(buffer);
+
+        socket.setReceiveBufferSize(100);
+        channel1.write(buffer);
+
+        socket.setReuseAddress(true);
+        channel1.write(buffer);
+
+        socket.setSendBufferSize(100);
+        channel1.write(buffer);
+
+        socket.setSoLinger(true, 100);
+        channel1.write(buffer);
+
+        socket.setSoTimeout(1000);
+        channel1.write(buffer);
+
+        socket.setTcpNoDelay(true);
+        channel1.write(buffer);
+
+        socket.setTrafficClass(10);
+        channel1.write(buffer);
+    }
+
     class MockSocketChannel extends SocketChannel{
         
         private boolean isWriteCalled = false;

Modified: harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/java/nio/charset/Charset.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/java/nio/charset/Charset.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/java/nio/charset/Charset.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio_char/src/main/java/java/nio/charset/Charset.java Sun Apr 19 11:15:28 2009
@@ -109,6 +109,8 @@
     // cached Charset table
     private final static HashMap<String, Charset> cachedCharsetTable = new HashMap<String, Charset>();
 
+    private static boolean inForNameInternal = false;
+
     static {
         /*
          * Create built-in charset provider even if no privilege to access
@@ -322,6 +324,11 @@
      */
     @SuppressWarnings("unchecked")
     public static SortedMap<String, Charset> availableCharsets() {
+        // workaround: conflicted Charsets with icu4j 4.0
+        Charset.forName("TIS-620");
+        Charset.forName("windows-1258");
+        Charset.forName("cp856");
+        Charset.forName("cp922");
         // Initialize the built-in charsets map cache if necessary
         if (null == _builtInCharsets) {
             synchronized (Charset.class) {
@@ -468,8 +475,10 @@
 
             // examine each configuration file
             while (e.hasMoreElements()) {
-                cs = searchConfiguredCharsets(charsetName, contextClassLoader,
+			     inForNameInternal = true;
+			     cs = searchConfiguredCharsets(charsetName, contextClassLoader,
                         e.nextElement());
+				 inForNameInternal = false;
                 if (null != cs) {
                     cacheCharset(cs);
                     return cs;
@@ -477,6 +486,8 @@
             }
         } catch (IOException ex) {
             // Unexpected ClassLoader exception, ignore
+		} finally {
+		    inForNameInternal = false;
         }
         return null;
     }
@@ -485,13 +496,17 @@
      * save charset into cachedCharsetTable
      */
     private static void cacheCharset(Charset cs) {
-        cachedCharsetTable.put(cs.name(), cs);
+        if (!cachedCharsetTable.containsKey(cs.name())){
+            cachedCharsetTable.put(cs.name(), cs);  
+        }
         Set<String> aliasesSet = cs.aliases();
         if (null != aliasesSet) {
             Iterator<String> iter = aliasesSet.iterator();
             while (iter.hasNext()) {
                 String alias = iter.next();
-                cachedCharsetTable.put(alias, cs);
+                if (!cachedCharsetTable.containsKey(alias)) {
+                    cachedCharsetTable.put(alias, cs); 
+                }
             }
         }
     }
@@ -525,8 +540,32 @@
      *             If the specified charset name is illegal.
      */
     public static boolean isSupported(String charsetName) {
-        Charset cs = forNameInternal(charsetName);
-        return (null != cs);
+        if (inForNameInternal  == true) {
+            Charset cs = cachedCharsetTable.get(charsetName);
+            if (null != cs) {
+                return true;
+            }
+
+            if (null == charsetName) {
+                throw new IllegalArgumentException();
+            }
+            checkCharsetName(charsetName);
+
+            // Try built-in charsets
+            if (_builtInProvider == null) {
+                _builtInProvider = new CharsetProviderImpl();
+            }
+            cs = _builtInProvider.charsetForName(charsetName);
+            if (null != cs) {
+                cacheCharset(cs);
+                return true;
+            }
+            return false;
+        } else {
+            Charset cs = forNameInternal(charsetName);
+            return (null != cs);
+        }
+
     }
 
     /**

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java Sun Apr 19 11:15:28 2009
@@ -28,6 +28,7 @@
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 import java.util.zip.GZIPOutputStream;
 
@@ -44,6 +45,7 @@
     private long segmentLimit = 1000000;
     private long currentSegmentSize;
     private boolean stripDebug;
+    private int effort = 5;
 
     public Archive(JarInputStream inputStream, OutputStream outputStream,
             boolean gzip) throws IOException {
@@ -54,7 +56,12 @@
         this.outputStream = new BufferedOutputStream(outputStream);
     }
 
-    public Archive(JarFile jarFile, OutputStream outputStream) {
+    public Archive(JarFile jarFile, OutputStream outputStream,
+            boolean gzip) throws IOException {
+
+        if (gzip) {
+            outputStream = new GZIPOutputStream(outputStream);
+        }
         this.outputStream = new BufferedOutputStream(outputStream);
         this.jarFile = jarFile;
         inputStream = null;
@@ -64,6 +71,10 @@
         segmentLimit = limit;
     }
 
+    public void setEffort(int effort) {
+        this.effort = effort;
+    }
+
     public void stripDebugAttributes() {
         stripDebug = true;
     }
@@ -71,66 +82,127 @@
     public void pack() throws Pack200Exception, IOException {
         List classes = new ArrayList();
         List files = new ArrayList();
-        Manifest manifest = jarFile != null ? jarFile.getManifest()
-                : inputStream.getManifest();
-        if (manifest != null) {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            manifest.write(baos);
-            // TODO: Need to add this in some cases, but I'm not sure which at the moment
-//            files.add(new File("META-INF", new byte[0], 0));
-            files.add(new File("META-INF/MANIFEST.MF", baos.toByteArray(), 0));
-        }
-        if (inputStream != null) {
-            JarEntry jarEntry = inputStream.getNextJarEntry();
-            while (jarEntry != null) {
-                boolean added = addJarEntry(jarEntry,
-                        new BufferedInputStream(inputStream), classes,
-                        files);
-                if (!added) { // not added because segment has reached
-                    // maximum size
-                    if(classes.size() > 0 || files.size() > 0) {
-                        new Segment().pack(classes, files, outputStream, stripDebug);
+
+        if(effort == 0) {
+            doZeroEffortPack();
+        } else {
+
+            if (inputStream != null) {
+                Manifest manifest = jarFile != null ? jarFile.getManifest()
+                        : inputStream.getManifest();
+                if (manifest != null) {
+                    System.out.println("manifest exists");
+                    System.out.println(manifest.toString());
+                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                    manifest.write(baos);
+                    files.add(new File("META-INF", new byte[0], 0));
+                    files.add(new File("META-INF/MANIFEST.MF", baos.toByteArray(), 0));
+                }
+                JarEntry jarEntry = inputStream.getNextJarEntry();
+                while (jarEntry != null) {
+                    if(jarEntry.getName().startsWith("META-INF")) {
+                        System.out.println(jarEntry.getName());
+                    }
+                    boolean added = addJarEntry(jarEntry,
+                            new BufferedInputStream(inputStream), classes,
+                            files);
+                    if (!added) { // not added because segment has reached
+                        // maximum size
+                        if(classes.size() > 0 || files.size() > 0) {
+                            new Segment().pack(classes, files, outputStream, stripDebug, effort);
+                            classes = new ArrayList();
+                            files = new ArrayList();
+                            currentSegmentSize = 0;
+                            addJarEntry(jarEntry, new BufferedInputStream(inputStream), classes, files);
+                            currentSegmentSize = 0; // ignore the size of the first entry for compatibility with the RI
+                        }
+                    } else if (segmentLimit == 0 && estimateSize(jarEntry) > 0) {
+                        // create a new segment for each class unless size = 0
+                        new Segment().pack(classes, files, outputStream, stripDebug, effort);
+                        classes = new ArrayList();
+                        files = new ArrayList();
+                    }
+                    jarEntry = inputStream.getNextJarEntry();
+                }
+            } else {
+                Enumeration jarEntries = jarFile.entries();
+                while (jarEntries.hasMoreElements()) {
+                    JarEntry jarEntry = (JarEntry) jarEntries.nextElement();
+                    boolean added = addJarEntry(jarEntry, new BufferedInputStream(
+                            jarFile.getInputStream(jarEntry)), classes, files);
+                    if (!added) { // not added because segment has reached maximum
+                        // size
+                        new Segment().pack(classes, files, outputStream, stripDebug, effort);
                         classes = new ArrayList();
                         files = new ArrayList();
                         currentSegmentSize = 0;
-                        addJarEntry(jarEntry, new BufferedInputStream(inputStream), classes, files);
+                        addJarEntry(jarEntry, new BufferedInputStream(jarFile
+                                .getInputStream(jarEntry)), classes, files);
                         currentSegmentSize = 0; // ignore the size of the first entry for compatibility with the RI
+                    } else if (segmentLimit == 0 && estimateSize(jarEntry) > 0) {
+                        // create a new segment for each class unless size = 0
+                        new Segment().pack(classes, files, outputStream, stripDebug, effort);
+                        classes = new ArrayList();
+                        files = new ArrayList();
                     }
-                } else if (segmentLimit == 0 && estimateSize(jarEntry) > 0) {
-                    // create a new segment for each class unless size = 0
-                    new Segment().pack(classes, files, outputStream, stripDebug);
-                    classes = new ArrayList();
-                    files = new ArrayList();
                 }
-                jarEntry = inputStream.getNextJarEntry();
             }
+            if(classes.size() > 0 || files.size() > 0) {
+                new Segment().pack(classes, files, outputStream, stripDebug, effort);
+            }
+            outputStream.close();
+        }
+    }
+
+    private void doZeroEffortPack() throws IOException, Pack200Exception {
+        JarOutputStream jarOutputStream = new JarOutputStream(outputStream);
+        if(inputStream != null) {
+            JarInputStream jarInputStream;
+            if(!(inputStream instanceof JarInputStream)) {
+                jarInputStream = new JarInputStream(inputStream);
+            } else {
+                jarInputStream = inputStream;
+            }
+            Manifest manifest = jarInputStream.getManifest();
+            if (manifest != null) {
+                jarOutputStream.putNextEntry(new JarEntry("META-INF/"));
+                jarOutputStream.closeEntry();
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                manifest.write(baos);
+                jarOutputStream.putNextEntry(new JarEntry("META-INF/MANIFEST.MF"));
+                jarOutputStream.write(baos.toByteArray());
+                jarOutputStream.closeEntry();
+            }
+            BufferedInputStream buff = new BufferedInputStream(jarInputStream);
+            JarEntry jarEntry;
+            while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
+                jarOutputStream.putNextEntry(jarEntry);
+                byte[] bytes = new byte[(int) jarEntry.getSize()];
+                int bytesRead = buff.read(bytes);
+                if(bytesRead != jarEntry.getSize()) {
+                    throw new Pack200Exception("Error reading from input jar file");
+                }
+                jarOutputStream.write(bytes, 0, bytesRead);
+                jarOutputStream.closeEntry();
+            }
+            jarOutputStream.close();
         } else {
             Enumeration jarEntries = jarFile.entries();
             while (jarEntries.hasMoreElements()) {
                 JarEntry jarEntry = (JarEntry) jarEntries.nextElement();
-                boolean added = addJarEntry(jarEntry, new BufferedInputStream(
-                        jarFile.getInputStream(jarEntry)), classes, files);
-                if (!added) { // not added because segment has reached maximum
-                    // size
-                    new Segment().pack(classes, files, outputStream, stripDebug);
-                    classes = new ArrayList();
-                    files = new ArrayList();
-                    currentSegmentSize = 0;
-                    addJarEntry(jarEntry, new BufferedInputStream(jarFile
-                            .getInputStream(jarEntry)), classes, files);
-                    currentSegmentSize = 0; // ignore the size of the first entry for compatibility with the RI
-                } else if (segmentLimit == 0 && estimateSize(jarEntry) > 0) {
-                    // create a new segment for each class unless size = 0
-                    new Segment().pack(classes, files, outputStream, stripDebug);
-                    classes = new ArrayList();
-                    files = new ArrayList();
+                InputStream inStream = new BufferedInputStream(
+                        jarFile.getInputStream(jarEntry));
+                jarOutputStream.putNextEntry(jarEntry);
+                byte[] bytes = new byte[16384];
+                int bytesRead = inStream.read(bytes);
+                while (bytesRead != -1) {
+                    jarOutputStream.write(bytes, 0, bytesRead);
+                    bytesRead = inStream.read(bytes);
                 }
+                jarOutputStream.closeEntry();
             }
+            jarOutputStream.close();
         }
-        if(classes.size() > 0 || files.size() > 0) {
-            new Segment().pack(classes, files, outputStream, stripDebug);
-        }
-        outputStream.close();
     }
 
     private boolean addJarEntry(JarEntry jarEntry, InputStream stream,
@@ -140,7 +212,8 @@
         if (size > Integer.MAX_VALUE) {
             throw new RuntimeException("Large Class!"); // TODO: Should probably allow this
         } else if (size < 0) {
-            throw new RuntimeException("Error: size for " + name + " is " + size);
+            size = 0;
+//            throw new RuntimeException("Error: size for " + name + " is " + size);
         }
         if(segmentLimit != -1 && segmentLimit != 0) {
             // -1 is a special case where only one segment is created and

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java Sun Apr 19 11:15:28 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();
@@ -49,8 +47,8 @@
     private final CpBands cpBands;
     private final Segment segment;
 
-    public AttributeDefinitionBands(Segment segment) {
-        this.segmentHeader = segment.getSegmentHeader();
+    public AttributeDefinitionBands(Segment segment, int effort) {
+        super(effort, segment.getSegmentHeader());
         this.cpBands = segment.getCpBands();
         this.segment = segment;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java Sun Apr 19 11:15:28 2009
@@ -441,6 +441,13 @@
     }
 
     /**
+     * @return the s
+     */
+    public int getS() {
+        return s;
+    }
+
+    /**
      * @return the l
      */
     public int getL() {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java Sun Apr 19 11:15:28 2009
@@ -23,6 +23,14 @@
 
 public abstract class BandSet {
 
+    private final int effort;
+    protected final SegmentHeader segmentHeader;
+
+    public BandSet(int effort, SegmentHeader header) {
+        this.effort = effort;
+        this.segmentHeader = header;
+    }
+
     public abstract void pack(OutputStream out) throws IOException, Pack200Exception;
 
     public byte[] encodeScalar(int[] band, BHSDCodec codec) throws Pack200Exception {
@@ -34,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, defaultCodec);
+                    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];
@@ -63,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/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java Sun Apr 19 11:15:28 2009
@@ -33,7 +33,8 @@
     private final CpBands cpBands;
     private final Segment segment;
 
-    public BcBands(CpBands cpBands, Segment segment) {
+    public BcBands(CpBands cpBands, Segment segment, int effort) {
+        super(effort, segment.getSegmentHeader());
         this.cpBands = cpBands;
         this.segment = segment;
     }
@@ -61,7 +62,6 @@
     private final List bcInitRef = new ArrayList();
 
     private String currentClass;
-    private String superClass;
 
     private static final int MULTIANEWARRAY = 197;
     private static final int ALOAD_0 = 42;
@@ -82,10 +82,6 @@
         currentClass = name;
     }
 
-    public void setSuperClass(String superName) {
-        superClass = superName;
-    }
-
     public void finaliseBands() {
         bcThisField = getIndexInClass(bcThisField);
         bcThisMethod = getIndexInClass(bcThisMethod);
@@ -229,7 +225,7 @@
     }
 
     public void visitIincInsn(int var, int increment) {
-        if (increment > Byte.MAX_VALUE) {
+        if (var > 255 || increment > 255) {
             byteCodeOffset += 6;
             bcCodes.add(WIDE);
             bcCodes.add(IINC);
@@ -427,7 +423,7 @@
 
     public void visitVarInsn(int opcode, int var) {
         // ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET
-        if (var > Byte.MAX_VALUE) {
+        if (var > 255) {
             byteCodeOffset += 4;
             bcCodes.add(WIDE);
             bcCodes.add(opcode);

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Sun Apr 19 11:15:28 2009
@@ -33,7 +33,6 @@
 
 public class ClassBands extends BandSet {
 
-    private final SegmentHeader header;
     private final CpBands cpBands;
     private final AttributeDefinitionBands attrBands;
 
@@ -116,9 +115,9 @@
 
     private final Map classReferencesInnerClass = new HashMap();
 
-    public ClassBands(Segment segment, int numClasses) {
+    public ClassBands(Segment segment, int numClasses, int 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];
@@ -135,15 +134,15 @@
         major_versions = new int[numClasses];
         class_flags = new long[numClasses];
 
-        class_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_CLASS, cpBands);
-        class_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_CLASS, cpBands);
-        field_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_FIELD, cpBands);
-        field_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_FIELD, cpBands);
-        method_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_METHOD, cpBands);
-        method_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_METHOD, cpBands);
-        method_RVPA_bands = new MetadataBandGroup("RVPA", MetadataBandGroup.CONTEXT_METHOD, cpBands);
-        method_RIPA_bands = new MetadataBandGroup("RIPA", MetadataBandGroup.CONTEXT_METHOD, cpBands);
-        method_AD_bands = new MetadataBandGroup("AD", MetadataBandGroup.CONTEXT_METHOD, cpBands);
+        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;
@@ -236,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) {
@@ -433,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));
@@ -448,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));
@@ -468,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));
@@ -526,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)]
@@ -947,7 +946,7 @@
 
     public void addAnnotationDefault(List nameRU, List t, List values, List caseArrayN, List nestTypeRS, List nestNameRU, List nestPairN) {
         method_AD_bands.addAnnotation(null, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
-        Integer flag = (Integer) tempMethodFlags.remove(tempMethodFlags.size() - 1);
-        tempMethodFlags.add(new Integer(flag.intValue() | (1<<25)));
+        Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+        tempMethodFlags.add(new Long(flag.longValue() | (1<<25)));
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java Sun Apr 19 11:15:28 2009
@@ -19,6 +19,7 @@
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -215,12 +216,122 @@
     }
 
     public static int getSpecifierForDefaultCodec(BHSDCodec defaultCodec) {
+        return getSpecifier(defaultCodec, null)[0];
+    }
+
+    public static int[] getSpecifier(Codec codec, Codec defaultForBand) {
+        // 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;
+        } else if (codec instanceof RunCodec) {
+            RunCodec runCodec = (RunCodec) codec;
+            int k = runCodec.getK();
+            int kb;
+            int kx;
+            if(k <= 256) {
+                kb = 0;
+                kx = k - 1;
+            } else if (k <= 4096) {
+                kb = 1;
+                kx = k/16 - 1;
+            } else if (k <= 65536) {
+                kb = 2;
+                kx = k/256 - 1;
+            } else {
+                kb = 3;
+                kx = k/4096 - 1;
+            }
+            Codec aCodec = runCodec.getACodec();
+            Codec bCodec = runCodec.getBCodec();
+            int abDef = 0;
+            if(aCodec.equals(defaultForBand)) {
+                abDef = 1;
+            } else if (bCodec.equals(defaultForBand)) {
+                abDef = 2;
+            }
+            int first = 117 + kb + (kx==3 ? 0 : 4) + (8 * abDef);
+            int[] aSpecifier = abDef == 1 ? new int[0] : getSpecifier(aCodec, defaultForBand);
+            int[] bSpecifier = abDef == 2 ? new int[0] : getSpecifier(bCodec, defaultForBand);
+            int[] specifier = new int[1 + (kx==3 ? 0 : 1) + aSpecifier.length + bSpecifier.length];
+            specifier[0] = first;
+            int index = 1;
+            if(kx != 3) {
+                specifier[1] = kx;
+                index++;
+            }
+            for (int i = 0; i < aSpecifier.length; i++) {
+                specifier[index] = aSpecifier[i];
+                index++;
+            }
+            for (int i = 0; i < bSpecifier.length; i++) {
+                specifier[index] = bSpecifier[i];
+                index++;
+            }
+            return specifier;
+        } else if (codec instanceof PopulationCodec) {
+            PopulationCodec populationCodec = (PopulationCodec) codec;
+            Codec tokenCodec = populationCodec.getTokenCodec();
+            Codec favouredCodec = populationCodec.getFavouredCodec();
+            Codec unfavouredCodec = populationCodec.getUnfavouredCodec();
+            int fDef = favouredCodec.equals(defaultForBand) ? 1 : 0;
+            int uDef = unfavouredCodec.equals(defaultForBand) ? 1 : 0;
+            int tDefL = 0;
+            long[] favoured = populationCodec.getFavoured();
+            if(favoured != null) {
+                int k = favoured.length;
+                if(tokenCodec == Codec.BYTE1) {
+                    tDefL = 1;
+                } else if (tokenCodec instanceof BHSDCodec) {
+                    BHSDCodec tokenBHSD = (BHSDCodec) tokenCodec;
+                    if(tokenBHSD.getS() == 0) {
+                        int[] possibleLValues = new int[] {4, 8, 16, 32, 64, 128, 192, 224, 240, 248, 252};
+                        int l = 256-tokenBHSD.getH();
+                        int index = Arrays.binarySearch(possibleLValues, l);
+                        if(index != -1) {
+                            // TODO: check range is ok for ks
+                            tDefL = index++;
+                        }
+                    }
+                }
+            }
+            int first = 141 + fDef + (2 * uDef) + (4 * tDefL);
+            int[] favouredSpecifier = fDef == 1 ? new int[0] : getSpecifier(favouredCodec, defaultForBand);
+            int[] tokenSpecifier = tDefL != 0 ? new int[0] : getSpecifier(tokenCodec, defaultForBand);
+            int[] unfavouredSpecifier = uDef == 1 ? new int[0] : getSpecifier(unfavouredCodec, defaultForBand);
+            int[] specifier = new int[1 + favouredSpecifier.length + unfavouredSpecifier.length + tokenSpecifier.length];
+            specifier[0] = first;
+            int index = 1;
+            for (int i = 0; i < favouredSpecifier.length; i++) {
+                specifier[index] = favouredSpecifier[i];
+                index++;
+            }
+            for (int i = 0; i < tokenSpecifier.length; i++) {
+                specifier[index] = tokenSpecifier[i];
+                index++;
+            }
+            for (int i = 0; i < unfavouredSpecifier.length; i++) {
+                specifier[index] = unfavouredSpecifier[i];
+                index++;
+            }
+            return specifier;
+        }
+
+        return null;
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java Sun Apr 19 11:15:28 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();
 
@@ -64,8 +62,8 @@
 
     private final Segment segment;
 
-    public CpBands(Segment segment) {
-        this.segmentHeader = segment.getSegmentHeader();
+    public CpBands(Segment segment, int effort) {
+        super(effort, segment.getSegmentHeader());
         this.segment = segment;
         defaultAttributeNames.add("AnnotationDefault");
         defaultAttributeNames.add("RuntimeVisibleAnnotations");
@@ -409,6 +407,9 @@
     }
 
     public CPSignature getCPSignature(String signature) {
+        if(signature == null) {
+            return null;
+        }
         CPSignature cpS = (CPSignature) stringsToCpSignature.get(signature);
         if (cpS == null) {
             List cpClasses = new ArrayList();

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java Sun Apr 19 11:15:28 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;
@@ -33,8 +32,8 @@
     private final byte[][] file_bits;
 
     public FileBands(CpBands cpBands, SegmentHeader segmentHeader,
-            List files) {
-        this.segmentHeader = segmentHeader;
+            List files, int effort) {
+        super(effort, segmentHeader);
         int size =  files.size();
         fileName = new CPUTF8[size];
         file_modtime = new long[size];

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java Sun Apr 19 11:15:28 2009
@@ -29,14 +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) {
-        this.segmentHeader = segmentHeader;
+    public IcBands(SegmentHeader segmentHeader, CpBands cpBands, int effort) {
+        super(effort, segmentHeader);
         this.cpBands = cpBands;
     }
 

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java Sun Apr 19 11:15:28 2009
@@ -61,7 +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) {
+    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/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java Sun Apr 19 11:15:28 2009
@@ -134,7 +134,7 @@
         return favouredCodec;
     }
 
-    public Codec getUnvafouredCodec() {
+    public Codec getUnfavouredCodec() {
         return unvafouredCodec;
     }
 
@@ -147,4 +147,12 @@
         // TODO Auto-generated method stub
         return null;
     }
+
+    public Codec getTokenCodec() {
+        return tokenCodec;
+    }
+
+    public int getL() {
+        return l;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java Sun Apr 19 11:15:28 2009
@@ -105,7 +105,7 @@
             for (int i = 0; i < band.length; i++) {
                 boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                 Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
-                        : popCodec.getUnvafouredCodec();
+                        : popCodec.getUnfavouredCodec();
                 if (theCodec instanceof BHSDCodec
                         && ((BHSDCodec) theCodec).isDelta()) {
                     BHSDCodec bhsd = (BHSDCodec) theCodec;
@@ -135,4 +135,16 @@
         // TODO Auto-generated method stub
         return null;
     }
+
+    public int getK() {
+        return k;
+    }
+
+    public Codec getACodec() {
+        return aCodec;
+    }
+
+    public Codec getBCodec() {
+        return bCodec;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java Sun Apr 19 11:15:28 2009
@@ -44,19 +44,21 @@
     private final SegmentMethodVisitor methodVisitor = new SegmentMethodVisitor();
     private Pack200ClassReader currentClassReader;
     private boolean stripDebug;
+    private int effort;
 
-    public void pack(List classes, List files, OutputStream out, boolean stripDebug)
+    public void pack(List classes, List files, OutputStream out, boolean stripDebug, int effort)
             throws IOException, Pack200Exception {
+        this.effort = effort;
         this.stripDebug = stripDebug;
         segmentHeader = new SegmentHeader();
         segmentHeader.setFile_count(files.size());
         segmentHeader.setHave_all_code_flags(!stripDebug);
-        cpBands = new CpBands(this);
-        attributeDefinitionBands = new AttributeDefinitionBands(this);
-        icBands = new IcBands(segmentHeader, cpBands);
-        classBands = new ClassBands(this, classes.size());
-        bcBands = new BcBands(cpBands, this);
-        fileBands = new FileBands(cpBands, segmentHeader, files);
+        cpBands = new CpBands(this, effort);
+        attributeDefinitionBands = new AttributeDefinitionBands(this, effort);
+        icBands = new IcBands(segmentHeader, cpBands, effort);
+        classBands = new ClassBands(this, classes.size(), effort);
+        bcBands = new BcBands(cpBands, this, effort);
+        fileBands = new FileBands(cpBands, segmentHeader, files, effort);
 
         processClasses(classes);
 
@@ -89,7 +91,6 @@
     public void visit(int version, int access, String name, String signature,
             String superName, String[] interfaces) {
         bcBands.setCurrentClass(name);
-        bcBands.setSuperClass(superName);
         segmentHeader.addMajorVersion(version);
         classBands.addClass(version, access, name, signature, superName,
                 interfaces);
@@ -295,6 +296,9 @@
         }
 
         public void visit(String name, Object value) {
+            if (name == null) {
+                name = "";
+            }
             nameRU.add(name);
             values.add(value);
             addTag(value);
@@ -326,6 +330,9 @@
 
         public AnnotationVisitor visitAnnotation(String name, String desc) {
             T.add("@");
+            if (name == null) {
+                name = "";
+            }
             nameRU.add(name);
             nestTypeRS.add(desc);
             nestPairN.add(new Integer(0));
@@ -366,12 +373,18 @@
 
         public AnnotationVisitor visitArray(String name) {
             T.add("[");
+            if (name == null) {
+                name = "";
+            }
             nameRU.add(name);
             caseArrayN.add(new Integer(0));
             return new AnnotationVisitor() {
                 public void visit(String name, Object value) {
                     Integer numCases = (Integer) caseArrayN.remove(caseArrayN.size() - 1);
                     caseArrayN.add(new Integer(numCases.intValue() + 1));
+                    if (name == null) {
+                        name = "";
+                    }
                     nameRU.add(name);
                     values.add(value);
                     addTag(value);
@@ -388,13 +401,15 @@
                 }
 
                 public void visitEnd() {
-                    throw new RuntimeException("Not yet supported");
                 }
 
                 public void visitEnum(String name, String desc, String value) {
                     Integer numCases = (Integer) caseArrayN.remove(caseArrayN.size() - 1);
                     caseArrayN.add(new Integer(numCases.intValue() + 1));
                     T.add("e");
+                    if(name == null) {
+                        name = "";
+                    }
                     nameRU.add(name);
                     values.add(desc);
                     values.add(value);
@@ -414,6 +429,9 @@
 
         public void visitEnum(String name, String desc, String value) {
             T.add("e");
+            if (name == null) {
+                name = "";
+            }
             nameRU.add(name);
             values.add(desc);
             values.add(value);

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java Sun Apr 19 11:15:28 2009
@@ -24,6 +24,10 @@
  */
 public class SegmentHeader extends BandSet {
 
+    public SegmentHeader() {
+        super(1, null); // Don't do anything special for the header
+    }
+
     private static final int[] magic = { 0xCA, 0xFE, 0xD0, 0x0D };
     private static final int archive_minver = 7;
     private static final int archive_majver = 150;
@@ -44,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
 
@@ -80,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
@@ -288,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));
         }
     }
 
@@ -373,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/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BandSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BandSet.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BandSet.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BandSet.java Sun Apr 19 11:15:28 2009
@@ -16,7 +16,6 @@
  */
 package org.apache.harmony.unpack200;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
@@ -127,7 +126,7 @@
             for (int i = 0; i < band.length; i++) {
                 boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                 Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
-                        : popCodec.getUnvafouredCodec();
+                        : popCodec.getUnfavouredCodec();
                 if (theCodec instanceof BHSDCodec
                         && ((BHSDCodec) theCodec).isDelta()) {
                     BHSDCodec bhsd = (BHSDCodec) theCodec;
@@ -251,7 +250,7 @@
             for (int i = 0; i < band.length; i++) {
                 boolean favouredValue = Arrays.binarySearch(favoured, band[i]) > -1;
                 Codec theCodec = favouredValue ? popCodec.getFavouredCodec()
-                        : popCodec.getUnvafouredCodec();
+                        : popCodec.getUnfavouredCodec();
                 if (theCodec instanceof BHSDCodec
                         && ((BHSDCodec) theCodec).isDelta()) {
                     BHSDCodec bhsd = (BHSDCodec) theCodec;

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java5/org/apache/harmony/unpack200/Pack200PackerAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java5/org/apache/harmony/unpack200/Pack200PackerAdapter.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java5/org/apache/harmony/unpack200/Pack200PackerAdapter.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java5/org/apache/harmony/unpack200/Pack200PackerAdapter.java Sun Apr 19 11:15:28 2009
@@ -39,7 +39,7 @@
                     "Must specify both input and output streams");
         completed(0);
         try {
-            new org.apache.harmony.pack200.Archive(file, out).pack();
+            new org.apache.harmony.pack200.Archive(file, out, true).pack();
         } catch (Pack200Exception e) {
             throw new IOException("Failed to pack Jar:" + String.valueOf(e));
         }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java Sun Apr 19 11:15:28 2009
@@ -28,7 +28,6 @@
 import java.util.Enumeration;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
-import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 
 import junit.framework.TestCase;
@@ -39,14 +38,13 @@
 
 public class ArchiveTest extends TestCase {
 
-    JarInputStream in;
+    JarFile in;
     OutputStream out;
     File file;
 
     public void testHelloWorld() throws IOException, Pack200Exception, URISyntaxException {
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
         file = File.createTempFile("helloworld", ".pack.gz");
         out = new FileOutputStream(file);
         new Archive(in, out, true).pack();
@@ -95,8 +93,8 @@
     }
 
     public void testSQL() throws IOException, Pack200Exception, URISyntaxException {
-        in = new JarInputStream(Archive.class
-                .getResourceAsStream("/org/apache/harmony/pack200/tests/sqlUnpacked.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
         file = File.createTempFile("sql", ".pack");
         out = new FileOutputStream(file);
         new Archive(in, out, false).pack();
@@ -121,9 +119,37 @@
         compareFiles(jarFile, jarFile2);
     }
 
+    public void testLargeClass() throws IOException, Pack200Exception, URISyntaxException {
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/largeClassUnpacked.jar")
+                .toURI()));
+        file = File.createTempFile("largeClass", ".pack");
+        out = new FileOutputStream(file);
+        new Archive(in, out, false).pack();
+        in.close();
+        out.close();
+
+        // now unpack
+        InputStream in2 = new FileInputStream(file);
+        File file2 = File.createTempFile("largeClassOut", ".jar");
+        JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
+        org.apache.harmony.unpack200.Archive archive = new org.apache.harmony.unpack200.Archive(in2, out2);
+        archive.unpack();
+        JarFile jarFile = new JarFile(file2);
+        file2.deleteOnExit();
+
+        File compareFile = new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/largeClassUnpacked.jar").toURI());
+        JarFile jarFile2 = new JarFile(compareFile);
+
+        assertEquals(jarFile2.size(), jarFile.size());
+
+        compareFiles(jarFile, jarFile2);
+    }
+
     public void testJNDI() throws IOException, Pack200Exception, URISyntaxException {
-        in = new JarInputStream(Archive.class
-                .getResourceAsStream("/org/apache/harmony/pack200/tests/jndi.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/jndi.jar").toURI()));
         file = File.createTempFile("jndi", ".pack");
         out = new FileOutputStream(file);
         new Archive(in, out, false).pack();
@@ -144,11 +170,10 @@
         compareFiles(jarFile, jarFile2);
     }
 
-    public void testSegmentLimits() throws IOException, Pack200Exception {
-
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+    public void testSegmentLimits() throws IOException, Pack200Exception,
+            URISyntaxException {
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
         file = File.createTempFile("helloworld", ".pack.gz");
         out = new FileOutputStream(file);
         Archive archive = new Archive(in, out, true);
@@ -157,9 +182,8 @@
         in.close();
         out.close();
 
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
         file = File.createTempFile("helloworld", ".pack.gz");
         out = new FileOutputStream(file);
         archive = new Archive(in, out, true);
@@ -168,9 +192,8 @@
         in.close();
         out.close();
 
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/hw.jar").toURI()));
         file = File.createTempFile("helloworld", ".pack.gz");
         out = new FileOutputStream(file);
         archive = new Archive(in, out, true);
@@ -181,8 +204,8 @@
     }
 
     public void testStripDebug() throws IOException, Pack200Exception, URISyntaxException {
-        in = new JarInputStream(Archive.class
-                .getResourceAsStream("/org/apache/harmony/pack200/tests/sqlUnpacked.jar"));
+        in = new JarFile(new File(Archive.class
+                .getResource("/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
         file = File.createTempFile("sql", ".pack");
         out = new FileOutputStream(file);
         Archive archive = new Archive(in, out, false);
@@ -211,9 +234,9 @@
 
     public void testAnnotations() throws IOException, Pack200Exception,
             URISyntaxException {
-        in = new JarInputStream(
-                Archive.class
-                        .getResourceAsStream("/org/apache/harmony/pack200/tests/annotationsUnpacked.jar"));
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/annotationsUnpacked.jar")
+                .toURI()));
         file = File.createTempFile("annotations", ".pack");
         out = new FileOutputStream(file);
         new Archive(in, out, false).pack();
@@ -235,6 +258,56 @@
         compareFiles(jarFile, jarFile2);
     }
 
+    public void testE0() throws Pack200Exception, IOException, URISyntaxException {
+        File f1 = new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/jndi.jar").toURI());
+        in = new JarFile(f1);
+        file = File.createTempFile("jndiE0", ".pack");
+        out = new FileOutputStream(file);
+        Archive archive = new Archive(in, out, false);
+        archive.setEffort(0);
+        archive.pack();
+        in.close();
+        out.close();
+        compareFiles(new JarFile(f1), new JarFile(file));
+
+    }
+
+//    public void testE0again() throws IOException, Pack200Exception, URISyntaxException {
+//        JarInputStream inputStream = new JarInputStream(Archive.class.getResourceAsStream("/org/apache/harmony/pack200/tests/jndi.jar"));
+//        file = File.createTempFile("jndiE0", ".pack");
+//        out = new FileOutputStream(file);
+//        Archive archive = new Archive(inputStream, out, false);
+//        archive.setEffort(0);
+//        archive.pack();
+//        inputStream.close();
+//        out.close();
+//        in = new JarFile(new File(Archive.class.getResource(
+//                "/org/apache/harmony/pack200/tests/jndi.jar").toURI()));
+//        compareFiles(in, new JarFile(file));
+//    }
+
+    public void testMultipleJars() throws URISyntaxException, IOException, Pack200Exception {
+    	File folder = new File(Archive.class
+    			.getResource("/org/apache/harmony/pack200/tests/jars").toURI());
+    	String[] children = folder.list();
+    	for (int i = 0; i < children.length; i++) {
+			if(children[i].endsWith(".jar") && !children[i].endsWith("Unpacked.jar")) {
+				File inputFile = new File(folder, children[i]);
+				in = new JarFile(inputFile);
+				file = File.createTempFile("temp", ".pack.gz");
+		        out = new FileOutputStream(file);
+//		        System.out.println("packing " + children[i]);
+		        new Archive(in, out, true).pack();
+		        in.close();
+		        out.close();
+
+		        // unpack and compare
+
+			}
+		}
+    }
+
     private void compareFiles(JarFile jarFile, JarFile jarFile2)
             throws IOException {
         Enumeration entries = jarFile.entries();
@@ -245,20 +318,25 @@
 
             String name = entry.getName();
             JarEntry entry2 = jarFile2.getJarEntry(name);
-            assertNotNull(entry2);
-            if(!name.equals("META-INF/MANIFEST.MF")) { // Manifests aren't necessarily byte-for-byte identical
+            assertNotNull("Missing Entry: " + name, entry2);
+            if (!name.equals("META-INF/MANIFEST.MF")) { // Manifests aren't
+                                                        // necessarily
+                                                        // byte-for-byte
+                                                        // identical
 
                 InputStream ours = jarFile.getInputStream(entry);
                 InputStream expected = jarFile2.getInputStream(entry2);
 
-                BufferedReader reader1 = new BufferedReader(new InputStreamReader(ours));
-                BufferedReader reader2 = new BufferedReader(new InputStreamReader(
-                        expected));
+                BufferedReader reader1 = new BufferedReader(
+                        new InputStreamReader(ours));
+                BufferedReader reader2 = new BufferedReader(
+                        new InputStreamReader(expected));
                 String line1 = reader1.readLine();
                 String line2 = reader2.readLine();
                 int i = 1;
                 while (line1 != null || line2 != null) {
-                    assertEquals("Unpacked files differ for " + name, line2, line1);
+                    assertEquals("Unpacked files differ for " + name, line2,
+                            line1);
                     line1 = reader1.readLine();
                     line2 = reader2.readLine();
                     i++;
@@ -267,6 +345,8 @@
                 reader2.close();
             }
         }
+        jarFile.close();
+        jarFile2.close();
     }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java Sun Apr 19 11:15:28 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;
 
@@ -27,9 +28,11 @@
 import org.apache.harmony.pack200.Codec;
 import org.apache.harmony.pack200.CodecEncoding;
 import org.apache.harmony.pack200.Pack200Exception;
+import org.apache.harmony.pack200.PopulationCodec;
+import org.apache.harmony.pack200.RunCodec;
 
 /**
- * 
+ *
  */
 public class CodecEncodingTest extends TestCase {
 
@@ -172,4 +175,137 @@
                 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), null)[0]);
+        }
+
+        // Test a range of non-canonical codecs
+        Codec c1 = new BHSDCodec(2, 125, 0, 1);
+        int[] specifiers = CodecEncoding.getSpecifier(c1, null);
+        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, null);
+        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, null);
+        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, null);
+        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, null);
+        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));
+    }
+
+    public void testGetSpeciferForRunCodec() throws Pack200Exception, IOException {
+        RunCodec runCodec = new RunCodec(25, Codec.DELTA5, Codec.BYTE1);
+        int[] specifiers = CodecEncoding.getSpecifier(runCodec, null);
+        assertTrue(specifiers[0] > 116);
+        assertTrue(specifiers[0] < 141);
+        byte[] bytes = new byte[specifiers.length - 1];
+        for (int i = 0; i < bytes.length; i++) {
+            bytes[i] = (byte) specifiers[i+1];
+        }
+        InputStream in = new ByteArrayInputStream(bytes);
+        RunCodec runCodec2 = (RunCodec) CodecEncoding.getCodec(specifiers[0], in, null);
+        assertEquals(runCodec.getK(), runCodec2.getK());
+        assertEquals(runCodec.getACodec(), runCodec2.getACodec());
+        assertEquals(runCodec.getBCodec(), runCodec2.getBCodec());
+
+        // One codec is the same as the default
+        runCodec = new RunCodec(4096, Codec.DELTA5, Codec.BYTE1);
+        specifiers = CodecEncoding.getSpecifier(runCodec, Codec.DELTA5);
+        assertTrue(specifiers[0] > 116);
+        assertTrue(specifiers[0] < 141);
+        bytes = new byte[specifiers.length - 1];
+        for (int i = 0; i < bytes.length; i++) {
+            bytes[i] = (byte) specifiers[i+1];
+        }
+        in = new ByteArrayInputStream(bytes);
+        runCodec2 = (RunCodec) CodecEncoding.getCodec(specifiers[0], in, Codec.DELTA5);
+        assertEquals(runCodec.getK(), runCodec2.getK());
+        assertEquals(runCodec.getACodec(), runCodec2.getACodec());
+        assertEquals(runCodec.getBCodec(), runCodec2.getBCodec());
+
+        // Nested run codecs
+        runCodec = new RunCodec(64, Codec.SIGNED5, new RunCodec(25, Codec.UDELTA5, Codec.DELTA5));
+        specifiers = CodecEncoding.getSpecifier(runCodec, null);
+        assertTrue(specifiers[0] > 116);
+        assertTrue(specifiers[0] < 141);
+        bytes = new byte[specifiers.length - 1];
+        for (int i = 0; i < bytes.length; i++) {
+            bytes[i] = (byte) specifiers[i+1];
+        }
+        in = new ByteArrayInputStream(bytes);
+        runCodec2 = (RunCodec) CodecEncoding.getCodec(specifiers[0], in, null);
+        assertEquals(runCodec.getK(), runCodec2.getK());
+        assertEquals(runCodec.getACodec(), runCodec2.getACodec());
+        RunCodec bCodec = (RunCodec) runCodec.getBCodec();
+        RunCodec bCodec2 = (RunCodec) runCodec2.getBCodec();
+        assertEquals(bCodec.getK(), bCodec2.getK());
+        assertEquals(bCodec.getACodec(), bCodec2.getACodec());
+        assertEquals(bCodec.getBCodec(), bCodec2.getBCodec());
+
+        // Nested with one the same as the default
+        runCodec = new RunCodec(64, Codec.SIGNED5, new RunCodec(25, Codec.UDELTA5, Codec.DELTA5));
+        specifiers = CodecEncoding.getSpecifier(runCodec, Codec.UDELTA5);
+        assertTrue(specifiers[0] > 116);
+        assertTrue(specifiers[0] < 141);
+        bytes = new byte[specifiers.length - 1];
+        for (int i = 0; i < bytes.length; i++) {
+            bytes[i] = (byte) specifiers[i+1];
+        }
+        in = new ByteArrayInputStream(bytes);
+        runCodec2 = (RunCodec) CodecEncoding.getCodec(specifiers[0], in, Codec.UDELTA5);
+        assertEquals(runCodec.getK(), runCodec2.getK());
+        assertEquals(runCodec.getACodec(), runCodec2.getACodec());
+        bCodec = (RunCodec) runCodec.getBCodec();
+        bCodec2 = (RunCodec) runCodec2.getBCodec();
+        assertEquals(bCodec.getK(), bCodec2.getK());
+        assertEquals(bCodec.getACodec(), bCodec2.getACodec());
+        assertEquals(bCodec.getBCodec(), bCodec2.getBCodec());
+    }
+
+    public void testGetSpeciferForPopulationCodec() throws IOException, Pack200Exception {
+        PopulationCodec pCodec = new PopulationCodec(Codec.BYTE1, Codec.CHAR3, Codec.UNSIGNED5);
+        int[] specifiers = CodecEncoding.getSpecifier(pCodec, null);
+        assertTrue(specifiers[0] > 140);
+        assertTrue(specifiers[0] < 189);
+        byte[] bytes = new byte[specifiers.length - 1];
+        for (int i = 0; i < bytes.length; i++) {
+            bytes[i] = (byte) specifiers[i+1];
+        }
+        InputStream in = new ByteArrayInputStream(bytes);
+        PopulationCodec pCodec2 = (PopulationCodec) CodecEncoding.getCodec(specifiers[0], in, null);
+        assertEquals(pCodec.getFavouredCodec(), pCodec2.getFavouredCodec());
+        assertEquals(pCodec.getTokenCodec(), pCodec2.getTokenCodec());
+        assertEquals(pCodec.getUnfavouredCodec(), pCodec2.getUnfavouredCodec());
+    }
+
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/test/native/hyfile/shared/hyfile.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/test/native/hyfile/shared/hyfile.c?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/portlib/src/test/native/hyfile/shared/hyfile.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/test/native/hyfile/shared/hyfile.c Sun Apr 19 11:15:28 2009
@@ -518,7 +518,6 @@
   }
   
   offset = hyportLibrary->file_seek(hyportLibrary, fd, -193, HySeekEnd);
-  printf("  offset = %d\n", offset);
   if (offset != 7) {
     Hytest_setErrMsg(hyportLibrary, "Output should be [%d] not [%d] (%s)\n",7,offset,HY_GET_CALLSITE());
     hyportLibrary->file_close(hyportLibrary, fd);
@@ -676,7 +675,6 @@
   }
   
   length = hyportLibrary->file_length(hyportLibrary, tmpAbsolutePath);
-  printf("  length = %d\n", length);
   if (length != 200) {
     Hytest_setErrMsg(hyportLibrary, "Output should be [%d] not [%d] (%s)\n",200,length,HY_GET_CALLSITE());
     cleanup(*hyportLibrary);
@@ -922,7 +920,6 @@
   }
   
   time = hyportLibrary->file_lastmod (hyportLibrary, tmpAbsolutePath);  
-  printf("  last modify time = %I64d\n", time);
   if (time == -1) {
     Hytest_setErrMsg(hyportLibrary, "fail to get last modify time(%s)\n",HY_GET_CALLSITE());
     cleanup(*hyportLibrary);

Modified: harmony/enhanced/classlib/branches/java6/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java Sun Apr 19 11:15:28 2009
@@ -79,11 +79,13 @@
                 Preferences sroot = Preferences.systemRoot();
                 try {
                     uroot.flush();
-                } catch (BackingStoreException e) {//ignore
+                } catch (BackingStoreException e) {
+                    // ignore
                 }
                 try {
                     sroot.flush();
-                } catch (BackingStoreException e) {//ignore
+                } catch (BackingStoreException e) {
+                    // ignore
                 }
             }
         });
@@ -402,13 +404,13 @@
         if (key == null) {
             throw new NullPointerException();
         }
-        String result;
+        String result = null;
         synchronized (lock) {
             checkState();
             try {
                 result = getSpi(key);
             } catch (Exception e) {
-                result = null;
+                // ignored
             }
         }
         return (result == null ? deflt : result);
@@ -419,9 +421,10 @@
         String result = get(key, null);
         if (result == null) {
             return deflt;
-        } else if (result.equalsIgnoreCase("true")) { //$NON-NLS-1$
+        }
+        if ("true".equalsIgnoreCase(result)) { //$NON-NLS-1$
             return true;
-        } else if (result.equalsIgnoreCase("false")) { //$NON-NLS-1$
+        } else if ("false".equalsIgnoreCase(result)) { //$NON-NLS-1$
             return false;
         } else {
             return deflt;
@@ -437,17 +440,15 @@
         if (svalue.length() == 0) { 
             return new byte[0];
         }
-        byte[] dres;
         try {
             byte[] bavalue = svalue.getBytes("US-ASCII"); //$NON-NLS-1$
             if (bavalue.length % 4 != 0) {
                 return deflt;
             }
-            dres = Base64.decode(bavalue);
+            return Base64.decode(bavalue);
         } catch (Exception e) {
-            dres = deflt;
+            return deflt;
         }
-        return dres;
     }
 
     @Override
@@ -456,13 +457,11 @@
         if (result == null) {
             return deflt;
         }
-        double dres;
         try {
-            dres = Double.parseDouble(result);
+            return Double.parseDouble(result);
         } catch (NumberFormatException e) {
-            dres = deflt;
+            return deflt;
         }
-        return dres;
     }
 
     @Override
@@ -471,13 +470,11 @@
         if (result == null) {
             return deflt;
         }
-        float fres;
         try {
-            fres = Float.parseFloat(result);
+            return Float.parseFloat(result);
         } catch (NumberFormatException e) {
-            fres = deflt;
+            return deflt;
         }
-        return fres;
     }
 
     @Override
@@ -486,13 +483,11 @@
         if (result == null) {
             return deflt;
         }
-        int ires;
         try {
-            ires = Integer.parseInt(result);
+            return Integer.parseInt(result);
         } catch (NumberFormatException e) {
-            ires = deflt;
+            return deflt;
         }
-        return ires;
     }
 
     @Override
@@ -501,13 +496,11 @@
         if (result == null) {
             return deflt;
         }
-        long lres;
         try {
-            lres = Long.parseLong(result);
+            return Long.parseLong(result);
         } catch (NumberFormatException e) {
-            lres = deflt;
+            return deflt;
         }
-        return lres;
     }
 
     @Override
@@ -546,24 +539,22 @@
                 startNode = this;
             }
         }
-        Preferences result = null;
         try {
-            result = startNode.nodeImpl(name, true);
+            return startNode.nodeImpl(name, true);
         } catch (BackingStoreException e) {
-            //should not happen
+            // should not happen
+            return null;
         }
-        return result;
     }
 
     private void validateName(String name) {
         if (name.endsWith("/") && name.length() > 1) { //$NON-NLS-1$
             // prefs.6=Name cannot end with '/'\!
-            throw new IllegalArgumentException(Messages.getString("prefs.6"));  //$NON-NLS-1$
+            throw new IllegalArgumentException(Messages.getString("prefs.6")); //$NON-NLS-1$
         }
         if (name.indexOf("//") >= 0) { //$NON-NLS-1$
             // prefs.7=Name cannot contains consecutive '/'\!
-            throw new IllegalArgumentException(
-                    Messages.getString("prefs.7"));  //$NON-NLS-1$
+            throw new IllegalArgumentException(Messages.getString("prefs.7")); //$NON-NLS-1$
         }
     }
 
@@ -580,7 +571,6 @@
                     temp = getNodeFromBackend(createNew, currentNode, name);
                 }
             }
-
             currentNode = temp;
         }
         return currentNode;
@@ -589,12 +579,12 @@
     private AbstractPreferences getNodeFromBackend(boolean createNew,
             AbstractPreferences currentNode, String name)
             throws BackingStoreException {
-        AbstractPreferences temp;
         if (name.length() > MAX_NAME_LENGTH) {
             // prefs.8=Name length is too long: {0}
-            throw new IllegalArgumentException(Messages.getString("prefs.8",  //$NON-NLS-1$
+            throw new IllegalArgumentException(Messages.getString("prefs.8", //$NON-NLS-1$
                     name));
         }
+        AbstractPreferences temp;
         if (createNew) {
             temp = currentNode.childSpi(name);
             currentNode.cachedNode.put(name, temp);
@@ -609,6 +599,9 @@
 
     @Override
     public boolean nodeExists(String name) throws BackingStoreException {
+        if (null == name) {
+            throw new NullPointerException();
+        }
         AbstractPreferences startNode = null;
         synchronized (lock) {
             if (isRemoved()) {

Modified: harmony/enhanced/classlib/branches/java6/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java?rev=766448&r1=766447&r2=766448&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java Sun Apr 19 11:15:28 2009
@@ -64,7 +64,6 @@
                 SYSTEM_HOME = System.getProperty("java.home") + "/.systemPrefs";//$NON-NLS-1$//$NON-NLS-2$
                 return null;
             }
-
         });
     }
 
@@ -192,7 +191,8 @@
                 prefs = XMLParser.loadFilePrefs(prefsFile);
             }
             return prefs.getProperty(key);
-        } catch (Exception e) {// if Exception happened, return null
+        } catch (Exception e) {
+            // if Exception happened, return null
             return null;
         }
     }



Mime
View raw message