Merge change I8c671e53

* changes:
  Implement ProcessBuilder.redirectErrorStream.
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/BreakIterator.java b/icu/src/main/java/com/ibm/icu4jni/text/BreakIterator.java
index c8f5372..5ef1161 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/BreakIterator.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/BreakIterator.java
@@ -22,10 +22,10 @@
 
 public abstract class BreakIterator implements Cloneable
 {
-    protected static int BI_CHAR_INSTANCE = 1;
-    protected static int BI_WORD_INSTANCE = 2;
-    protected static int BI_LINE_INSTANCE = 3;
-    protected static int BI_SENT_INSTANCE = 4;
+    protected static final int BI_CHAR_INSTANCE = 1;
+    protected static final int BI_WORD_INSTANCE = 2;
+    protected static final int BI_LINE_INSTANCE = 3;
+    protected static final int BI_SENT_INSTANCE = 4;
     
     protected int type = 0;
     
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/CollationKey.java b/icu/src/main/java/com/ibm/icu4jni/text/CollationKey.java
index 7e8a000..9e9401d 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/CollationKey.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/CollationKey.java
@@ -122,7 +122,7 @@
   {
     if (m_hash_ == 0)
     {
-      if (m_bytes_ != null || m_bytes_.length != 0) 
+      if (m_bytes_ != null && m_bytes_.length != 0)
       {                        
         int len = m_bytes_.length;
         int inc = ((len - 32) / 32) + 1;  
diff --git a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java
index 98463e4..ebda335 100644
--- a/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java
+++ b/icu/src/main/java/com/ibm/icu4jni/text/DecimalFormatSymbols.java
@@ -24,7 +24,7 @@
 import java.util.Locale;
 import java.util.ResourceBundle;
 
-public class DecimalFormatSymbols {
+public class DecimalFormatSymbols implements Cloneable {
     
     private int addr;
     
diff --git a/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java b/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
index a04dfd7..6773fd4 100644
--- a/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
@@ -577,9 +577,6 @@
             return netImpl.sendDatagram2(fd, buffer, offset, count, port,
                     address);
         }
-        // BEGIN android-changed
-        // call sendStream() instead of write()
-        return netImpl.sendStream(fd, buffer, offset, count);
-        // END android-changed
+        return netImpl.write(fd, buffer, offset, count);
     }
 }
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java b/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
index bf2effe..71a272a 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
@@ -126,11 +126,6 @@
     public void connectDatagram(FileDescriptor aFD, int port, int trafficClass,
             InetAddress inetAddress) throws SocketException;
 
-    // BEGIN android-added
-    public int sendStream(FileDescriptor fd, byte[] data, int offset, int count)
-            throws IOException;
-    // END android-added
-
     public void shutdownInput(FileDescriptor descriptor) throws IOException;
 
     public void shutdownOutput(FileDescriptor descriptor) throws IOException;
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java b/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
index f6f9e83..105cbf4 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
@@ -458,29 +458,8 @@
             DatagramPacket packet, int address, int offset, int length,
             int receiveTimeout, boolean peek) throws IOException;
 
-    // BEGIN android-added
     /**
-     * Send <code>count</code> bytes from the buffer <code>data</code> at
-     * the <code>offset</code>, on the socket.
-     *
-     * @param fd
-     *
-     * @param data the send buffer @param offset the offset into the buffer
-     * @param count the number of bytes to receive @return int the actual number
-     * of bytes sent @throws IOException @exception SocketException if an error
-     * occurs while writing
-     */
-    public int sendStream(FileDescriptor fd, byte[] data, int offset, int count)
-            throws IOException {
-        return sendStreamImpl(fd, data, offset, count);
-    }
-
-    static native int sendStreamImpl(FileDescriptor fd, byte[] data,
-            int offset, int count) throws IOException;
-    // END android-added
-
-    /**
-     * Recieve data on the connected socket into the specified buffer. The
+     * Receive data on the connected socket into the specified buffer. The
      * packet fields <code>data</code> and <code>length</code> are passed in
      * addition to <code>packet</code> to eliminate the JNI field access calls.
      *
diff --git a/luni/src/main/java/org/apache/harmony/luni/util/ErrorCodeException.java b/luni/src/main/java/org/apache/harmony/luni/util/ErrorCodeException.java
deleted file mode 100644
index 92258ef..0000000
--- a/luni/src/main/java/org/apache/harmony/luni/util/ErrorCodeException.java
+++ /dev/null
@@ -1,33 +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;
-
-public class ErrorCodeException extends Exception {
-
-    private static final long serialVersionUID = -8716868971626579265L;
-   
-    private int errorCode;
-  
-    public ErrorCodeException(int errorCode){
-        this.errorCode = errorCode;
-    }
-    
-    public int getErrorCode(){
-        return errorCode;
-    }
-
-}
diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
index 3390880..5020ada 100644
--- a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
+++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
@@ -1550,9 +1550,9 @@
     if (bytesReceived == 0) {
         return -1;
     } else if (bytesReceived == -1) {
-        if (errno == EWOULDBLOCK) {
+        if (errno == EAGAIN || errno == EWOULDBLOCK) {
             // We were asked to read a non-blocking socket with no data
-            // available, so report "no data".
+            // available, so report "no bytes read".
             return 0;
         } else {
             throwSocketException(env, convertError(errno));
@@ -1587,86 +1587,38 @@
         return 0;
     }
 
-    int handle;
-    if (!jniGetFd(env, fileDescriptor, handle)) {
+    int fd;
+    if (!jniGetFd(env, fileDescriptor, fd)) {
         return 0;
     }
 
     jbyte* message = reinterpret_cast<jbyte*>(static_cast<uintptr_t>(address + offset));
-    int result = send(handle, message, count, SOCKET_NOFLAGS);
-    if (result < 0) {
-        int err = convertError(errno);
-
-        if (SOCKERR_WOULDBLOCK == err){
-            jclass socketExClass,errorCodeExClass;
-            jmethodID errorCodeExConstructor, socketExConstructor,socketExCauseMethod;
-            jobject errorCodeEx, socketEx;
-            const char* errorMessage = netLookupErrorString(err);
-            jstring errorMessageString = env->NewStringUTF(errorMessage);
-
-            errorCodeExClass = env->FindClass("org/apache/harmony/luni/util/ErrorCodeException");
-            if (!errorCodeExClass){
-                return 0;
-            }
-            errorCodeExConstructor = env->GetMethodID(errorCodeExClass,"<init>","(I)V");
-            if (!errorCodeExConstructor){
-                return 0;
-            }
-            errorCodeEx = env->NewObject(errorCodeExClass,errorCodeExConstructor,err);
-
-            socketExClass = env->FindClass("java/net/SocketException");
-            if (!socketExClass) {
-                return 0;
-            }
-            socketExConstructor = env->GetMethodID(socketExClass,"<init>","(Ljava/lang/String;)V");
-            if (!socketExConstructor) {
-                return 0;
-            }
-            socketEx = env->NewObject(socketExClass, socketExConstructor, errorMessageString);
-            socketExCauseMethod = env->GetMethodID(socketExClass,"initCause","(Ljava/lang/Throwable;)Ljava/lang/Throwable;");
-            env->CallObjectMethod(socketEx,socketExCauseMethod,errorCodeEx);
-            env->Throw((jthrowable)socketEx);
+    int bytesSent = send(fd, message, count, SOCKET_NOFLAGS);
+    if (bytesSent == -1) {
+        if (errno == EAGAIN || errno == EWOULDBLOCK) {
+            // We were asked to write to a non-blocking socket, but were told
+            // it would block, so report "no bytes written".
+            return 0;
+        } else {
+            throwSocketException(env, convertError(errno));
             return 0;
         }
-        throwSocketException(env, err);
-        return 0;
     }
-
-    return result;
+    return bytesSent;
 }
 
 static jint osNetworkSystem_writeSocketImpl(JNIEnv* env, jclass clazz,
-        jobject fileDescriptor, jbyteArray data, jint offset, jint count) {
+        jobject fileDescriptor, jbyteArray byteArray, jint offset, jint count) {
     // LOGD("ENTER writeSocketImpl");
 
-    jbyte *message;
-    int sent = 0;
-    jint result = 0;
-
-/* TODO: ARRAY PINNING */
-#define INTERNAL_SEND_BUFFER_MAX 512
-    jbyte internalBuffer[INTERNAL_SEND_BUFFER_MAX];
-
-    if (count > INTERNAL_SEND_BUFFER_MAX) {
-        message = (jbyte*)malloc(count * sizeof( jbyte));
-        if (message == NULL) {
-            jniThrowException(env, "java/lang/OutOfMemoryError",
-                    "couldn't allocate enough memory for writeSocket");
-            return 0;
-        }
-    } else {
-        message = (jbyte *)internalBuffer;
+    jbyte* bytes = env->GetByteArrayElements(byteArray, NULL);
+    if (bytes == NULL) {
+        return -1;
     }
-
-    env->GetByteArrayRegion(data, offset, count, message);
-
-    result = osNetworkSystem_writeSocketDirectImpl(env, clazz, fileDescriptor,
-            (jint) message, 0, count);
-
-    if (( jbyte *)message != internalBuffer) {
-        free(( jbyte *)message);
-    }
-#undef INTERNAL_SEND_BUFFER_MAX
+    jint address = static_cast<jint>(reinterpret_cast<uintptr_t>(bytes));
+    int result = osNetworkSystem_writeSocketDirectImpl(env, clazz,
+            fileDescriptor, address, offset, count);
+    env->ReleaseByteArrayElements(byteArray, bytes, 0);
     return result;
 }
 
@@ -2317,41 +2269,6 @@
     setsockopt(handle, SOL_SOCKET, SO_REUSEADDR, &value, sizeof(int));
 }
 
-static jint osNetworkSystem_sendStreamImpl(JNIEnv* env, jclass clazz,
-        jobject fileDescriptor, jbyteArray data, jint offset, jint count) {
-    // LOGD("ENTER sendStreamImpl");
-
-    int fd;
-    if (!jniGetFd(env, fileDescriptor, fd)) {
-        return 0;
-    }
-
-    // Cap write length to available buf size
-    int spaceAvailable = env->GetArrayLength(data) - offset;
-    if (count > spaceAvailable) count = spaceAvailable;
-
-    int sent = 0;
-    jbyte* message = env->GetByteArrayElements(data, NULL);
-    while (sent < count) {
-        // LOGD("before select %d", count);
-        selectWait(fd, SEND_RETRY_TIME, SELECT_WRITE_TYPE);
-        int result = send(fd, message + offset + sent, count - sent,
-                SOCKET_NOFLAGS);
-        if (result == -1) {
-            if (errno == EAGAIN || errno == EWOULDBLOCK) {
-                // LOGD("write blocked %d", sent);
-                continue;
-            }
-            throwSocketException(env, convertError(errno));
-            env->ReleaseByteArrayElements(data, message, 0);
-            return 0;
-        }
-        sent += result;
-    }
-    env->ReleaseByteArrayElements(data, message, 0);
-    return sent;
-}
-
 static void doShutdown(JNIEnv* env, jobject fileDescriptor, int how) {
     int fd;
     if (!jniGetFd(env, fileDescriptor, fd)) {
@@ -3289,7 +3206,6 @@
     { "sendConnectedDatagramImpl",         "(Ljava/io/FileDescriptor;[BIIZ)I",                                         (void*) osNetworkSystem_sendConnectedDatagramImpl          },
     { "sendConnectedDatagramDirectImpl",   "(Ljava/io/FileDescriptor;IIIZ)I",                                          (void*) osNetworkSystem_sendConnectedDatagramDirectImpl    },
     { "createServerStreamSocketImpl",      "(Ljava/io/FileDescriptor;Z)V",                                             (void*) osNetworkSystem_createServerStreamSocketImpl       },
-    { "sendStreamImpl",                    "(Ljava/io/FileDescriptor;[BII)I",                                          (void*) osNetworkSystem_sendStreamImpl                     },
     { "shutdownInputImpl",                 "(Ljava/io/FileDescriptor;)V",                                              (void*) osNetworkSystem_shutdownInputImpl                  },
     { "shutdownOutputImpl",                "(Ljava/io/FileDescriptor;)V",                                              (void*) osNetworkSystem_shutdownOutputImpl                 },
     { "sendDatagramImpl2",                 "(Ljava/io/FileDescriptor;[BIIILjava/net/InetAddress;)I",                   (void*) osNetworkSystem_sendDatagramImpl2                  },
diff --git a/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java b/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
index 513b54c..109a819 100644
--- a/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
+++ b/nio/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
@@ -45,7 +45,7 @@
 import org.apache.harmony.luni.platform.FileDescriptorHandler;
 import org.apache.harmony.luni.platform.INetworkSystem;
 import org.apache.harmony.luni.platform.Platform;
-import org.apache.harmony.luni.util.ErrorCodeException;
+//import org.apache.harmony.luni.util.ErrorCodeException; android-removed
 import org.apache.harmony.nio.AddressUtil;
 
 /*
@@ -61,7 +61,7 @@
     // default timeout used to nonblocking mode.
     private static final int DEFAULT_TIMEOUT = 1;
 
-    private static final int ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK = -211;
+    // android-removed: private static final int ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK = -211;
 
     private static final byte[] stubArray = new byte[0];
 
@@ -629,14 +629,7 @@
                             .array(), start, length, isBound);
                 }
                 return result;
-            } catch (SocketException e) {
-                if (e.getCause() instanceof ErrorCodeException) {
-                    if (ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK == ((ErrorCodeException) e
-                            .getCause()).getErrorCode()) {
-                        return result;
-                    }
-                }
-                throw e;
+                // android-removed: bogus catch (SocketException e) and use of ErrorCodeException.
             } finally {
                 end(result > 0);
             }
diff --git a/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java b/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
index be9ab9e..cf6d839 100644
--- a/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
+++ b/nio/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
@@ -50,7 +50,7 @@
 import org.apache.harmony.luni.platform.FileDescriptorHandler;
 import org.apache.harmony.luni.platform.INetworkSystem;
 import org.apache.harmony.luni.platform.Platform;
-import org.apache.harmony.luni.util.ErrorCodeException;
+//import org.apache.harmony.luni.util.ErrorCodeException; android-removed
 import org.apache.harmony.luni.util.Msg;
 import org.apache.harmony.nio.AddressUtil;
 import org.apache.harmony.nio.internal.nls.Messages;
@@ -62,7 +62,7 @@
 
     private static final int EOF = -1;
 
-    private static final int ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK = -211;
+    // android-removed: private static final int ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK = -211;
 
     // The singleton to do the native network operation.
     static final INetworkSystem networkSystem = Platform.getNetworkSystem();
@@ -569,14 +569,7 @@
                     writeCount = networkSystem.write(fd, array, 0, length);
                 }
                 source.position(pos + writeCount);
-            } catch (SocketException e) {
-                if (e.getCause() instanceof ErrorCodeException) {
-                    if (ERRCODE_SOCKET_NONBLOCKING_WOULD_BLOCK == ((ErrorCodeException) e
-                            .getCause()).getErrorCode()) {
-                        return writeCount;
-                    }
-                }
-                throw e;
+                // android-removed: bogus catch (SocketException e) and use of ErrorCodeException.
             } finally {
                 if (isBlocking()) {
                     end(writeCount >= 0);
diff --git a/xml/src/main/java/org/xmlpull/v1/XmlPullParserFactory.java b/xml/src/main/java/org/xmlpull/v1/XmlPullParserFactory.java
index 7b786f6..7814651 100644
--- a/xml/src/main/java/org/xmlpull/v1/XmlPullParserFactory.java
+++ b/xml/src/main/java/org/xmlpull/v1/XmlPullParserFactory.java
@@ -252,6 +252,7 @@
     public static XmlPullParserFactory newInstance (String classNames, Class context)
         throws XmlPullParserException {
 
+        /*
         if (context == null) {
             //NOTE: make sure context uses the same class loader as API classes
             //      this is the best we can do without having access to context classloader in J2ME
@@ -259,7 +260,6 @@
             context = referenceContextClass;
         }
 
-        /*
         String  classNamesLocation = null;
 
         if (classNames == null || classNames.length() == 0 || "DEFAULT".equals(classNames)) {
@@ -345,5 +345,3 @@
         return factory;
     }
 }
-
-