Create tag based on trunk@r885602

git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/classlib/tags/latest-java6-merge@889201 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/make/build-test.xml b/make/build-test.xml
index eaeea57..f926d3f 100644
--- a/make/build-test.xml
+++ b/make/build-test.xml
@@ -27,20 +27,6 @@
     <property name="tests.output" location="build/test_report" />
     <import file="${basedir}/make/properties.xml" />
 
-    <property name="gen.report" value="true" />
-    <condition property="do.full.report" value="true">
-        <and>
-            <equals arg1="${gen.report}" arg2="true" />
-            <not><equals arg1="${short.report}" arg2="true" /></not>
-        </and>
-    </condition>
-    <condition property="do.short.report" value="true">
-        <and>
-            <equals arg1="${gen.report}" arg2="true" />
-            <equals arg1="${short.report}" arg2="true" />
-        </and>
-    </condition>
-
     <property name="tests.support.output" location="build/test_support" />
     <property name="support.dir" location="support"/>
     <property name="tests.depends.jars" location="deploy/jdk/jre/lib/boot" />
@@ -85,7 +71,7 @@
 
     <property name="report.dir" value="${tests.output}/html"/>
 
-    <target name="full-report" if="do.full.report" >
+    <target name="full-report" unless="short.report" >
         <delete dir="${report.dir}" />
         <junitreport todir="${tests.output}">
             <fileset dir="${tests.output}">
@@ -99,7 +85,7 @@
         <echo message="The test report is in ${display-location}"/>
     </target>
 
-    <target name="short-report" if="do.short.report">
+    <target name="short-report" if="short.report" >
         <delete dir="${report.dir}" />
         <junitreport todir="${tests.output}">
             <fileset dir="${tests.output}" includes="TEST*-*.xml">
diff --git a/modules/archive/src/main/java/java/util/jar/JarFile.java b/modules/archive/src/main/java/java/util/jar/JarFile.java
index bebc82e..0fabd60 100644
--- a/modules/archive/src/main/java/java/util/jar/JarFile.java
+++ b/modules/archive/src/main/java/java/util/jar/JarFile.java
@@ -17,19 +17,19 @@
 
 package java.util.jar;
 
+import java.io.ByteArrayOutputStream;
+import java.util.List;
+import java.util.ArrayList;
 import java.io.File;
 import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
 import org.apache.harmony.archive.internal.nls.Messages;
 import org.apache.harmony.archive.util.Util;
-import org.apache.harmony.luni.util.InputStreamHelper;
 
 /**
  * {@code JarFile} is used to read jar entries and their associated data from
@@ -282,6 +282,42 @@
         return (JarEntry) getEntry(name);
     }
 
+    /*
+     * Drains the entire content from the given input stream and returns it as a
+     * byte[]. The stream is closed after being drained, or if an IOException
+     * occurs.
+     */
+    private byte[] getAllBytesFromStreamAndClose(InputStream is)
+            throws IOException {
+        try {
+            // Initial read
+            byte[] buffer = new byte[1024];
+            int count = is.read(buffer);
+            int nextByte = is.read();
+
+            // Did we get it all in one read?
+            if (nextByte == -1) {
+                byte[] dest = new byte[count];
+                System.arraycopy(buffer, 0, dest, 0, count);
+                return dest;
+            }
+
+            // Requires additional reads
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
+            baos.write(buffer, 0, count);
+            baos.write(nextByte);
+            while (true) {
+                count = is.read(buffer);
+                if (count == -1) {
+                    return baos.toByteArray();
+                }
+                baos.write(buffer, 0, count);
+            }
+        } finally {
+            is.close();
+        }
+    }
+
     /**
      * Returns the {@code Manifest} object associated with this {@code JarFile}
      * or {@code null} if no MANIFEST entry exists.
@@ -304,8 +340,7 @@
         try {
             InputStream is = super.getInputStream(manifestEntry);
             if (verifier != null) {
-                verifier.addMetaEntry(manifestEntry.getName(),
-                        InputStreamHelper.readFullyAndClose(is));
+                verifier.addMetaEntry(manifestEntry.getName(), getAllBytesFromStreamAndClose(is));
                 is = super.getInputStream(manifestEntry);
             }
             try {
@@ -357,7 +392,7 @@
                                 || Util.asciiEndsWithIgnoreCase(entryName, ".RSA"))) {
                     signed = true;
                     InputStream is = super.getInputStream(entry);
-                    byte[] buf = InputStreamHelper.readFullyAndClose(is);
+                    byte[] buf = getAllBytesFromStreamAndClose(is);
                     verifier.addMetaEntry(entryName, buf);
                 }
             }
diff --git a/modules/archive/src/main/java/java/util/jar/Manifest.java b/modules/archive/src/main/java/java/util/jar/Manifest.java
index 48dc8c8..7f6437d 100644
--- a/modules/archive/src/main/java/java/util/jar/Manifest.java
+++ b/modules/archive/src/main/java/java/util/jar/Manifest.java
@@ -30,7 +30,7 @@
 import java.util.Map;
 
 import org.apache.harmony.archive.internal.nls.Messages;
-import org.apache.harmony.luni.util.InputStreamHelper;
+import org.apache.harmony.luni.util.InputStreamExposer;
 import org.apache.harmony.luni.util.ThreadLocalCache;
 
 /**
@@ -209,7 +209,7 @@
         byte[] buf;
         // Try to read get a reference to the bytes directly
         try {
-            buf = InputStreamHelper.expose(is);
+            buf = InputStreamExposer.expose(is);
         } catch (UnsupportedOperationException uoe) {
             buf = readFully(is);
         }
diff --git a/modules/archive/src/main/java/java/util/zip/ZipFile.java b/modules/archive/src/main/java/java/util/zip/ZipFile.java
index 48541e1..7a412fd 100644
--- a/modules/archive/src/main/java/java/util/zip/ZipFile.java
+++ b/modules/archive/src/main/java/java/util/zip/ZipFile.java
@@ -368,6 +368,7 @@
         RandomAccessFile mSharedRaf;
         long mOffset;
         long mLength;
+        private byte[] singleByteBuf = new byte[1];
 
         public RAFStream(RandomAccessFile raf, long pos) throws IOException {
             mSharedRaf = raf;
@@ -382,7 +383,6 @@
 
         @Override
         public int read() throws IOException {
-            byte[] singleByteBuf = new byte[1];
             if (read(singleByteBuf, 0, 1) == 1) {
                 return singleByteBuf[0] & 0XFF;
             } else {
diff --git a/modules/instrument/src/main/native/instrument/shared/inst_agt.c b/modules/instrument/src/main/native/instrument/shared/inst_agt.c
index 11f1b9e..97966a6 100644
--- a/modules/instrument/src/main/native/instrument/shared/inst_agt.c
+++ b/modules/instrument/src/main/native/instrument/shared/inst_agt.c
@@ -206,7 +206,7 @@
 
     /* read bytes */
     size = zipEntry.uncompressedSize;
-    result = (char *)hymem_allocate_memory(size*sizeof(char) + 1);
+    result = (char *)hymem_allocate_memory(size*sizeof(char));
 #ifndef HY_ZIP_API
     retval = zip_getZipEntryData(privatePortLibrary, &zipFile, &zipEntry, (unsigned char*)result, size);
 #else /* HY_ZIP_API */
@@ -223,7 +223,6 @@
         return NULL;
     }
 
-    result[size] = '\0';
     /* free resource */
 #ifndef HY_ZIP_API
     zip_freeZipEntry(privatePortLibrary, &zipEntry);
@@ -244,7 +243,6 @@
     char *pos;
     char *end;
     char *value;
-    char *tmp;
     int length;
     PORT_ACCESS_FROM_JAVAVM(vm);
 
@@ -255,46 +253,18 @@
     pos = manifest+ (strstr(lwrmanifest,target) - lwrmanifest);
     pos += strlen(target)+2;//": "
     end = strchr(pos, '\n');
-
-    while (end != NULL && *(end + 1) == ' ') {
-        end = strchr(end + 1, '\n');
-    }
-
     if(NULL == end){
         end = manifest + strlen(manifest);
     }
-
+    /* in windows, has '\r\n' in the end of line, omit '\r' */
+    if (*(end - 1) == '\r'){
+        end--;
+    }
     length = end - pos;
 
     value = (char *)hymem_allocate_memory(sizeof(char)*(length+1));
-    tmp = value;
-
-    end = strchr(pos, '\n');
-    while (end != NULL && *(end + 1) == ' ') {
-        /* in windows, has '\r\n' in the end of line, omit '\r' */
-        if (*(end - 1) == '\r') {
-            strncpy(tmp, pos, end - 1 - pos);
-            tmp += end - 1 - pos;
-            pos = end + 2;
-        } else {
-            strncpy(tmp, pos, end - pos);
-            tmp += end - pos;
-            pos = end + 2;
-        }
-        end = strchr(end + 1, '\n');
-    }
-
-    if (NULL == end) {
-        strcpy(tmp, pos);
-    } else {
-        /* in windows, has '\r\n' in the end of line, omit '\r' */
-        if (*(end - 1) == '\r') {
-            end--;
-        }
-        strncpy(tmp, pos, end - pos);
-        *(tmp + (end - pos)) = '\0';
-    }
-
+    strncpy(value, pos, length);
+    *(value+length) = '\0';
     return value;
 }
 
@@ -346,11 +316,7 @@
     check_jvmti_error(env, (*jvmti)->GetSystemProperty(jvmti,"java.class.path",&classpath),"Failed to get classpath.");
     classpath_cpy = (char *)hymem_allocate_memory((sizeof(char)*(strlen(classpath)+strlen(jar_name)+2)));
     strcpy(classpath_cpy,classpath);
-#if defined(WIN32) || defined(WIN64)
     strcat(classpath_cpy,";");
-#else
-    strcat(classpath_cpy,":");
-#endif
     strcat(classpath_cpy,jar_name);
     check_jvmti_error(env, (*jvmti)->SetSystemProperty(jvmti, "java.class.path",classpath_cpy),"Failed to set classpath.");
     hymem_free_memory(classpath_cpy);
@@ -373,9 +339,9 @@
     str_support_redefine = read_attribute(vm, manifest, lwrmanifest,"can-redefine-classes");
     if(NULL != str_support_redefine){
         support_redefine = str2bol(str_support_redefine);
+        gsupport_redefine |= support_redefine;
         hymem_free_memory(str_support_redefine);
     }
-    gsupport_redefine &= support_redefine;
 
     //add bootclasspath
 
@@ -396,10 +362,6 @@
 JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved){
     PORT_ACCESS_FROM_JAVAVM(vm);
     VMI_ACCESS_FROM_JAVAVM(vm);
-    jvmtiError jvmti_err;
-    JNIEnv *env = NULL;
-    static jvmtiEnv *jvmti;
-    jvmtiCapabilities updatecapabilities;
     jint err = (*vm)->GetEnv(vm, (void **)&jnienv, JNI_VERSION_1_2);
     if(JNI_OK != err){
         return err;
@@ -409,6 +371,8 @@
         jvmtiCapabilities capabilities;
         jvmtiError jvmti_err;
         jvmtiEventCallbacks callbacks;
+        JNIEnv *env = NULL;
+        static jvmtiEnv *jvmti;
 
         gdata = hymem_allocate_memory(sizeof(AgentData));
 
@@ -419,10 +383,15 @@
         }
         gdata->jvmti = jvmti;
 
-        //get JVMTI potential capabilities
-        jvmti_err = (*jvmti)->GetPotentialCapabilities(jvmti, &capabilities);
-        check_jvmti_error(env, jvmti_err, "Cannot get JVMTI potential capabilities.");
-        gsupport_redefine = (capabilities.can_redefine_classes == 1);
+        //set prerequisite capabilities for classfileloadhook, redefine, and VMInit event
+        memset(&capabilities, 0, sizeof(capabilities));
+        capabilities.can_generate_all_class_hook_events=1;
+        capabilities.can_redefine_classes = 1;
+        //FIXME VM doesnot support the capbility right now.
+        //capabilities.can_redefine_any_class = 1;
+        jvmti_err = (*jvmti)->AddCapabilities(jvmti, &capabilities);
+        check_jvmti_error(env, jvmti_err,
+                          "Cannot add JVMTI capabilities.");
 
         //set events callback function
         (void)memset(&callbacks, 0, sizeof(callbacks));
@@ -436,18 +405,7 @@
         check_jvmti_error(env, jvmti_err, "Cannot set JVMTI VMInit event notification mode.");
     }
 
-    err = Parse_Options(vm,jnienv, gdata->jvmti,options);
-
-    //update capabilities JVMTI
-    memset(&updatecapabilities, 0, sizeof(updatecapabilities));
-    updatecapabilities.can_generate_all_class_hook_events = 1;
-    updatecapabilities.can_redefine_classes = gsupport_redefine;
-    //FIXME VM doesnot support the capbility right now.
-    //capabilities.can_redefine_any_class = 1;
-    jvmti_err = (*jvmti)->AddCapabilities(jvmti, &updatecapabilities);
-    check_jvmti_error(env, jvmti_err, "Cannot add JVMTI capabilities.");
-
-    return err;
+    return Parse_Options(vm,jnienv, gdata->jvmti,options);
 }
 
 JNIEXPORT void JNICALL Agent_OnUnload(JavaVM *vm){
diff --git a/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/HelloWorldTest.java b/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/HelloWorldTest.java
deleted file mode 100644
index 13dde0b..0000000
--- a/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/HelloWorldTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.tests.java.lang.instrument;
-
-import static org.apache.harmony.tests.java.lang.instrument.InstrumentTestHelper.LINE_SEPARATOR;
-import static org.apache.harmony.tests.java.lang.instrument.InstrumentTestHelper.PREMAIN_CLASS;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.tests.java.lang.instrument.agents.HelloWorldAgent;
-
-public class HelloWorldTest extends TestCase {
-    private InstrumentTestHelper helper = null;
-
-    private static String JAR_PREFIX = "HelloWorldTest";
-
-    @Override
-    public void setUp() {
-        helper = new InstrumentTestHelper();
-    }
-
-    @Override
-    public void tearDown() {
-        helper.clean();
-    }
-
-    public void testHelloWorld() throws Exception {
-        helper.addManifestAttributes(PREMAIN_CLASS, HelloWorldAgent.class
-                .getName());
-        helper.setJarName(JAR_PREFIX + ".testHelloWorld.jar");
-        helper.setMainClass(TestMain.class);
-        List<Class> classes = new ArrayList<Class>();
-        classes.add(HelloWorldAgent.class);
-        helper.addClasses(classes);
-
-        helper.run();
-
-        assertEquals(0, helper.getExitCode());
-        assertEquals("Hello World" + LINE_SEPARATOR, helper.getStdOut());
-        assertEquals("", helper.getStdErr());
-    }
-
-    public void testMultiLineValue() throws Exception {
-        StringBuilder name = new StringBuilder(HelloWorldAgent.class.getName());
-        // line separator + one whitespace is allowed
-        name.insert(5, "\n ");
-        helper.addManifestAttributes(PREMAIN_CLASS, name.toString());
-
-        helper.setJarName(JAR_PREFIX + ".testMultiLineValue.jar");
-        helper.setMainClass(TestMain.class);
-        List<Class> classes = new ArrayList<Class>();
-        classes.add(HelloWorldAgent.class);
-        helper.addClasses(classes);
-
-        helper.run();
-
-        assertEquals(0, helper.getExitCode());
-        assertEquals("Hello World" + LINE_SEPARATOR, helper.getStdOut());
-        assertEquals("", helper.getStdErr());
-    }
-
-    public void testInvalidMultiLineValue() throws Exception {
-        StringBuilder name = new StringBuilder(HelloWorldAgent.class.getName());
-        // line separator + two whitespaces is not allowed
-        name.insert(5, "\n  ");
-        helper.addManifestAttributes("Premain-Class", name.toString());
-
-        helper.setJarName(JAR_PREFIX + ".testInvalidMultiLineValue.jar");
-        helper.setMainClass(TestMain.class);
-        List<Class> classes = new ArrayList<Class>();
-        classes.add(HelloWorldAgent.class);
-        helper.addClasses(classes);
-
-        helper.run();
-
-        assertTrue(0 != helper.getExitCode());
-        assertTrue(helper.getStdErr().contains(
-                ClassNotFoundException.class.getName()));
-    }
-}
diff --git a/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/InstrumentTestHelper.java b/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/InstrumentTestHelper.java
deleted file mode 100644
index 8e50c4f..0000000
--- a/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/InstrumentTestHelper.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.tests.java.lang.instrument;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-import java.util.jar.JarFile;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-
-public class InstrumentTestHelper {
-    private Manifest manifest;
-
-    private List<Class> classes = new ArrayList<Class>();
-
-    private String jarName;
-
-    private Class mainClass;
-
-    private String commandAgent;
-
-    private String commandAgentOptions;
-
-    private List<String> classpath = new ArrayList<String>();
-
-    private StringBuilder stdOut = new StringBuilder();
-
-    private StringBuilder stdErr = new StringBuilder();
-
-    private int exitCode;
-
-    private String mainJarName;
-
-    private List<File> toBeCleaned = new ArrayList<File>();
-
-    public static final String PREMAIN_CLASS = "Premain-Class";
-
-    public static final String AGENT_CLASS = "Agent-Class";
-
-    public static final String BOOT_CLASS_PATH = "Boot-Class-Path";
-
-    public static final String CAN_REDEFINE_CLASSES = "Can-Redefine-Classes";
-
-    public static final String CAN_RETRANSFORM_CLASSES = "Can-Retransform-Classes";
-
-    public static final String CAN_SET_NATIVE_METHOD_PREFIX = "Can-Set-Native-Method-Prefix";
-
-    public static final String LINE_SEPARATOR = System
-            .getProperty("line.separator");
-
-    /*
-     * This variable is just for debugging. set to false, generated jar won't be
-     * deleted after testing, so you can verify if the jar was generated as you
-     * expected.
-     */
-    private boolean isDeleteJarOnExit = true;
-
-    public void clean() {
-        for (File file : toBeCleaned) {
-            file.delete();
-        }
-    }
-
-    public InstrumentTestHelper() {
-        manifest = new Manifest();
-        manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
-    }
-
-    public void addClasses(List<Class> added) {
-        classes.addAll(added);
-    }
-
-    public void addManifestAttributes(String key, String value) {
-        manifest.getMainAttributes().putValue(key, value);
-    }
-
-    public String getCommandAgent() {
-        return commandAgent;
-    }
-
-    public void setCommandAgent(String commandAgent) {
-        this.commandAgent = commandAgent;
-    }
-
-    public String getCommandAgentOptions() {
-        return commandAgentOptions;
-    }
-
-    public void setCommandAgentOptions(String commandAgentOptions) {
-        this.commandAgentOptions = commandAgentOptions;
-    }
-
-    public String getJarName() {
-        return jarName;
-    }
-
-    public void setJarName(String jarName) {
-        if (jarName.endsWith(".jar")) {
-            this.jarName = jarName;
-            mainJarName = jarName.substring(0, jarName.length() - 4)
-                    + ".main.jar";
-        } else {
-            this.jarName = jarName + ".jar";
-            mainJarName = jarName + ".main.jar";
-        }
-    }
-
-    public Class getMainClass() {
-        return mainClass;
-    }
-
-    public void setMainClass(Class mainClass) {
-        this.mainClass = mainClass;
-    }
-
-    public void run() throws Exception {
-        generateJars();
-        runAgentTest();
-    }
-
-    private void runAgentTest() throws IOException, InterruptedException {
-        String[] args = new String[2];
-        args[0] = "-javaagent:" + commandAgent;
-        if (commandAgentOptions != null
-                && commandAgentOptions.trim().length() != 0) {
-            args[0] += "=" + commandAgentOptions;
-        }
-
-        args[1] = mainClass.getName();
-
-        Process process = execJava(args, getClasspath());
-        process.waitFor();
-
-        exitCode = process.exitValue();
-    }
-
-    private Process execJava(String[] args, String[] classpath)
-            throws IOException {
-        // this function returns the resulting process from the exec
-        StringBuilder command;
-        String testVMArgs;
-        StringTokenizer st;
-
-        List<String> execArgs = new ArrayList<String>(3 + args.length);
-
-        // construct the name of executable file
-        String executable = System.getProperty("java.home");
-        if (!executable.endsWith(File.separator)) {
-            executable += File.separator;
-        }
-        executable += "bin" + File.separator + "java";
-        execArgs.add(executable);
-
-        // add classpath string
-        StringBuilder classPathString = new StringBuilder();
-        if (classpath != null && classpath.length > 0) {
-            boolean isFirst = true;
-            for (String element : classpath) {
-                if (isFirst) {
-                    isFirst = false;
-                } else {
-                    classPathString.append(File.pathSeparator);
-                }
-                classPathString.append(element);
-            }
-        }
-
-        if (classPathString.toString().length() != 0) {
-            execArgs.add("-cp");
-            execArgs.add(classPathString.toString());
-        }
-
-        // parse hy.test.vmargs if was given
-        testVMArgs = System.getProperty("hy.test.vmargs");
-        if (testVMArgs != null) {
-            st = new StringTokenizer(testVMArgs, " ");
-            while (st.hasMoreTokens()) {
-                execArgs.add(st.nextToken());
-            }
-        }
-
-        // add custom args given as parameter
-        for (String arg : args) {
-            execArgs.add(arg);
-        }
-
-        // construct command line string and print it to stdout
-        command = new StringBuilder(execArgs.get(0));
-        for (int i = 1; i < execArgs.size(); i++) {
-            command.append(" ");
-            command.append(execArgs.get(i));
-        }
-        System.out.println("Exec: " + command.toString());
-        System.out.println();
-
-        // execute java process
-        final Process proc = Runtime.getRuntime().exec(
-                execArgs.toArray(new String[execArgs.size()]));
-
-        final String lineSeparator = System.getProperty("line.separator");
-        Thread errReader = new Thread(new Runnable() {
-            public void run() {
-                BufferedReader reader = new BufferedReader(
-                        new InputStreamReader(proc.getErrorStream()));
-                String line = null;
-                try {
-                    while ((line = reader.readLine()) != null) {
-                        stdErr.append(line).append(lineSeparator);
-                    }
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        });
-        errReader.start();
-
-        Thread outReader = new Thread(new Runnable() {
-            public void run() {
-                BufferedReader reader = new BufferedReader(
-                        new InputStreamReader(proc.getInputStream()));
-                String line = null;
-                try {
-                    while ((line = reader.readLine()) != null) {
-                        stdOut.append(line).append(lineSeparator);
-                    }
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        });
-        outReader.start();
-
-        return proc;
-    }
-
-    private void generateJars() throws FileNotFoundException, IOException,
-            URISyntaxException {
-
-        File agentJar = generateJar(jarName, manifest, classes,
-                isDeleteJarOnExit);
-        toBeCleaned.add(agentJar);
-        commandAgent = agentJar.getAbsolutePath();
-
-        List<Class> list = new ArrayList<Class>();
-        list.add(mainClass);
-
-        File mainJarFile = generateJar(mainJarName, null, list,
-                isDeleteJarOnExit);
-        toBeCleaned.add(mainJarFile);
-
-        classpath.add(mainJarFile.getAbsolutePath());
-    }
-
-    private static File calculateJarDir() throws MalformedURLException,
-            URISyntaxException {
-        URL location = ClassLoader.getSystemResource(InstrumentTestHelper.class
-                .getName().replace(".", "/")
-                + ".class");
-        String locationStr = location.toString();
-
-        // calculate jarDir
-        File jarDir = null;
-        if ("jar".equals(location.getProtocol())) {
-            URL jar = null;
-            int index = locationStr.indexOf(".jar!") + 4;
-            if (locationStr.startsWith("jar:")) {
-                jar = new URL(locationStr.substring(4, index));
-            } else {
-                jar = new URL(locationStr.substring(0, index));
-            }
-            jarDir = new File(jar.toURI()).getParentFile();
-        } else {
-            int index = locationStr.lastIndexOf(InstrumentTestHelper.class
-                    .getName().replace(".", "/"));
-            URL jar = new URL(locationStr.substring(0, index));
-            jarDir = new File(jar.toURI());
-        }
-        return jarDir;
-    }
-
-    public String getStdOut() {
-        return stdOut.toString();
-    }
-
-    public String getStdErr() {
-        return stdErr.toString();
-    }
-
-    public String[] getClasspath() {
-        return classpath.toArray(new String[0]);
-    }
-
-    public void setClasspath(String[] pathes) {
-        classpath.addAll(Arrays.asList(pathes));
-    }
-
-    public int getExitCode() {
-        return exitCode;
-    }
-
-    public boolean isDeleteJarOnExit() {
-        return isDeleteJarOnExit;
-    }
-
-    public void setDeleteJarOnExit(boolean isDeleteJarOnExit) {
-        this.isDeleteJarOnExit = isDeleteJarOnExit;
-    }
-
-    public static File generateJar(String jarName, Manifest manifest,
-            List<Class> classes, boolean isDeleteOnExit)
-            throws FileNotFoundException, IOException, URISyntaxException {
-        File jarDir = calculateJarDir();
-
-        File jarFile = new File(jarDir, jarName);
-
-        JarOutputStream out = null;
-        if (manifest == null) {
-            out = new JarOutputStream(new FileOutputStream(jarFile));
-        } else {
-            out = new JarOutputStream(new FileOutputStream(jarFile), manifest);
-        }
-
-        for (Iterator<Class> iter = classes.iterator(); iter.hasNext();) {
-            Class element = iter.next();
-            String name = element.getName().replace(".", "/") + ".class";
-            InputStream in = ClassLoader.getSystemResourceAsStream(name);
-            byte[] bs = new byte[1024];
-            int count = 0;
-            ZipEntry entry = new ZipEntry(name);
-            out.putNextEntry(entry);
-            while ((count = in.read(bs)) != -1) {
-                out.write(bs, 0, count);
-            }
-            in.close();
-        }
-        out.close();
-
-        if (isDeleteOnExit) {
-            jarFile.deleteOnExit();
-        }
-
-        return jarFile;
-    }
-}
diff --git a/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/agents/HelloWorldAgent.java b/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/agents/HelloWorldAgent.java
deleted file mode 100644
index 24ca671..0000000
--- a/modules/instrument/src/test/java/org/apache/harmony/tests/java/lang/instrument/agents/HelloWorldAgent.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.tests.java.lang.instrument.agents;
-
-import java.lang.instrument.Instrumentation;
-
-public class HelloWorldAgent {
-    public static void premain(String agentArgs, Instrumentation inst) {
-        System.out.println("Hello World");
-    }
-}
diff --git a/modules/luni/META-INF/MANIFEST.MF b/modules/luni/META-INF/MANIFEST.MF
index 0894d0e..04bd3c2 100644
--- a/modules/luni/META-INF/MANIFEST.MF
+++ b/modules/luni/META-INF/MANIFEST.MF
@@ -21,7 +21,6 @@
  java.security,
  java.security.cert,
  java.text,
- java.util.concurrent;resolution:=optional,
  java.util.jar,
  java.util.regex,
  java.util.zip,
diff --git a/modules/luni/src/main/java/java/util/AbstractMap.java b/modules/luni/src/main/java/java/util/AbstractMap.java
index 90bbe15..7875a7d 100644
--- a/modules/luni/src/main/java/java/util/AbstractMap.java
+++ b/modules/luni/src/main/java/java/util/AbstractMap.java
@@ -133,22 +133,19 @@
                 return false;
             }
 
+            Iterator<Map.Entry<K, V>> it = entrySet().iterator();
+
             try {
-                for (Entry<K, V> entry : entrySet()) {
+                while (it.hasNext()) {
+                    Entry<K, V> entry = it.next();
                     K key = entry.getKey();
-                    V mine = entry.getValue();
-                    Object theirs = map.get(key);
-                    if (mine == null) {
-                        if (theirs != null || !map.containsKey(key)) {
-                            return false;
-                        }
-                    } else if (!mine.equals(theirs)) {
+                    V value = entry.getValue();
+                    Object obj = map.get(key);
+                    if( null != obj && (!obj.equals(value)) || null == obj && obj != value) {
                         return false;
                     }
                 }
-            } catch (NullPointerException ignored) {
-                return false;
-            } catch (ClassCastException ignored) {
+            } catch (ClassCastException cce) {
                 return false;
             }
             return true;
diff --git a/modules/luni/src/main/java/java/util/AbstractSet.java b/modules/luni/src/main/java/java/util/AbstractSet.java
index 1515550..e6ef0bb 100644
--- a/modules/luni/src/main/java/java/util/AbstractSet.java
+++ b/modules/luni/src/main/java/java/util/AbstractSet.java
@@ -55,9 +55,7 @@
 
             try {
                 return size() == s.size() && containsAll(s);
-            } catch (NullPointerException ignored) {
-                return false;
-            } catch (ClassCastException ignored) {
+            } catch (ClassCastException cce) {
                 return false;
             }
         }
diff --git a/modules/luni/src/main/java/java/util/Collections.java b/modules/luni/src/main/java/java/util/Collections.java
index 976fb6a..1315293 100644
--- a/modules/luni/src/main/java/java/util/Collections.java
+++ b/modules/luni/src/main/java/java/util/Collections.java
@@ -19,7 +19,6 @@
 
 import java.io.IOException;
 import java.io.ObjectOutputStream;
-import java.io.ObjectStreamException;
 import java.io.Serializable;
 import java.lang.reflect.Array;
 
@@ -189,15 +188,8 @@
     @SuppressWarnings("unchecked")
     public static final Map EMPTY_MAP = new EmptyMap();
 
-    /**
-     * This class is a singleton so that equals() and hashCode() work properly.
-     */
     private static final class ReverseComparator<T> implements Comparator<T>,
             Serializable {
-
-        private static final ReverseComparator<Object> INSTANCE
-                = new ReverseComparator<Object>();
-
         private static final long serialVersionUID = 7207038068494060240L;
 
         @SuppressWarnings("unchecked")
@@ -205,10 +197,6 @@
             Comparable<T> c2 = (Comparable<T>) o2;
             return c2.compareTo(o1);
         }
-
-        private Object readResolve() throws ObjectStreamException {
-            return INSTANCE;
-        }
     }
 
     private static final class ReverseComparatorWithComparator<T> implements
@@ -225,18 +213,6 @@
         public int compare(T o1, T o2) {
             return comparator.compare(o2, o1);
         }
-
-        @Override
-        public boolean equals(Object o) {
-            return o instanceof ReverseComparatorWithComparator
-                    && ((ReverseComparatorWithComparator) o).comparator
-                            .equals(comparator);
-        }
-
-        @Override
-        public int hashCode() {
-            return ~comparator.hashCode();
-        }
     }
 
     private static final class SingletonSet<E> extends AbstractSet<E> implements
@@ -376,17 +352,34 @@
                         }
 
                         public Map.Entry<K, V> next() {
-                            if (!hasNext) {
-                                throw new NoSuchElementException();
-                            }
+                            if (hasNext) {
+                                hasNext = false;
+                                return new Map.Entry<K, V>() {
+                                    @Override
+                                    public boolean equals(Object object) {
+                                        return contains(object);
+                                    }
 
-                            hasNext = false;
-                            return new MapEntry<K, V>(k, v) {
-                                @Override
-                                public V setValue(V value) {
-                                    throw new UnsupportedOperationException();
-                                }
-                            };
+                                    public K getKey() {
+                                        return k;
+                                    }
+
+                                    public V getValue() {
+                                        return v;
+                                    }
+
+                                    @Override
+                                    public int hashCode() {
+                                        return (k == null ? 0 : k.hashCode())
+                                                ^ (v == null ? 0 : v.hashCode());
+                                    }
+
+                                    public V setValue(V value) {
+                                        throw new UnsupportedOperationException();
+                                    }
+                                };
+                            }
+                            throw new NoSuchElementException();
                         }
 
                         public void remove() {
@@ -1691,12 +1684,6 @@
      */
     public static <T> T max(Collection<? extends T> collection,
             Comparator<? super T> comparator) {
-        if (comparator == null) {
-            @SuppressWarnings("unchecked") // null comparator? T is comparable
-            T result = (T) max((Collection<Comparable>) collection);
-            return result;
-        }
-
         Iterator<? extends T> it = collection.iterator();
         T max = it.next();
         while (it.hasNext()) {
@@ -1747,12 +1734,6 @@
      */
     public static <T> T min(Collection<? extends T> collection,
             Comparator<? super T> comparator) {
-        if (comparator == null) {
-            @SuppressWarnings("unchecked") // null comparator? T is comparable
-            T result = (T) min((Collection<Comparable>) collection);
-            return result;
-        }
-
         Iterator<? extends T> it = collection.iterator();
         T min = it.next();
         while (it.hasNext()) {
@@ -1812,9 +1793,8 @@
      * @see Comparable
      * @see Serializable
      */
-    @SuppressWarnings("unchecked")
     public static <T> Comparator<T> reverseOrder() {
-        return (Comparator) ReverseComparator.INSTANCE;
+        return new ReverseComparator<T>();
     }
 
     /**
@@ -1835,9 +1815,6 @@
         if (c == null) {
             return reverseOrder();
         }
-        if (c instanceof ReverseComparatorWithComparator) {
-            return ((ReverseComparatorWithComparator<T>) c).comparator;
-        }
         return new ReverseComparatorWithComparator<T>(c);
     }
 
@@ -2683,8 +2660,8 @@
      *            class of object that should be
      * @return specified object
      */
-    static <E> E checkType(E obj, Class<? extends E> type) {
-        if (obj != null && !type.isInstance(obj)) {
+    static <E> E checkType(E obj, Class<E> type) {
+        if (!type.isInstance(obj)) {
             // luni.05=Attempt to insert {0} element into collection with
             // element type {1}
             throw new ClassCastException(Messages.getString(
@@ -2792,11 +2769,20 @@
          */
         @SuppressWarnings("unchecked")
         public boolean addAll(Collection<? extends E> c1) {
-            Object[] array = c1.toArray();
-            for (Object o : array) {
-                checkType(o, type);
+            int size = c1.size();
+            if (size == 0) {
+                return false;
             }
-            return c.addAll((List<E>) Arrays.asList(array));
+            E[] arr = (E[]) new Object[size];
+            Iterator<? extends E> it = c1.iterator();
+            for (int i = 0; i < size; i++) {
+                arr[i] = checkType(it.next(), type);
+            }
+            boolean added = false;
+            for (int i = 0; i < size; i++) {
+                added |= c.add(arr[i]);
+            }
+            return added;
         }
 
         /**
@@ -2942,11 +2928,16 @@
          */
         @SuppressWarnings("unchecked")
         public boolean addAll(int index, Collection<? extends E> c1) {
-            Object[] array = c1.toArray();
-            for (Object o : array) {
-                checkType(o, type);
+            int size = c1.size();
+            if (size == 0) {
+                return false;
             }
-            return l.addAll(index, (List<E>) Arrays.asList(array));
+            E[] arr = (E[]) new Object[size];
+            Iterator<? extends E> it = c1.iterator();
+            for (int i = 0; i < size; i++) {
+                arr[i] = checkType(it.next(), type);
+            }
+            return l.addAll(index, Arrays.asList(arr));
         }
 
         /**
diff --git a/modules/luni/src/main/java/java/util/EnumSet.java b/modules/luni/src/main/java/java/util/EnumSet.java
index 6ba2299..9a96f06 100644
--- a/modules/luni/src/main/java/java/util/EnumSet.java
+++ b/modules/luni/src/main/java/java/util/EnumSet.java
@@ -103,7 +103,7 @@
         if (c instanceof EnumSet) {
             return copyOf((EnumSet<E>) c);
         }
-        if (c.isEmpty()) {
+        if (0 == c.size()) {
             throw new IllegalArgumentException();
         }
         Iterator<E> iterator = c.iterator();
@@ -304,13 +304,15 @@
     @Override
     public EnumSet<E> clone() {
         try {
-            return (EnumSet<E>) super.clone();
+            Object set = super.clone();
+            return (EnumSet<E>) set;
         } catch (CloneNotSupportedException e) {
-            throw new AssertionError(e);
+            return null;
         }
     }
 
-    boolean isValidType(Class<?> cls) {
+    @SuppressWarnings("unchecked")
+    boolean isValidType(Class cls) {
         return cls == elementClass || cls.getSuperclass() == elementClass;
     }
 
diff --git a/modules/luni/src/main/java/java/util/HugeEnumSet.java b/modules/luni/src/main/java/java/util/HugeEnumSet.java
index 30192ba..493a698 100644
--- a/modules/luni/src/main/java/java/util/HugeEnumSet.java
+++ b/modules/luni/src/main/java/java/util/HugeEnumSet.java
@@ -18,95 +18,90 @@
 
 
 /**
- * A concrete EnumSet for enums with more than 64 elements.
+ * This is a concrete subclass of EnumSet designed specifically for enum type
+ * with more than 64 elements.
+ * 
  */
 @SuppressWarnings("serial")
 final class HugeEnumSet<E extends Enum<E>> extends EnumSet<E> {
     
-    private static final int BIT_IN_LONG = 64;
-
     final private E[] enums;
     
     private long[] bits;
     
     private int size;
     
+    private static final int BIT_IN_LONG = 64;
+    
     HugeEnumSet(Class<E> elementType) {
         super(elementType);
         enums = elementType.getEnumConstants();
         bits = new long[(enums.length + BIT_IN_LONG - 1) / BIT_IN_LONG];
+        Arrays.fill(bits, 0);
     }
     
     private class HugeEnumSetIterator implements Iterator<E> {
 
-        /**
-         * The bits yet to be returned for the long in bits[index]. As values from the current index
-         * are returned, their bits are zeroed out. When this reaches zero, the index must be
-         * incremented.
-         */
-        private long currentBits = bits[0];
+        private long[] unProcessedBits;
 
-        /**
-         * The index into HugeEnumSet.bits of the next value to return.
-         */
-        private int index;
+        private int bitsPosition = 0;
 
-        /**
-         * The single bit of the next value to return.
+        /*
+         * Mask for current element.
          */
-        private long mask;
+        private long currentElementMask = 0;
 
-        /**
-         * The candidate for removal. If null, no value may be removed.
-         */
-        private E last;
+        boolean canProcess = true;
 
         private HugeEnumSetIterator() {
-            computeNextElement();
+            unProcessedBits = new long[bits.length];
+            System.arraycopy(bits, 0, unProcessedBits, 0, bits.length);
+            bitsPosition = unProcessedBits.length;
+            findNextNoneZeroPosition(0);
+            if (bitsPosition == unProcessedBits.length) {
+                canProcess = false;
+            }
         }
 
-        /**
-         * Assigns mask and index to the next available value, cycling currentBits as necessary.
-         */
-        void computeNextElement() {
-            while (true) {
-                if (currentBits != 0) {
-                    mask = currentBits & -currentBits; // the lowest 1 bit in currentBits
-                    return;
-                } else if (++index < bits.length) {
-                    currentBits = bits[index];
-                } else {
-                    mask = 0;
-                    return;
+        private void findNextNoneZeroPosition(int start) {
+            for (int i = start; i < unProcessedBits.length; i++) {
+                if (0 != bits[i]) {
+                    bitsPosition = i;
+                    break;
                 }
             }
         }
 
         public boolean hasNext() {
-            return mask != 0;
+            return canProcess;
         }
 
         public E next() {
-            if (mask == 0) {
+            if (!canProcess) {
                 throw new NoSuchElementException();
             }
-
-            int ordinal = Long.numberOfTrailingZeros(mask) + index * BIT_IN_LONG;
-            last = enums[ordinal];
-
-            currentBits &= ~mask;
-            computeNextElement();
-
-            return last;
+            currentElementMask = unProcessedBits[bitsPosition]
+                    & (-unProcessedBits[bitsPosition]);
+            unProcessedBits[bitsPosition] -= currentElementMask;
+            int index = Long.numberOfTrailingZeros(currentElementMask)
+                    + bitsPosition * BIT_IN_LONG;
+            if (0 == unProcessedBits[bitsPosition]) {
+                int oldBitsPosition = bitsPosition;
+                findNextNoneZeroPosition(bitsPosition + 1);
+                if (bitsPosition == oldBitsPosition) {
+                    canProcess = false;
+                }
+            }
+            return enums[index];
         }
 
         public void remove() {
-            if (last == null) {
+            if (currentElementMask == 0) {
                 throw new IllegalStateException();
             }
-
-            HugeEnumSet.this.remove(last);
-            last = null;
+            bits[bitsPosition] &= ~currentElementMask;
+            size--;
+            currentElementMask = 0;
         }
     }
     
@@ -115,44 +110,38 @@
         if (!isValidType(element.getDeclaringClass())) {
             throw new ClassCastException();
         }
+        calculateElementIndex(element);
 
-        int ordinal = element.ordinal();
-        int index = ordinal / BIT_IN_LONG;
-        int inBits = ordinal % BIT_IN_LONG;
-        long oldBits = bits[index];
-        long newBits = oldBits | (1L << inBits);
-        if (oldBits != newBits) {
-            bits[index] = newBits;
-            size++;
-            return true;
+        bits[bitsIndex] |= (1l << elementInBits);
+        if (oldBits == bits[bitsIndex]) {
+            return false;
         }
-        return false;
+        size++;
+        return true;
     }
     
     @Override
     public boolean addAll(Collection<? extends E> collection) {
-        if (collection.isEmpty() || collection == this) {
+        if (0 == collection.size() || this == collection) {
             return false;
         }
-
         if (collection instanceof EnumSet) {
-            EnumSet<?> set = (EnumSet<?>) collection;
+            EnumSet set = (EnumSet) collection;
             if (!isValidType(set.elementClass)) {
                 throw new ClassCastException();
             }
-
-            HugeEnumSet<E> hugeSet = (HugeEnumSet<E>) set;
-            boolean changed = false;
+            HugeEnumSet hugeSet = (HugeEnumSet) set;
+            boolean addSuccessful = false;
             for (int i = 0; i < bits.length; i++) {
-                long oldBits = bits[i];
-                long newBits = oldBits | hugeSet.bits[i];
-                if (oldBits != newBits) {
-                    bits[i] = newBits;
-                    size += Long.bitCount(newBits) - Long.bitCount(oldBits);
-                    changed = true;
+                oldBits = bits[i];
+                bits[i] |= hugeSet.bits[i];
+                if (oldBits != bits[i]) {
+                    addSuccessful = true;
+                    size = size - Long.bitCount(oldBits)
+                            + Long.bitCount(bits[i]);
                 }
             }
-            return changed;
+            return addSuccessful;
         }
         return super.addAll(collection);
     }
@@ -170,53 +159,61 @@
     
     @Override
     protected void complement() {
-        size = 0;
-        for (int i = 0, length = bits.length; i < length; i++) {
-            long b = ~bits[i];
+        if (0 != enums.length) {
+            bitsIndex = enums.length / BIT_IN_LONG;
 
-            // zero out unused bits on the last element
-            if (i == length - 1) {
-                b &= -1L >>> (BIT_IN_LONG - (enums.length % BIT_IN_LONG));
+            size = 0;
+            int bitCount = 0;
+            for (int i = 0; i <= bitsIndex; i++) {
+                bits[i] = ~bits[i];
+                bitCount = Long.bitCount(bits[i]);
+                size += bitCount;
             }
-
-            size += Long.bitCount(b);
-            bits[i] = b;
+            bits[bitsIndex] &= (-1l >>> (BIT_IN_LONG - enums.length
+                    % BIT_IN_LONG));
+            size -= bitCount;
+            bitCount = Long.bitCount(bits[bitsIndex]);
+            size += bitCount;
         }
     }
     
+    @SuppressWarnings("unchecked")
     @Override
     public boolean contains(Object object) {
-        if (object == null || !isValidType(object.getClass())) {
+        if (null == object) {
             return false;
         }
-
-        @SuppressWarnings("unchecked") // guarded by isValidType()
-        int ordinal = ((E) object).ordinal();
-        int index = ordinal / BIT_IN_LONG;
-        int inBits = ordinal % BIT_IN_LONG;
-        return (bits[index] & (1L << inBits)) != 0;
+        if (!isValidType(object.getClass())) {
+            return false;
+        }
+        calculateElementIndex((E)object);
+        return (bits[bitsIndex] & (1l << elementInBits)) != 0;
     }
     
     @Override
+    @SuppressWarnings("unchecked")
     public HugeEnumSet<E> clone() {
-        HugeEnumSet<E> set = (HugeEnumSet<E>) super.clone();
-        set.bits = bits.clone();
-        return set;
+        Object set = super.clone();
+        if (null != set) {
+            ((HugeEnumSet<E>) set).bits = bits.clone();
+            return (HugeEnumSet<E>) set;
+        }
+        return null;
     }
     
     @Override
     public boolean containsAll(Collection<?> collection) {
-        if (collection.isEmpty()) {
+        if (collection.size() == 0) {
             return true;
         }
         if (collection instanceof HugeEnumSet) {
-            HugeEnumSet<?> set = (HugeEnumSet<?>) collection;
-            if (isValidType(set.elementClass)) {
-                for (int i = 0; i < bits.length; i++) {
-                    long setBits = set.bits[i];
-                    if ((bits[i] & setBits) != setBits) {
+            HugeEnumSet set = (HugeEnumSet) collection;
+            if(isValidType(set.elementClass )) {
+                for(int i = 0; i < bits.length; i++) {
+                    if((bits[i] & set.bits[i]) != set.bits[i]){
                         return false;
                     }
+                    
                 }
                 return true;
             }
@@ -226,13 +223,13 @@
     
     @Override
     public boolean equals(Object object) {
-        if (object == null) {
+        if (null == object) {
             return false;
         }
         if (!isValidType(object.getClass())) {
             return super.equals(object);
         }
-        return Arrays.equals(bits, ((HugeEnumSet<?>) object).bits);
+        return Arrays.equals(bits, ((HugeEnumSet) object).bits);
     }
     
     @Override
@@ -242,48 +239,38 @@
     
     @Override
     public boolean remove(Object object) {
-        if (object == null || !isValidType(object.getClass())) {
+        if (!contains(object)) {
             return false;
         }
-
-        @SuppressWarnings("unchecked") // guarded by isValidType()
-        int ordinal = ((E) object).ordinal();
-        int index = ordinal / BIT_IN_LONG;
-        int inBits = ordinal % BIT_IN_LONG;
-        long oldBits = bits[index];
-        long newBits = oldBits & ~(1L << inBits);
-        if (oldBits != newBits) {
-            bits[index] = newBits;
-            size--;
-            return true;
-        }
-        return false;
+        bits[bitsIndex] -= (1l << elementInBits);
+        size--;
+        return true;
     }
     
     @Override
     public boolean removeAll(Collection<?> collection) {
-        if (collection.isEmpty()) {
+        if (0 == collection.size()) {
             return false;
         }
         
         if (collection instanceof EnumSet) {
-            EnumSet<?> set = (EnumSet<?>) collection;
+            EnumSet<E> set = (EnumSet<E>) collection;
             if (!isValidType(set.elementClass)) {
                 return false;
             }
-
-            HugeEnumSet<E> hugeSet = (HugeEnumSet<E>) set;
-            boolean changed = false;
+            boolean removeSuccessful = false;
+            long mask = 0;
             for (int i = 0; i < bits.length; i++) {
-                long oldBits = bits[i];
-                long newBits = oldBits & ~hugeSet.bits[i];
-                if (oldBits != newBits) {
-                    bits[i] = newBits;
-                    size += Long.bitCount(newBits) - Long.bitCount(oldBits);
-                    changed = true;
+                oldBits = bits[i];
+                mask = bits[i] & ((HugeEnumSet<E>) set).bits[i];
+                if (mask != 0) {
+                    bits[i] -= mask;
+                    size = (size - Long.bitCount(oldBits) + Long
+                            .bitCount(bits[i]));
+                    removeSuccessful = true;
                 }
             }
-            return changed;
+            return removeSuccessful;
         }
         return super.removeAll(collection);
     }
@@ -291,65 +278,72 @@
     @Override
     public boolean retainAll(Collection<?> collection) {
         if (collection instanceof EnumSet) {
-            EnumSet<?> set = (EnumSet<?>) collection;
+            EnumSet<E> set = (EnumSet<E>) collection;
             if (!isValidType(set.elementClass)) {
-                if (size > 0) {
-                    clear();
-                    return true;
-                } else {
-                    return false;
-                }
+                clear();
+                return true;
             }
 
-            HugeEnumSet<E> hugeSet = (HugeEnumSet<E>) set;
-            boolean changed = false;
+            boolean retainSuccessful = false;
+            oldBits = 0;
             for (int i = 0; i < bits.length; i++) {
-                long oldBits = bits[i];
-                long newBits = oldBits & hugeSet.bits[i];
-                if (oldBits != newBits) {
-                    bits[i] = newBits;
-                    size += Long.bitCount(newBits) - Long.bitCount(oldBits);
-                    changed = true;
+                oldBits = bits[i];
+                bits[i] &= ((HugeEnumSet<E>) set).bits[i];
+                if (oldBits != bits[i]) {
+                    size = size - Long.bitCount(oldBits)
+                            + Long.bitCount(bits[i]);
+                    retainSuccessful = true;
                 }
             }
-            return changed;
+            return retainSuccessful;
         }
         return super.retainAll(collection);
     }
     
     @Override
     void setRange(E start, E end) {
-        int startOrdinal = start.ordinal();
-        int startIndex = startOrdinal / BIT_IN_LONG;
-        int startInBits = startOrdinal % BIT_IN_LONG;
-
-        int endOrdinal = end.ordinal();
-        int endIndex = endOrdinal / BIT_IN_LONG;
-        int endInBits = endOrdinal % BIT_IN_LONG;
-
-        if (startIndex == endIndex) {
-            long range = (-1L >>> (BIT_IN_LONG -(endInBits - startInBits + 1))) << startInBits;
-            size -= Long.bitCount(bits[startIndex]);
-            bits[startIndex] |= range;
-            size += Long.bitCount(bits[startIndex]);
-
+        calculateElementIndex(start);
+        int startBitsIndex = bitsIndex;
+        int startElementInBits = elementInBits;
+        calculateElementIndex(end);
+        int endBitsIndex = bitsIndex;
+        int endElementInBits = elementInBits;
+        long range = 0;
+        if (startBitsIndex == endBitsIndex) {
+            range = (-1l >>> (BIT_IN_LONG -(endElementInBits - startElementInBits + 1))) << startElementInBits;
+            size -= Long.bitCount(bits[bitsIndex]);
+            bits[bitsIndex] |= range;
+            size += Long.bitCount(bits[bitsIndex]);
         } else {
-            long range = (-1L >>> startInBits) << startInBits;
-            size -= Long.bitCount(bits[startIndex]);
-            bits[startIndex] |= range;
-            size += Long.bitCount(bits[startIndex]);
+            range = (-1l >>> startElementInBits) << startElementInBits;
+            size -= Long.bitCount(bits[startBitsIndex]);
+            bits[startBitsIndex] |= range;
+            size += Long.bitCount(bits[startBitsIndex]);
 
-            // endInBits + 1 is the number of consecutive ones.
-            // 63 - endInBits is the following zeros of the right most one.
-            range = -1L >>> (BIT_IN_LONG - (endInBits + 1));
-            size -= Long.bitCount(bits[endIndex]);
-            bits[endIndex] |= range;
-            size += Long.bitCount(bits[endIndex]);
-            for (int i = (startIndex + 1); i <= (endIndex - 1); i++) {
+            // endElementInBits + 1 is the number of consecutive ones.
+            // 63 - endElementInBits is the following zeros of the right most one.
+            range = -1l >>> (BIT_IN_LONG - (endElementInBits + 1));
+            size -= Long.bitCount(bits[endBitsIndex]);
+            bits[endBitsIndex] |= range;
+            size += Long.bitCount(bits[endBitsIndex]);
+            for(int i = (startBitsIndex + 1); i <= (endBitsIndex - 1); i++) {
                 size -= Long.bitCount(bits[i]);
-                bits[i] = -1L;
+                bits[i] = -1l;
                 size += Long.bitCount(bits[i]);
             }
         }
     }
+    
+    private void calculateElementIndex(E element) {
+        int elementOrdinal = element.ordinal();
+        bitsIndex = elementOrdinal / BIT_IN_LONG;
+        elementInBits = elementOrdinal % BIT_IN_LONG;
+        oldBits = bits[bitsIndex];
+    }
+    
+    private int bitsIndex;
+
+    private int elementInBits;
+
+    private long oldBits;
 }
diff --git a/modules/luni/src/main/java/java/util/MiniEnumSet.java b/modules/luni/src/main/java/java/util/MiniEnumSet.java
index 24f8249..dace982 100644
--- a/modules/luni/src/main/java/java/util/MiniEnumSet.java
+++ b/modules/luni/src/main/java/java/util/MiniEnumSet.java
@@ -18,7 +18,9 @@
 
 
 /**
- * A concrete EnumSet for enums with 64 or fewer elements.
+ * This is a concrete subclass of EnumSet designed specifically for enum type
+ * with less than or equal to 64 elements.
+ * 
  */
 @SuppressWarnings("serial")
 final class MiniEnumSet<E extends Enum<E>> extends EnumSet<E> {
@@ -37,47 +39,45 @@
     
     private class MiniEnumSetIterator implements Iterator<E> {
 
-        /**
-         * The bits yet to be returned for bits. As values from the current index are returned,
-         * their bits are zeroed out.
-         */
-        private long currentBits = bits;
+        private long unProcessedBits;
 
-        /**
-         * The single bit of the next value to return.
+        /*
+         * Mask for current element.
          */
-        private long mask = currentBits & -currentBits; // the lowest 1 bit in currentBits
+        private long currentElementMask;
 
-        /**
-         * The candidate for removal. If null, no value may be removed.
-         */
-        private E last;
+        private boolean canProcess = true;
+
+        private MiniEnumSetIterator() {
+            unProcessedBits = bits;
+            if (0 == unProcessedBits) {
+                canProcess = false;
+            }
+        }
 
         public boolean hasNext() {
-            return mask != 0;
+            return canProcess;
         }
 
         public E next() {
-            if (mask == 0) {
+            if (!canProcess) {
                 throw new NoSuchElementException();
             }
-
-            int ordinal = Long.numberOfTrailingZeros(mask);
-            last = enums[ordinal];
-
-            currentBits &= ~mask;
-            mask = currentBits & -currentBits; // the lowest 1 bit in currentBits
-
-            return last;
+            currentElementMask = unProcessedBits & (-unProcessedBits);
+            unProcessedBits -= currentElementMask;
+            if (0 == unProcessedBits) {
+                canProcess = false;
+            }
+            return enums[Long.numberOfTrailingZeros(currentElementMask)];
         }
 
         public void remove() {
-            if (last == null) {
+            if ( currentElementMask == 0 ) {
                 throw new IllegalStateException();
             }
-
-            MiniEnumSet.this.remove(last);
-            last = null;
+            bits &= ~currentElementMask;
+            size = Long.bitCount(bits);
+            currentElementMask = 0;
         }
     }
 
@@ -102,83 +102,77 @@
         if (!isValidType(element.getDeclaringClass())) {
             throw new ClassCastException();
         }
-
-        long oldBits = bits;
-        long newBits = oldBits | (1L << element.ordinal());
-        if (oldBits != newBits) {
-            bits = newBits;
-            size++;
-            return true;
+        long mask = 1l << element.ordinal();
+        if ((bits & mask) == mask) {
+            return false;
         }
-        return false;
+        bits |= mask;
+
+        size++;
+        return true;
     }
     
     @Override
     public boolean addAll(Collection<? extends E> collection) {
-        if (collection.isEmpty()) {
+        if (0 == collection.size()) {
             return false;
         }
         if (collection instanceof EnumSet) {
-            EnumSet<?> set = (EnumSet<?>) collection;
+            EnumSet<?> set = (EnumSet)collection;
             if (!isValidType(set.elementClass)) {
                 throw new ClassCastException();
             }
-
             MiniEnumSet<?> miniSet = (MiniEnumSet<?>) set;
             long oldBits = bits;
-            long newBits = oldBits | miniSet.bits;
-            bits = newBits;
-            size = Long.bitCount(newBits);
-            return (oldBits != newBits);
+            bits |= miniSet.bits;
+            size = Long.bitCount(bits);
+            return (oldBits != bits);
         }
         return super.addAll(collection);
     }
     
     @Override
     public boolean contains(Object object) {
-        if (object == null || !isValidType(object.getClass())) {
+        if (null == object) {
             return false;
         }
-
-        @SuppressWarnings("unchecked") // guarded by isValidType()
-        Enum<E> element = (Enum<E>) object;
+        if (!isValidType(object.getClass())) {
+            return false;
+        }
+        Enum<?> element = (Enum<?>) object;
         int ordinal = element.ordinal();
-        return (bits & (1L << ordinal)) != 0;
+        return (bits & (1l << ordinal)) != 0;
     }
     
     @Override
     public boolean containsAll(Collection<?> collection) {
-        if (collection.isEmpty()) {
+        if (collection.size() == 0) {
             return true;
         }
         if (collection instanceof MiniEnumSet) {
             MiniEnumSet<?> set = (MiniEnumSet<?>) collection;
-            long setBits = set.bits;
-            return isValidType(set.elementClass) && ((bits & setBits) == setBits);
+            return isValidType(set.elementClass ) && ((bits & set.bits) == set.bits);
         }
         return !(collection instanceof EnumSet) && super.containsAll(collection);  
     }
     
     @Override
     public boolean removeAll(Collection<?> collection) {
-        if (collection.isEmpty()) {
+        if (0 == collection.size()) {
             return false;
         }
         if (collection instanceof EnumSet) {
-            EnumSet<?> set = (EnumSet<?>) collection;
-            if (!isValidType(set.elementClass)) {
-                return false;
+            EnumSet<E> set = (EnumSet<E>) collection;
+            boolean removeSuccessful = false;
+            if (isValidType(set.elementClass)) {
+                long mask = bits & ((MiniEnumSet<E>) set).bits;
+                if (mask != 0) {
+                    bits -= mask;
+                    size = Long.bitCount(bits);
+                    removeSuccessful = true;
+                }
             }
-
-            MiniEnumSet<E> miniSet = (MiniEnumSet<E>) set;
-            long oldBits = bits;
-            long newBits = oldBits & ~miniSet.bits;
-            if (oldBits != newBits) {
-                bits = newBits;
-                size = Long.bitCount(newBits);
-                return true;
-            }
-            return false;
+            return removeSuccessful;
         }
         return super.removeAll(collection);
     }
@@ -186,46 +180,33 @@
     @Override
     public boolean retainAll(Collection<?> collection) {
         if (collection instanceof EnumSet) {
-            EnumSet<?> set = (EnumSet<?>) collection;
+            EnumSet<E> set = (EnumSet<E>) collection;
             if (!isValidType(set.elementClass)) {
-                if (size > 0) {
-                    clear();
-                    return true;
-                } else {
-                    return false;
-                }
-            }
-
-            MiniEnumSet<E> miniSet = (MiniEnumSet<E>) set;
-            long oldBits = bits;
-            long newBits = oldBits & miniSet.bits;
-            if (oldBits != newBits) {
-                bits = newBits;
-                size = Long.bitCount(newBits);
+                clear();
                 return true;
             }
-            return false;
+            boolean retainSuccessful = false;
+            long oldBits = bits;
+            bits &= ((MiniEnumSet<E>)set).bits;
+            if (oldBits != bits) {
+                size = Long.bitCount(bits);
+                retainSuccessful = true;
+            }
+            return retainSuccessful;
         }
         return super.retainAll(collection);
     }
     
     @Override
     public boolean remove(Object object) {
-        if (object == null || !isValidType(object.getClass())) {
+        if (!contains(object)) {
             return false;
         }
-
-        @SuppressWarnings("unchecked") // guarded by isValidType() 
-        Enum<E> element = (Enum<E>) object;
+        Enum<?> element = (Enum<?>) object;
         int ordinal = element.ordinal();
-        long oldBits = bits;
-        long newBits = oldBits & ~(1L << ordinal);
-        if (oldBits != newBits) {
-            bits = newBits;
-            size--;
-            return true;
-        }
-        return false;
+        bits -= (1l << ordinal);
+        size--;
+        return true;
     }
     
     @Override
@@ -233,18 +214,18 @@
         if (!(object instanceof EnumSet)) {
             return super.equals(object);
         }
-        EnumSet<?> set =(EnumSet<?>) object;
-        if (!isValidType(set.elementClass)) {
-            return size == 0 && set.isEmpty();
+        EnumSet<?> set =(EnumSet<?>)object; 
+        if( !isValidType(set.elementClass) ) {
+            return size == 0 && set.size() == 0;
         }
-        return bits == ((MiniEnumSet<?>) set).bits;
+        return bits == ((MiniEnumSet<?>)set).bits;
     }
     
     @Override
     void complement() {
-        if (enums.length != 0) {
+        if (0 != enums.length) {
             bits = ~bits;
-            bits &= (-1L >>> (MAX_ELEMENTS - enums.length));
+            bits &= (-1l >>> (MAX_ELEMENTS - enums.length));
             size = enums.length - size;
         }
     }
@@ -252,7 +233,7 @@
     @Override
     void setRange(E start, E end) {
         int length = end.ordinal() - start.ordinal() + 1;
-        long range = (-1L >>> (MAX_ELEMENTS - length)) << start.ordinal();
+        long range = (-1l >>> (MAX_ELEMENTS - length)) << start.ordinal();
         bits |= range;
         size = Long.bitCount(bits);
     }
diff --git a/modules/luni/src/main/java/java/util/TreeMap.java b/modules/luni/src/main/java/java/util/TreeMap.java
index 9d1e220..610bd50 100644
--- a/modules/luni/src/main/java/java/util/TreeMap.java
+++ b/modules/luni/src/main/java/java/util/TreeMap.java
@@ -160,9 +160,6 @@
 
     @SuppressWarnings("unchecked")
      private static <T> Comparable<T> toComparable(T obj) {
-        if (obj == null) {
-            throw new NullPointerException();
-        }
         return (Comparable) obj;
     }
 
diff --git a/modules/luni/src/main/java/java/util/TreeSet.java b/modules/luni/src/main/java/java/util/TreeSet.java
index 21c453a..2802bbc 100644
--- a/modules/luni/src/main/java/java/util/TreeSet.java
+++ b/modules/luni/src/main/java/java/util/TreeSet.java
@@ -35,10 +35,9 @@
 
     private static final long serialVersionUID = -2479143000061671589L;
 
-    /** Keys are this set's elements. Values are always Boolean.TRUE */
-    private transient SortedMap<E, Object> backingMap;
+    private transient SortedMap<E, E> backingMap;
 
-    private TreeSet(SortedMap<E, Object> map) {
+    private TreeSet(SortedMap<E, E> map) {
         this.backingMap = map;
     }
 
@@ -47,7 +46,7 @@
      * ordering.
      */
     public TreeSet() {
-        backingMap = new TreeMap<E, Object>();
+        backingMap = new TreeMap<E, E>();
     }
 
     /**
@@ -74,7 +73,7 @@
      *            the comparator to use.
      */
     public TreeSet(Comparator<? super E> comparator) {
-        backingMap = new TreeMap<E, Object>(comparator);
+        backingMap = new TreeMap<E, E>(comparator);
     }
 
     /**
@@ -108,7 +107,7 @@
      */
     @Override
     public boolean add(E object) {
-        return backingMap.put(object, Boolean.TRUE) == null;
+        return backingMap.put(object, object) == null;
     }
 
     /**
@@ -154,10 +153,10 @@
         try {
             TreeSet<E> clone = (TreeSet<E>) super.clone();
             if (backingMap instanceof TreeMap) {
-                clone.backingMap = (SortedMap<E, Object>) ((TreeMap<E, Object>) backingMap)
+                clone.backingMap = (SortedMap<E, E>) ((TreeMap<E, E>) backingMap)
                         .clone();
             } else {
-                clone.backingMap = new TreeMap<E, Object>(backingMap);
+                clone.backingMap = new TreeMap<E, E>(backingMap);
             }
             return clone;
         } catch (CloneNotSupportedException e) {
@@ -374,14 +373,14 @@
     private void readObject(ObjectInputStream stream) throws IOException,
             ClassNotFoundException {
         stream.defaultReadObject();
-        TreeMap<E, Object> map = new TreeMap<E, Object>(
-                (Comparator<? super E>) stream.readObject());
+        TreeMap<E, E> map = new TreeMap<E, E>((Comparator<? super E>) stream
+                .readObject());
         int size = stream.readInt();
         if (size > 0) {
-            TreeMap.Node<E, Object> lastNode = null;
+            TreeMap.Node<E,E> lastNode = null;
             for(int i=0; i<size; i++) {
                 E elem = (E)stream.readObject();
-                lastNode = map.addToLast(lastNode,elem, Boolean.TRUE);
+                lastNode = map.addToLast(lastNode,elem,elem);
             }
         }
         backingMap = map;
diff --git a/modules/luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java b/modules/luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java
new file mode 100644
index 0000000..0ff073c
--- /dev/null
+++ b/modules/luni/src/main/java/org/apache/harmony/luni/util/ExposedByteArrayInputStream.java
@@ -0,0 +1,57 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.luni.util;
+
+import java.io.ByteArrayInputStream;
+
+/**
+ * The extension of <code>ByteArrayInputStream</code> which exposes an
+ * underlying buffer.
+ */
+public class ExposedByteArrayInputStream extends ByteArrayInputStream {
+
+    /**
+     * @see java.io.ByteArrayInputStream(byte[])
+     */
+    public ExposedByteArrayInputStream(byte buf[]) {
+        super(buf);
+    }
+
+    /**
+     * @see java.io.ByteArrayInputStream(byte[], int, int)
+     */
+    public ExposedByteArrayInputStream(byte buf[], int offset, int length) {
+        super(buf, offset, length);
+    }
+
+    /**
+     * Reads the whole stream and returns the stream snapshot.
+     */
+    public synchronized byte[] expose() {
+        if (pos == 0 && count == buf.length) {
+            skip(count);
+            return buf;
+        }
+
+        final int available = available();
+        final byte[] buffer = new byte[available];
+        System.arraycopy(buf, pos, buffer, 0, available);
+        skip(available);
+        return buffer;
+    }
+}
diff --git a/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java b/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
new file mode 100644
index 0000000..61dfeee
--- /dev/null
+++ b/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamExposer.java
@@ -0,0 +1,116 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.luni.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * The class contains static {@link java.io.InputStream} utilities.
+ */
+public class InputStreamExposer {
+
+    /**
+     * Provides access to a protected underlying buffer of
+     * <code>ByteArrayInputStream</code>.
+     */
+    private static final Field BAIS_BUF;
+
+    /**
+     * Provides access to a protected position in the underlying buffer of
+     * <code>ByteArrayInputStream</code>.
+     */
+    private static final Field BAIS_POS;
+
+    static {
+        final Field[] f = new Field[2];
+        AccessController.doPrivileged(new PrivilegedAction<Object>() {
+            public Object run() {
+                try {
+                    f[0] = ByteArrayInputStream.class.getDeclaredField("buf");
+                    f[0].setAccessible(true);
+                    f[1] = ByteArrayInputStream.class.getDeclaredField("pos");
+                    f[1].setAccessible(true);
+                } catch (NoSuchFieldException nsfe) {
+                    throw new InternalError(nsfe.getLocalizedMessage());
+                }
+                return null;
+            }
+        });
+        BAIS_BUF = f[0];
+        BAIS_POS = f[1];
+    }
+
+    /**
+     * Reads all bytes from {@link java.io.ByteArrayInputStream} using its
+     * underlying buffer directly.
+     * 
+     * @return an underlying buffer, if a current position is at the buffer
+     *         beginning, and an end position is at the buffer end, or a copy of
+     *         the underlying buffer part.
+     */
+    private static byte[] expose(ByteArrayInputStream bais) {
+        byte[] buffer, buf;
+        int pos;
+        synchronized (bais) {
+            int available = bais.available();
+            try {
+                buf = (byte[]) BAIS_BUF.get(bais);
+                pos = BAIS_POS.getInt(bais);
+            } catch (IllegalAccessException iae) {
+                throw new InternalError(iae.getLocalizedMessage());
+            }
+            if (pos == 0 && available == buf.length) {
+                buffer = buf;
+            } else {
+                buffer = new byte[available];
+                System.arraycopy(buf, pos, buffer, 0, available);
+            }
+            bais.skip(available);
+        }
+        return buffer;
+    }
+
+    /**
+     * The utility method for reading the whole input stream into a snapshot
+     * buffer. To speed up the access it works with an underlying buffer for a
+     * given {@link java.io.ByteArrayInputStream}.
+     * 
+     * @param is
+     *            the stream to be read.
+     * @return the snapshot wrapping the buffer where the bytes are read to.
+     * @throws UnsupportedOperationException if the input stream data cannot be exposed
+     */
+    public static byte[] expose(InputStream is) throws IOException, UnsupportedOperationException {
+        if (is instanceof ExposedByteArrayInputStream) {
+            return ((ExposedByteArrayInputStream) is).expose();
+        }
+
+        if (is.getClass().equals(ByteArrayInputStream.class)) {
+            return expose((ByteArrayInputStream) is);
+        }
+
+        // We don't know how to do this
+        throw new UnsupportedOperationException();
+    }
+}
diff --git a/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java b/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java
deleted file mode 100644
index 98835f7..0000000
--- a/modules/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-package org.apache.harmony.luni.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * The class contains static {@link java.io.InputStream} utilities.
- */
-public class InputStreamHelper {
-
-    /**
-     * Provides access to a protected underlying buffer of
-     * <code>ByteArrayInputStream</code>.
-     */
-    private static final Field BAIS_BUF;
-
-    /**
-     * Provides access to a protected position in the underlying buffer of
-     * <code>ByteArrayInputStream</code>.
-     */
-    private static final Field BAIS_POS;
-
-    static {
-        final Field[] f = new Field[2];
-        AccessController.doPrivileged(new PrivilegedAction<Object>() {
-            public Object run() {
-                try {
-                    f[0] = ByteArrayInputStream.class.getDeclaredField("buf"); //$NON-NLS-1$
-                    f[0].setAccessible(true);
-                    f[1] = ByteArrayInputStream.class.getDeclaredField("pos"); //$NON-NLS-1$
-                    f[1].setAccessible(true);
-                } catch (NoSuchFieldException nsfe) {
-                    throw new InternalError(nsfe.getLocalizedMessage());
-                }
-                return null;
-            }
-        });
-        BAIS_BUF = f[0];
-        BAIS_POS = f[1];
-    }
-
-    /**
-     * The extension of <code>ByteArrayInputStream</code> which exposes an
-     * underlying buffer.
-     */
-    static class ExposedByteArrayInputStream extends ByteArrayInputStream {
-
-        /**
-         * @see java.io.ByteArrayInputStream(byte[])
-         */
-        public ExposedByteArrayInputStream(byte buf[]) {
-            super(buf);
-        }
-
-        /**
-         * @see java.io.ByteArrayInputStream(byte[], int, int)
-         */
-        public ExposedByteArrayInputStream(byte buf[], int offset, int length) {
-            super(buf, offset, length);
-        }
-
-        /**
-         * Reads the whole stream and returns the stream snapshot.
-         */
-        public synchronized byte[] expose() {
-            if (pos == 0 && count == buf.length) {
-                skip(count);
-                return buf;
-            }
-
-            final int available = available();
-            final byte[] buffer = new byte[available];
-            System.arraycopy(buf, pos, buffer, 0, available);
-            skip(available);
-            return buffer;
-        }
-    }
-
-    /**
-     * Reads all bytes from {@link java.io.ByteArrayInputStream} using its
-     * underlying buffer directly.
-     * 
-     * @return an underlying buffer, if a current position is at the buffer
-     *         beginning, and an end position is at the buffer end, or a copy of
-     *         the underlying buffer part.
-     */
-    private static byte[] expose(ByteArrayInputStream bais) {
-        byte[] buffer, buf;
-        int pos;
-        synchronized (bais) {
-            int available = bais.available();
-            try {
-                buf = (byte[]) BAIS_BUF.get(bais);
-                pos = BAIS_POS.getInt(bais);
-            } catch (IllegalAccessException iae) {
-                throw new InternalError(iae.getLocalizedMessage());
-            }
-            if (pos == 0 && available == buf.length) {
-                buffer = buf;
-            } else {
-                buffer = new byte[available];
-                System.arraycopy(buf, pos, buffer, 0, available);
-            }
-            bais.skip(available);
-        }
-        return buffer;
-    }
-
-    /**
-     * The utility method for reading the whole input stream into a snapshot
-     * buffer. To speed up the access it works with an underlying buffer for a
-     * given {@link java.io.ByteArrayInputStream}.
-     * 
-     * @param is
-     *            the stream to be read.
-     * @return the snapshot wrapping the buffer where the bytes are read to.
-     * @throws UnsupportedOperationException
-     *             if the input stream data cannot be exposed
-     */
-    public static byte[] expose(InputStream is) throws IOException,
-            UnsupportedOperationException {
-        if (is instanceof ExposedByteArrayInputStream) {
-            return ((ExposedByteArrayInputStream) is).expose();
-        }
-
-        if (is.getClass().equals(ByteArrayInputStream.class)) {
-            return expose((ByteArrayInputStream) is);
-        }
-
-        // We don't know how to do this
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * Reads all the bytes from the given input stream.
-     * 
-     * Calls read multiple times on the given input stream until it receives an
-     * end of file marker. Returns the combined results as a byte array. Note
-     * that this method may block if the underlying stream read blocks.
-     * 
-     * @param is
-     *            the input stream to be read.
-     * @return the content of the stream as a byte array.
-     * @throws IOException
-     *             if a read error occurs.
-     */
-    public static byte[] readFullyAndClose(InputStream is) throws IOException {
-
-        try {
-            // Initial read
-            byte[] buffer = new byte[1024];
-            int count = is.read(buffer);
-            int nextByte = is.read();
-
-            // Did we get it all in one read?
-            if (nextByte == -1) {
-                byte[] dest = new byte[count];
-                System.arraycopy(buffer, 0, dest, 0, count);
-                return dest;
-            }
-
-            // Requires additional reads
-            ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
-            baos.write(buffer, 0, count);
-            baos.write(nextByte);
-            while (true) {
-                count = is.read(buffer);
-                if (count == -1) {
-                    return baos.toByteArray();
-                }
-                baos.write(buffer, 0, count);
-            }
-        } finally {
-            is.close();
-        }
-    }
-}
diff --git a/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java b/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
index 5fb61a6..570b7c2 100644
--- a/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
+++ b/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/SerializationStressTest.java
@@ -58,8 +58,6 @@
 import java.util.TreeSet;
 import java.util.Vector;
 
-import org.apache.harmony.luni.util.InputStreamHelper;
-
 /**
  * Automated Test Suite for class java.io.ObjectOutputStream
  * 
@@ -660,25 +658,33 @@
 		assertTrue("resolved class 3", resolvedClasses[2] == Number.class);
 	}
 
-    public void test_reset() throws IOException, ClassNotFoundException {
-        oos.reset();
-        oos.writeObject("R");
-        oos.reset();
-        oos.writeByte(24);
-        oos.close();
+	public void test_reset() {
+		try {
+			oos.reset();
+			oos.writeObject("R");
+			oos.reset();
+			oos.writeByte(24);
+			oos.close();
 
-        DataInputStream dis = new DataInputStream(loadStream());
-        byte[] input = InputStreamHelper.readFullyAndClose(dis);
-        byte[] result = new byte[] { (byte) 0xac, (byte) 0xed, (byte) 0,
-                (byte) 5, (byte) 0x79, (byte) 0x74, (byte) 0, (byte) 1,
-                (byte) 'R', (byte) 0x79, (byte) 0x77, (byte) 1, (byte) 24 };
-        assertTrue("incorrect output", Arrays.equals(input, result));
+			DataInputStream dis = new DataInputStream(loadStream());
+			byte[] input = new byte[dis.available()];
+			dis.readFully(input);
+			byte[] result = new byte[] { (byte) 0xac, (byte) 0xed, (byte) 0,
+					(byte) 5, (byte) 0x79, (byte) 0x74, (byte) 0, (byte) 1,
+					(byte) 'R', (byte) 0x79, (byte) 0x77, (byte) 1, (byte) 24 };
+			assertTrue("incorrect output", Arrays.equals(input, result));
 
-        ois = new ObjectInputStreamSubclass(loadStream());
-        assertEquals("Wrong result from readObject()", "R", ois.readObject());
-        assertEquals("Wrong result from readByte()", 24, ois.readByte());
-        ois.close();
-    }
+			ois = new ObjectInputStreamSubclass(loadStream());
+			assertEquals("Wrong result from readObject()", "R", ois.readObject()
+					);
+			assertEquals("Wrong result from readByte()", 24, ois.readByte());
+			ois.close();
+		} catch (IOException e1) {
+			fail("IOException : " + e1.getMessage());
+		} catch (ClassNotFoundException e2) {
+			fail("ClassNotFoundException : " + e2.getMessage());
+		}
+	}
 
 	public void test_serialVersionUID(Class clazz, long svUID) throws Exception {
 		final String idWrong = "serialVersionUID is wrong for: ";
diff --git a/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/AbstractMapTest.java b/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/AbstractMapTest.java
index b267189..957c37f 100644
--- a/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/AbstractMapTest.java
+++ b/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/AbstractMapTest.java
@@ -19,7 +19,6 @@
 
 import java.util.AbstractMap;
 import java.util.AbstractSet;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -356,57 +355,6 @@
         assertEquals("Should be equal", amt, ht);
     }
 
-    public void testEqualsWithNullValues() {
-        Map<String, String> a = new HashMap<String, String>();
-        a.put("a", null);
-        a.put("b", null);
-
-        Map<String, String> b = new HashMap<String, String>();
-        a.put("c", "cat");
-        a.put("d", "dog");
-
-        assertFalse(a.equals(b));
-        assertFalse(b.equals(a));
-    }
-
-    public void testNullsOnViews() {
-        Map<String, String> nullHostile = new Hashtable<String, String>();
-
-        nullHostile.put("a", "apple");
-        testNullsOnView(nullHostile.entrySet());
-
-        nullHostile.put("a", "apple");
-        testNullsOnView(nullHostile.keySet());
-
-        nullHostile.put("a", "apple");
-        testNullsOnView(nullHostile.values());
-    }
-
-    private void testNullsOnView(Collection<?> view) {
-        try {
-            assertFalse(view.contains(null));
-        } catch (NullPointerException optional) {
-        }
-
-        try {
-            assertFalse(view.remove(null));
-        } catch (NullPointerException optional) {
-        }
-
-        Set<Object> setOfNull = Collections.singleton(null);
-        assertFalse(view.equals(setOfNull));
-
-        try {
-            assertFalse(view.removeAll(setOfNull));
-        } catch (NullPointerException optional) {
-        }
-
-        try {
-            assertTrue(view.retainAll(setOfNull)); // destructive
-        } catch (NullPointerException optional) {
-        }
-    }
-
     protected void setUp() {
     }
 
diff --git a/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/EnumSetTest.java b/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/EnumSetTest.java
index 4a203a6..5258faa 100644
--- a/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/EnumSetTest.java
+++ b/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/EnumSetTest.java
@@ -137,25 +137,6 @@
         }
     }
 
-    public void testRemoveIteratorRemoveFromHugeEnumSet() {
-        EnumSet<HugeEnumCount> set = EnumSet.noneOf(HugeEnumCount.class);
-        set.add(HugeEnumCount.NO64);
-        set.add(HugeEnumCount.NO65);
-        set.add(HugeEnumCount.NO128);
-        Iterator<HugeEnumCount> iterator = set.iterator();
-        assertTrue(iterator.hasNext());
-        assertEquals(HugeEnumCount.NO64, iterator.next());
-        assertTrue(iterator.hasNext());
-        iterator.remove();
-        assertEquals(HugeEnumCount.NO65, iterator.next());
-        assertTrue(iterator.hasNext());
-        assertEquals(HugeEnumCount.NO128, iterator.next());
-        assertFalse(iterator.hasNext());
-        assertEquals(EnumSet.of(HugeEnumCount.NO65, HugeEnumCount.NO128), set);
-        iterator.remove();
-        assertEquals(EnumSet.of(HugeEnumCount.NO65), set);
-    }
-
     /**
      * @tests java.util.EnumSet#allOf(java.lang.Class)
      */
@@ -1239,21 +1220,21 @@
         Set<EnumWithInnerClass> setWithInnerClass = EnumSet
                 .allOf(EnumWithInnerClass.class);
         result = set.retainAll(setWithInnerClass);
-        assertFalse("Should return false", result); //$NON-NLS-1$
+        assertTrue("Should return true", result); //$NON-NLS-1$
         assertEquals("Size of set should be 0", 0, set.size()); //$NON-NLS-1$
 
         setWithInnerClass = EnumSet.noneOf(EnumWithInnerClass.class);
         result = set.retainAll(setWithInnerClass);
-        assertFalse("Should return false", result); //$NON-NLS-1$
+        assertTrue("Should return true", result); //$NON-NLS-1$
 
         Set<EmptyEnum> emptySet = EnumSet.allOf(EmptyEnum.class);
         result = set.retainAll(emptySet);
-        assertFalse("Should return false", result); //$NON-NLS-1$
+        assertTrue("Should return true", result); //$NON-NLS-1$
 
         Set<EnumWithAllInnerClass> setWithAllInnerClass = EnumSet
                 .allOf(EnumWithAllInnerClass.class);
         result = set.retainAll(setWithAllInnerClass);
-        assertFalse("Should return false", result); //$NON-NLS-1$
+        assertTrue("Should return true", result); //$NON-NLS-1$
 
         set.add(EnumFoo.a);
         result = set.retainAll(setWithInnerClass);
@@ -1333,17 +1314,17 @@
         Set<HugeEnumWithInnerClass> hugeSetWithInnerClass = EnumSet
                 .allOf(HugeEnumWithInnerClass.class);
         result = hugeSet.retainAll(hugeSetWithInnerClass);
-        assertFalse(result);
+        assertTrue(result);
         assertEquals(0, hugeSet.size());
 
         hugeSetWithInnerClass = EnumSet.noneOf(HugeEnumWithInnerClass.class);
         result = hugeSet.retainAll(hugeSetWithInnerClass);
-        assertFalse(result);
+        assertTrue(result);
 
         Set<HugeEnumWithInnerClass> hugeSetWithAllInnerClass = EnumSet
                 .allOf(HugeEnumWithInnerClass.class);
         result = hugeSet.retainAll(hugeSetWithAllInnerClass);
-        assertFalse(result);
+        assertTrue(result);
 
         hugeSet.add(HugeEnum.a);
         result = hugeSet.retainAll(hugeSetWithInnerClass);
diff --git a/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/io/UnixFileTest.java b/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/io/UnixFileTest.java
index e796325..99bf53c 100644
--- a/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/io/UnixFileTest.java
+++ b/modules/luni/src/test/api/unix/org/apache/harmony/luni/tests/java/io/UnixFileTest.java
@@ -24,8 +24,7 @@
 
 public class UnixFileTest extends TestCase {
 
-    public void test_getCanonicalPath() throws IOException,
-                                               InterruptedException {
+    public void test_getCanonicalPath() throws IOException {
         File tmpFolder1 = new File("folder1");
         tmpFolder1.mkdirs();
         tmpFolder1.deleteOnExit();
@@ -43,8 +42,7 @@
         tmpFolder4.deleteOnExit();
 
         // make a link to folder1/folder2
-        Process ln = Runtime.getRuntime().exec("ln -s folder1/folder2 folder2");
-        ln.waitFor();
+        Runtime.getRuntime().exec("ln -s folder1/folder2 folder2");
         File linkFile = new File("folder2");
         linkFile.deleteOnExit();
 
diff --git a/modules/rmi/META-INF/MANIFEST.MF b/modules/rmi/META-INF/MANIFEST.MF
index 25c2fda..f36a610 100644
--- a/modules/rmi/META-INF/MANIFEST.MF
+++ b/modules/rmi/META-INF/MANIFEST.MF
@@ -23,7 +23,6 @@
  javax.net,
  javax.net.ssl,
  org.apache.harmony.kernel.vm,
- org.apache.harmony.luni.util,
  org.apache.harmony.testframework.serialization;hy_usage=test;resolution:=optional
 Export-Package: java.rmi,
  java.rmi.activation,
diff --git a/modules/rmi/src/main/java/java/rmi/server/RMIClassLoader.java b/modules/rmi/src/main/java/java/rmi/server/RMIClassLoader.java
index 1fdbe22..fd1adcd 100644
--- a/modules/rmi/src/main/java/java/rmi/server/RMIClassLoader.java
+++ b/modules/rmi/src/main/java/java/rmi/server/RMIClassLoader.java
@@ -29,7 +29,6 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
-import org.apache.harmony.luni.util.InputStreamHelper;
 import org.apache.harmony.rmi.DefaultRMIClassLoaderSpi;
 import org.apache.harmony.rmi.internal.nls.Messages;
 
@@ -211,7 +210,9 @@
             // resource not found
             return null;
         }
-        byte[] buf = InputStreamHelper.readFullyAndClose(in);
+        Object obj = null;
+        byte[] buf = new byte[in.available()];
+        in.read(buf);
         String str = new String(buf, "UTF-8"); //$NON-NLS-1$
         StringTokenizer tok = new StringTokenizer(str, "\n\r"); //$NON-NLS-1$
 
diff --git a/modules/security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java b/modules/security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java
index b3f13cc..b6b7dab 100644
--- a/modules/security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java
+++ b/modules/security/src/main/java/common/org/apache/harmony/security/utils/JarUtils.java
@@ -38,7 +38,6 @@
 
 import javax.security.auth.x500.X500Principal;
 
-import org.apache.harmony.luni.util.InputStreamHelper;
 import org.apache.harmony.security.asn1.BerInputStream;
 import org.apache.harmony.security.internal.nls.Messages;
 import org.apache.harmony.security.pkcs7.ContentInfo;
@@ -145,7 +144,8 @@
         // Otherwise, compute the message digest on the data.
         List atr = sigInfo.getAuthenticatedAttributes();
 
-        byte[] sfBytes = InputStreamHelper.readFullyAndClose(signature);
+        byte[] sfBytes = new byte[signature.available()];
+        signature.read(sfBytes);
 
         if (atr == null) {
             sig.update(sfBytes);    
diff --git a/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java b/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java
index 96c27ed..65f6c9a 100644
--- a/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java
+++ b/modules/security/src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java
@@ -17,6 +17,7 @@
 
 package org.apache.harmony.security.tests.java.security;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -28,8 +29,6 @@
 import java.util.Enumeration;
 import java.util.jar.JarFile;
 
-import org.apache.harmony.luni.util.InputStreamHelper;
-
 import tests.support.Support_GetLocal;
 
 public class SecureClassLoader2Test extends junit.framework.TestCase {
@@ -62,11 +61,47 @@
 
         File file = Support_GetLocal.getLocalFile("hyts_security.jar");
         JarFile jar = new JarFile(file);
-        InputStream in = jar.getInputStream(jar.getEntry("packA/SecurityTest.class"));
-        byte[] bytes = InputStreamHelper.readFullyAndClose(in);
+        InputStream in = jar.getInputStream(jar
+                .getEntry("packA/SecurityTest.class"));
+        byte[] bytes = drain(in);
         Class c = myloader.define("packA.SecurityTest", bytes);
 		ProtectionDomain pd = c.getProtectionDomain();
 		assertNotNull("Expected dynamic policy", pd.getClassLoader());
 		assertNull("Expected null permissions", pd.getPermissions());
 	}
+
+    /*
+     * Drains the entire content from the given input stream and returns it as a
+     * byte[]. The stream is closed after being drained, or if an IOException
+     * occurs.
+     */
+    private byte[] drain(InputStream is) throws IOException {
+        try {
+            // Initial read
+            byte[] buffer = new byte[1024];
+            int count = is.read(buffer);
+            int nextByte = is.read();
+
+            // Did we get it all in one read?
+            if (nextByte == -1) {
+                byte[] dest = new byte[count];
+                System.arraycopy(buffer, 0, dest, 0, count);
+                return dest;
+            }
+
+            // Requires additional reads
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
+            baos.write(buffer, 0, count);
+            baos.write(nextByte);
+            while (true) {
+                count = is.read(buffer);
+                if (count == -1) {
+                    return baos.toByteArray();
+                }
+                baos.write(buffer, 0, count);
+            }
+        } finally {
+            is.close();
+        }
+    }
 }
\ No newline at end of file
diff --git a/modules/sound/src/main/java/org/apache/harmony/sound/utils/ProviderService.java b/modules/sound/src/main/java/org/apache/harmony/sound/utils/ProviderService.java
index d65b657..3a574c3 100644
--- a/modules/sound/src/main/java/org/apache/harmony/sound/utils/ProviderService.java
+++ b/modules/sound/src/main/java/org/apache/harmony/sound/utils/ProviderService.java
@@ -17,11 +17,12 @@
 
 package org.apache.harmony.sound.utils;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.InputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -30,8 +31,6 @@
 import java.util.List;
 import java.util.Properties;
 
-import org.apache.harmony.luni.util.InputStreamHelper;
-
 public class ProviderService {
 
     // Properties from sound.propertie file
@@ -146,7 +145,7 @@
                             try {
                                 InputStream in = urls.nextElement()
                                         .openStream();
-                                bytes = InputStreamHelper.readFullyAndClose(in);
+                                bytes = getAllBytesFromStreamAndClose(in);
                             } catch (IOException e) {
                                 continue;
                             }
@@ -173,5 +172,41 @@
     public static Properties getSoundProperties() {
         return devices;
     }
+    
+    /*
+     * Drains the entire content from the given input stream and returns it as a
+     * byte[]. The stream is closed after being drained, or if an IOException
+     * occurs.
+     */
+    private static byte[] getAllBytesFromStreamAndClose(InputStream is)
+            throws IOException {
+        try {
+            // Initial read
+            byte[] buffer = new byte[512];
+            int count = is.read(buffer);
+            int nextByte = is.read();
+
+            // Did we get it all in one read?
+            if (nextByte == -1) {
+                byte[] dest = new byte[count];
+                System.arraycopy(buffer, 0, dest, 0, count);
+                return dest;
+            }
+
+            // Requires additional reads
+            ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
+            baos.write(buffer, 0, count);
+            baos.write(nextByte);
+            while (true) {
+                count = is.read(buffer);
+                if (count == -1) {
+                    return baos.toByteArray();
+                }
+                baos.write(buffer, 0, count);
+            }
+        } finally {
+            is.close();
+        }
+    }
 
 }
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLExceptionTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLExceptionTest.java
index fa3213b..1d1f264 100644
--- a/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLExceptionTest.java
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLExceptionTest.java
Binary files differ
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLWarningTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLWarningTest.java
index 28e7944..24753fd 100644
--- a/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLWarningTest.java
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLWarningTest.java
Binary files differ
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/transaction/TransactionRequiredExceptionTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/transaction/TransactionRequiredExceptionTest.java
index 78f49a3..74cc55b 100644
--- a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/transaction/TransactionRequiredExceptionTest.java
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/transaction/TransactionRequiredExceptionTest.java
Binary files differ
diff --git a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/transaction/TransactionRolledbackExceptionTest.java b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/transaction/TransactionRolledbackExceptionTest.java
index c59c6e9..420699e 100644
--- a/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/transaction/TransactionRolledbackExceptionTest.java
+++ b/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/transaction/TransactionRolledbackExceptionTest.java
Binary files differ