harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r727683 [3/11] - in /harmony/enhanced/classlib/branches/java6: ./ doc/ make/ modules/accessibility/src/main/java/javax/accessibility/ modules/archive/src/main/java/java/util/jar/ modules/archive/src/main/java/java/util/zip/ modules/archive/...
Date Thu, 18 Dec 2008 09:46:26 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Hashtable.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Hashtable.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Hashtable.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/java/util/Hashtable.java Thu Dec 18 01:46:12 2008
@@ -67,6 +67,21 @@
         }
     };
 
+    private static final Iterator<?> EMPTY_ITERATOR = new Iterator<Object>() {
+
+        public boolean hasNext() {
+            return false;
+        }
+
+        public Object next() {
+            throw new NoSuchElementException();
+        }
+
+        public void remove() {
+            throw new IllegalStateException();
+        }
+    };
+
     private static <K, V> Entry<K, V> newEntry(K key, V value, int hash) {
         return new Entry<K, V>(key, value);
     }
@@ -115,16 +130,16 @@
         }
     }
 
-    private final class HashIterator<E> implements Iterator<E> {
-        private int position, expectedModCount;
+    private class HashIterator<E> implements Iterator<E> {
+        int position, expectedModCount;
 
-        private final MapEntry.Type<E, K, V> type;
+        final MapEntry.Type<E, K, V> type;
 
-        private Entry<K, V> lastEntry;
+        Entry<K, V> lastEntry;
 
-        private int lastPosition;
+        int lastPosition;
 
-        private boolean canRemove = false;
+        boolean canRemove = false;
 
         HashIterator(MapEntry.Type<E, K, V> value) {
             type = value;
@@ -212,42 +227,6 @@
         }
     }
 
-    private final class HashEnumerator<E> implements Enumeration<E> {
-        boolean key;
-
-        int start;
-
-        Entry<K, V> entry;
-
-        HashEnumerator(boolean isKey) {
-            key = isKey;
-            start = lastSlot + 1;
-        }
-
-        public boolean hasMoreElements() {
-            if (entry != null) {
-                return true;
-            }
-            while (start > firstSlot) {
-                if (elementData[--start] != null) {
-                    entry = elementData[start];
-                    return true;
-                }
-            }
-            return false;
-        }
-
-        @SuppressWarnings("unchecked")
-        public E nextElement() {
-            if (hasMoreElements()) {
-                Object result = key ? entry.key : entry.value;
-                entry = entry.next;
-                return (E) result;
-            }
-            throw new NoSuchElementException();
-        }
-    }
-
     /**
      * Constructs a new Hashtable using the default capacity and load factor.
      */
@@ -426,7 +405,11 @@
         if (elementCount == 0) {
             return (Enumeration<V>) EMPTY_ENUMERATION;
         }
-        return new HashEnumerator<V>(false);
+        return new HashEnumIterator<V>(new MapEntry.Type<V, K, V>() {
+            public V get(MapEntry<K, V> entry) {
+                return entry.value;
+            }
+        }, true);
     }
 
     /**
@@ -605,7 +588,11 @@
         if (elementCount == 0) {
             return (Enumeration<K>) EMPTY_ENUMERATION;
         }
-        return new HashEnumerator<K>(true);
+        return new HashEnumIterator<K>(new MapEntry.Type<K, K, V>() {
+            public K get(MapEntry<K, V> entry) {
+                return entry.key;
+            }
+        }, true);
     }
 
     /**
@@ -643,7 +630,10 @@
 
             @Override
             public Iterator<K> iterator() {
-                return new HashIterator<K>(new MapEntry.Type<K, K, V>() {
+                if (this.size() == 0) {
+                    return (Iterator<K>) EMPTY_ITERATOR;
+                }
+                return new HashEnumIterator<K>(new MapEntry.Type<K, K, V>() {
                     public K get(MapEntry<K, V> entry) {
                         return entry.key;
                     }
@@ -652,6 +642,84 @@
         }, this);
     }
 
+    class HashEnumIterator<E> extends HashIterator<E> implements Enumeration<E> {
+
+        private boolean isEnumeration = false;
+
+        int start;
+
+        Entry<K, V> entry;
+
+        HashEnumIterator(MapEntry.Type<E, K, V> value) {
+            super(value);
+        }
+
+        HashEnumIterator(MapEntry.Type<E, K, V> value, boolean isEnumeration) {
+            super(value);
+            this.isEnumeration = isEnumeration;
+            start = lastSlot + 1;
+        }
+
+        public boolean hasMoreElements() {
+            if (isEnumeration) {
+                if (entry != null) {
+                    return true;
+                }
+                while (start > firstSlot) {
+                    if (elementData[--start] != null) {
+                        entry = elementData[start];
+                        return true;
+                    }
+                }
+                return false;
+            }
+            // iterator
+            return super.hasNext();
+        }
+
+        public boolean hasNext() {
+            if (isEnumeration) {
+                return hasMoreElements();
+            }
+            // iterator
+            return super.hasNext();
+        }
+
+        public E next() {
+            if (isEnumeration) {
+                if (expectedModCount == modCount) {
+                    return nextElement();
+                } else {
+                    throw new ConcurrentModificationException();
+                }
+            }
+            // iterator
+            return super.next();
+        }
+
+        @SuppressWarnings("unchecked")
+        public E nextElement() {
+            if (isEnumeration) {
+                if (hasMoreElements()) {
+                    Object result = type.get(entry);
+                    entry = entry.next;
+                    return (E) result;
+                }
+                throw new NoSuchElementException();
+            }
+            // iterator
+            return super.next();
+        }
+
+        public void remove() {
+            if (isEnumeration) {
+                throw new UnsupportedOperationException();
+            } else {
+                super.remove();
+            }
+        }
+    }
+
     /**
      * Associate the specified value with the specified key in this Hashtable.
      * If the key already exists, the old value is replaced. The key and value

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java Thu Dec 18 01:46:12 2008
@@ -42,7 +42,7 @@
  * support security checks. Alternative types of DatagramSocketImpl's may be
  * used by setting the <code>impl.prefix</code> system property.
  */
-class PlainDatagramSocketImpl extends DatagramSocketImpl {
+public class PlainDatagramSocketImpl extends DatagramSocketImpl {
 
     static final int MULTICAST_IF = 1;
 
@@ -70,7 +70,8 @@
      */
     static final int REUSEADDR_AND_REUSEPORT = 10001;
 
-    private boolean bindToDevice;
+    // Ignored in native code
+    private boolean bindToDevice = false;
 
     private byte[] ipaddress = { 0, 0, 0, 0 };
 
@@ -116,7 +117,7 @@
     public void bind(int port, InetAddress addr) throws SocketException {
         String prop = AccessController.doPrivileged(new PriviAction<String>("bindToDevice")); //$NON-NLS-1$
         boolean useBindToDevice = prop != null && prop.toLowerCase().equals("true"); //$NON-NLS-1$
-        bindToDevice = netImpl.bind2(fd, port, useBindToDevice, addr);
+        netImpl.bind(fd, addr, port);
         if (0 != port) {
             localPort = port;
         } else {

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java Thu Dec 18 01:46:12 2008
@@ -43,7 +43,7 @@
 /**
  * A concrete connected-socket implementation.
  */
-class PlainSocketImpl extends SocketImpl {
+public class PlainSocketImpl extends SocketImpl {
 
     // Const copy from socket
 
@@ -89,6 +89,27 @@
         fd = new FileDescriptor();
     }
 
+    public PlainSocketImpl(FileDescriptor fd) {
+        super();
+        this.fd = fd;
+    }
+    
+    /**
+     * creates an instance with specified proxy.
+     */
+    public PlainSocketImpl(Proxy proxy) {
+        this();
+        this.proxy = proxy;
+    }
+    
+    public PlainSocketImpl(FileDescriptor fd, int localport, InetAddress addr, int port) {
+        super();
+        this.fd = fd;
+        this.localport = localport;
+        this.address = addr;
+        this.port = port;
+    }
+    
     @Override
     protected void accept(SocketImpl newImpl) throws IOException {
         if (NetUtil.usingSocks(proxy)) {
@@ -154,7 +175,7 @@
 
     @Override
     protected void bind(InetAddress anAddr, int aPort) throws IOException {
-        netImpl.bind(fd, aPort, anAddr);
+        netImpl.bind(fd, anAddr, aPort);
         // PlainSocketImpl2.socketBindImpl2(fd, aPort, anAddr);
         address = anAddr;
         if (0 != aPort) {
@@ -207,9 +228,8 @@
      */
     private void connect(InetAddress anAddr, int aPort, int timeout)
             throws IOException {
-        InetAddress normalAddr = anAddr.isAnyLocalAddress() ? InetAddress
-                .getLocalHost() : anAddr;
-
+        
+        InetAddress normalAddr = anAddr.isAnyLocalAddress() ? InetAddress.getLocalHost() : anAddr;
         try {
             if (streaming) {
                 if (NetUtil.usingSocks(proxy)) {
@@ -534,16 +554,16 @@
         if (shutdownInput) {
             return -1;
         }
-        try {
-            int read = netImpl.receiveStream(fd, buffer, offset, count,
-                    receiveTimeout);
-            if (read == -1) {
-                shutdownInput = true;
-            }
-            return read;
-        } catch (InterruptedIOException e) {
-            throw new SocketTimeoutException(e.getMessage());
+        int read = netImpl.read(fd, buffer, offset, count, receiveTimeout);
+        // Return of zero bytes for a blocking socket means a timeout occurred
+        if (read == 0) {
+            throw new SocketTimeoutException();
+        }
+        // Return of -1 indicates the peer was closed
+        if (read == -1) {
+            shutdownInput = true;
         }
+        return read;
     }
 
     int write(byte[] buffer, int offset, int count) throws IOException {
@@ -551,6 +571,6 @@
             return netImpl.sendDatagram2(fd, buffer, offset, count, port,
                     address);
         }
-        return netImpl.sendStream(fd, buffer, offset, count);
+        return netImpl.write(fd, buffer, offset, count);
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java Thu Dec 18 01:46:12 2008
@@ -25,7 +25,7 @@
  * TODO Type description
  * 
  */
-public interface IFileSystem extends ISystemComponent {
+public interface IFileSystem {
 
 	public final int SHARED_LOCK_TYPE = 1;
 

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java Thu Dec 18 01:46:12 2008
@@ -47,15 +47,9 @@
 	public void accept(FileDescriptor fdServer, SocketImpl newSocket,
 			FileDescriptor fdnewSocket, int timeout) throws IOException;
 
-	public void bind(FileDescriptor aFD, int port, InetAddress inetAddress)
+	public void bind(FileDescriptor aFD, InetAddress inetAddress, int port)
 			throws SocketException;
 
-	public boolean bind2(FileDescriptor aFD, int port, boolean bindToDevice,
-			InetAddress inetAddress) throws SocketException;
-
-	public void createSocket(FileDescriptor fd, boolean preferIPv4Stack)
-			throws IOException;
-
 	public int read(FileDescriptor aFD, byte[] data, int offset, int count,
 			int timeout) throws IOException;
     
@@ -119,18 +113,13 @@
 	public void connectDatagram(FileDescriptor aFD, int port, int trafficClass,
 			InetAddress inetAddress) throws SocketException;
 
-	public void createMulticastSocket(FileDescriptor aFD,
-			boolean preferIPv4Stack) throws SocketException;
-
-	public void createServerStreamSocket(FileDescriptor aFD,
-			boolean preferIPv4Stack) throws SocketException;
-
+	/**
+	 * @deprecated Use {@link #read(FileDescriptor, byte[], int, int, int)}
+	 */
+	@Deprecated
 	public int receiveStream(FileDescriptor aFD, byte[] data, int offset,
 			int count, int timeout) throws IOException;
 
-	public int sendStream(FileDescriptor fd, byte[] data, int offset, int count)
-			throws IOException;
-
 	public void shutdownInput(FileDescriptor descriptor) throws IOException;
 
 	public void shutdownOutput(FileDescriptor descriptor) throws IOException;

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSFileSystem.java Thu Dec 18 01:46:12 2008
@@ -25,12 +25,15 @@
  * This is the portable implementation of the file system interface.
  * 
  */
-class OSFileSystem extends OSComponent implements IFileSystem {
+class OSFileSystem implements IFileSystem {
 
-	/**
-	 * 
-	 */
-	public OSFileSystem() {
+    private static final OSFileSystem singleton = new OSFileSystem();
+
+    public static OSFileSystem getOSFileSystem() {
+        return singleton;
+    }
+
+    private OSFileSystem() {
 		super();
 	}
 

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java Thu Dec 18 01:46:12 2008
@@ -39,7 +39,7 @@
  * above.
  * </p>
  */
-final class OSMemory extends OSComponent implements IMemorySystem {
+final class OSMemory implements IMemorySystem {
 
 	/**
 	 * Defines the size, in bytes, of a native pointer type for the underlying
@@ -70,11 +70,11 @@
 	}
 
 	/**
-	 * This class is not designed to be publically instantiated.
+	 * This class is not designed to be publicly instantiated.
 	 * 
 	 * @see #getOSMemory()
 	 */
-	OSMemory() {
+	private OSMemory() {
 		super();
 	}
 

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSNetworkSystem.java Thu Dec 18 01:46:12 2008
@@ -26,249 +26,304 @@
 import java.net.UnknownHostException;
 import java.nio.channels.Channel;
 
-/*
- * 
- * This Class is used for native code wrap, the implement class of
- * INetworkSystem.
- * 
+/**
+ * This wraps native code that implements the INetworkSystem interface.
  */
 final class OSNetworkSystem implements INetworkSystem {
 
-	// ----------------------------------------------------
-	// Class Variables
-	// ----------------------------------------------------
+    private static final int ERRORCODE_SOCKET_TIMEOUT = -209;
 
-	private static final int ERRORCODE_SOCKET_TIMEOUT = -209;
-
-	private static OSNetworkSystem ref = new OSNetworkSystem();
-    
     private static final int INETADDR_REACHABLE = 0;
-    
+
     private static boolean isNetworkInited = false;
-    
 
-	// ----------------------------------------------------
-	// Class Constructor
-	// ----------------------------------------------------
-
-	// can not be instantiated.
-	private OSNetworkSystem() {
-		super();
-	}
-
-	/*
-	 * @return a static ref of this class
-	 */
-	public static OSNetworkSystem getOSNetworkSystem() {
-		return ref;
-	}
-
-	// --------------------------------------------------
-	// java codes that wrap native codes
-	// --------------------------------------------------
-
-	public void createSocket(FileDescriptor fd, boolean preferIPv4Stack)
-			throws IOException {
-		createSocketImpl(fd, preferIPv4Stack);
-	}
-
-	public void createDatagramSocket(FileDescriptor fd, boolean preferIPv4Stack)
-			throws SocketException {
-		createDatagramSocketImpl(fd, preferIPv4Stack);
-	}
-
-	public int read(FileDescriptor aFD, byte[] data, int offset, int count,
-			int timeout) throws IOException {
-		return readSocketImpl(aFD, data, offset, count, timeout);
-	}
-    
-    public int readDirect(FileDescriptor aFD, long address, int count,
-            int timeout) throws IOException {
-        return readSocketDirectImpl(aFD, address, count, timeout);
-    }
+    private static OSNetworkSystem singleton = new OSNetworkSystem();
 
-	public int write(FileDescriptor aFD, byte[] data, int offset, int count)
-			throws IOException {
-		return writeSocketImpl(aFD, data, offset, count);
-	}
-    
-    public int writeDirect(FileDescriptor aFD, long address, int count)
-            throws IOException {
-        return writeSocketDirectImpl(aFD, address, count);
+    /**
+     * Answers the unique instance of the OSNetworkSystem.
+     * 
+     * @return the network system interface instance
+     */
+    public static OSNetworkSystem getOSNetworkSystem() {
+        return singleton;
     }
 
-	public void setNonBlocking(FileDescriptor aFD, boolean block)
-			throws IOException {
-		setNonBlockingImpl(aFD, block);
-	}
-
-	public void connectDatagram(FileDescriptor aFD, int port, int trafficClass,
-			InetAddress inetAddress) throws SocketException {
-		connectDatagramImpl2(aFD, port, trafficClass, inetAddress);
-	}
-
-	public int connect(FileDescriptor aFD, int trafficClass,
-			InetAddress inetAddress, int port)  throws IOException{
-		return connectSocketImpl(aFD, trafficClass, inetAddress, port);
-	}
-
-	public int connectWithTimeout(FileDescriptor aFD, int timeout,
-			int trafficClass, InetAddress inetAddress, int port, int step,
-			Long context)  throws IOException{
-		return connectWithTimeoutSocketImpl(aFD, timeout, trafficClass,
-				inetAddress, port, step, context);
-	}
-
-	public void connectStreamWithTimeoutSocket(FileDescriptor aFD, int aport,
-			int timeout, int trafficClass, InetAddress inetAddress)
-			throws IOException {
-		connectStreamWithTimeoutSocketImpl(aFD, aport, timeout, trafficClass,
-				inetAddress);
-	}
-
-	public void bind(FileDescriptor aFD, int port, InetAddress inetAddress)
-			throws SocketException {
-		socketBindImpl(aFD, port, inetAddress);
-	}
-
-	public boolean bind2(FileDescriptor aFD, int port, boolean bindToDevice,
-			InetAddress inetAddress) throws SocketException {
-		return socketBindImpl2(aFD, port, bindToDevice, inetAddress);
-	}
-
-	public void accept(FileDescriptor fdServer, SocketImpl newSocket,
-			FileDescriptor fdnewSocket, int timeout) throws IOException {
-		acceptSocketImpl(fdServer, newSocket, fdnewSocket, timeout);
-	}
-
-	public int sendDatagram(FileDescriptor fd, byte[] data, int offset,
-			int length, int port, boolean bindToDevice, int trafficClass,
-			InetAddress inetAddress) throws IOException {
-		return sendDatagramImpl(fd, data, offset, length, port, bindToDevice,
-				trafficClass, inetAddress);
-	}
-    
-    public int sendDatagramDirect(FileDescriptor fd, long address, int offset,
-            int length, int port, boolean bindToDevice, int trafficClass,
-            InetAddress inetAddress) throws IOException {
-        return sendDatagramDirectImpl(fd, address, offset, length, port, bindToDevice,
-                trafficClass, inetAddress);
+    // Can not be instantiated.
+    private OSNetworkSystem() {
+        super();
     }
 
-	public int sendDatagram2(FileDescriptor fd, byte[] data, int offset,
-			int length, int port, InetAddress inetAddress) throws IOException {
-		return sendDatagramImpl2(fd, data, offset, length, port, inetAddress);
-	}
+    public native void accept(FileDescriptor fdServer, SocketImpl newSocket,
+            FileDescriptor fdnewSocket, int timeout) throws IOException;
 
-	public int receiveDatagram(FileDescriptor aFD, DatagramPacket packet,
-            byte[] data, int offset, int length, int receiveTimeout,
-            boolean peek) throws IOException {
-        return receiveDatagramImpl(aFD, packet, data, offset, length,
-                receiveTimeout, peek);
-    }
-    
-    public int receiveDatagramDirect(FileDescriptor aFD, DatagramPacket packet,
-            long address, int offset, int length, int receiveTimeout,
-            boolean peek) throws IOException {
-        return receiveDatagramDirectImpl(aFD, packet, address, offset, length,
-                receiveTimeout, peek);
-    }
+    public native void acceptStreamSocket(FileDescriptor fdServer,
+            SocketImpl newSocket, FileDescriptor fdnewSocket, int timeout)
+            throws IOException;
 
-	public int recvConnectedDatagram(FileDescriptor aFD, DatagramPacket packet,
-			byte[] data, int offset, int length, int receiveTimeout,
-			boolean peek) throws IOException {
-		return recvConnectedDatagramImpl(aFD, packet, data, offset, length,
-				receiveTimeout, peek);
-	}
-    
-    public int recvConnectedDatagramDirect(FileDescriptor aFD, DatagramPacket packet, long address,
-             int offset, int length, int receiveTimeout, boolean peek)
-            throws IOException {
-        return recvConnectedDatagramDirectImpl(aFD, packet, address, offset, length, receiveTimeout, peek);
-    }
+    public native int availableStream(FileDescriptor fd) throws SocketException;
 
-	public int peekDatagram(FileDescriptor aFD, InetAddress sender,
-			int receiveTimeout) throws IOException {
-		return peekDatagramImpl(aFD, sender, receiveTimeout);
-	}
-
-	public int sendConnectedDatagram(FileDescriptor fd, byte[] data,
-			int offset, int length, boolean bindToDevice) throws IOException {
-		return sendConnectedDatagramImpl(fd, data, offset, length, bindToDevice);
-	}
-    
-    public int sendConnectedDatagramDirect(FileDescriptor fd, long address,
-            int offset, int length, boolean bindToDevice) throws IOException {
-        return sendConnectedDatagramDirectImpl(fd, address, offset, length, bindToDevice);
-    }
+    /**
+     * Associates a local address with a socket.
+     * 
+     * @param fd
+     *            the socket descriptor
+     * @param port
+     *            the port number
+     * @param inetAddress
+     *            address to bind
+     * @throws SocketException
+     *             thrown if bind operation fails
+     */
+    public native void bind(FileDescriptor fd, InetAddress inetAddress, int port) throws SocketException;
+
+    public native int connect(FileDescriptor fd, int trafficClass,
+            InetAddress inetAddress, int port) throws IOException;
+
+    public native void connectDatagram(FileDescriptor fd, int port,
+            int trafficClass, InetAddress inetAddress) throws SocketException;
+
+    public native void connectStreamWithTimeoutSocket(FileDescriptor aFD,
+            int aport, int timeout, int trafficClass, InetAddress inetAddress)
+            throws IOException;
+
+    public native int connectWithTimeout(FileDescriptor fd, int timeout,
+            int trafficClass, InetAddress inetAddress, int port, int step,
+            Long context) throws IOException;
+
+    public native void createDatagramSocket(FileDescriptor fd,
+            boolean preferIPv4Stack) throws SocketException;
+
+    public native void createStreamSocket(FileDescriptor fd,
+            boolean preferIPv4Stack) throws SocketException;
+
+    /**
+     * Disconnect the socket to a port and address
+     * 
+     * @param fd
+     *            the FileDescriptor associated with the socket
+     * 
+     * @throws SocketException
+     *             if the disconnect fails
+     */
+    public native void disconnectDatagram(FileDescriptor fd)
+            throws SocketException;
+
+    public native InetAddress getHostByAddr(byte[] addr)
+            throws UnknownHostException;
+
+    public native InetAddress getHostByName(String addr,
+            boolean preferIPv6Addresses) throws UnknownHostException;
+
+    public native int getSocketFlags();
+
+    public native InetAddress getSocketLocalAddress(FileDescriptor fd,
+            boolean preferIPv6Addresses);
+
+    /**
+     * Query the IP stack for the local port to which this socket is bound.
+     * 
+     * @param aFD
+     *            the socket descriptor
+     * @param preferIPv6Addresses
+     *            address preference for nodes that support both IPv4 and IPv6
+     * @return the local port to which the socket is bound
+     */
+    public native int getSocketLocalPort(FileDescriptor aFD,
+            boolean preferIPv6Addresses);
+
+    /**
+     * Query the IP stack for the nominated socket option.
+     * 
+     * @param fd
+     *            the socket descriptor
+     * @param opt
+     *            the socket option type
+     * @return the nominated socket option value
+     * @throws SocketException
+     *             if the option is invalid
+     */
+    public native Object getSocketOption(FileDescriptor fd, int opt)
+            throws SocketException;
+
+    public native Channel inheritedChannel();
 
-	public void disconnectDatagram(FileDescriptor aFD) throws SocketException {
-		disconnectDatagramImpl(aFD);
-	}
-
-	public void createMulticastSocket(FileDescriptor aFD,
-			boolean preferIPv4Stack) throws SocketException {
-		createMulticastSocketImpl(aFD, preferIPv4Stack);
-	}
-
-	public void createServerStreamSocket(FileDescriptor aFD,
-			boolean preferIPv4Stack) throws SocketException {
-		createServerStreamSocketImpl(aFD, preferIPv4Stack);
-	}
-
-	public int receiveStream(FileDescriptor aFD, byte[] data, int offset,
-			int count, int timeout) throws IOException {
-		return receiveStreamImpl(aFD, data, offset, count, timeout);
-	}
-
-	public int sendStream(FileDescriptor fd, byte[] data, int offset, int count)
-			throws IOException {
-		return sendStreamImpl(fd, data, offset, count);
-	}
-
-	public void shutdownInput(FileDescriptor descriptor) throws IOException {
-		shutdownInputImpl(descriptor);
-	}
-
-	public void shutdownOutput(FileDescriptor descriptor) throws IOException {
-		shutdownOutputImpl(descriptor);
-	}
-
-	public boolean supportsUrgentData(FileDescriptor fd) {
-		return supportsUrgentDataImpl(fd);
-	}
-
-	public void sendUrgentData(FileDescriptor fd, byte value) {
-		sendUrgentDataImpl(fd, value);
-	}
-
-	public int availableStream(FileDescriptor aFD) throws SocketException {
-		return availableStreamImpl(aFD);
-	}
-
-	public void acceptStreamSocket(FileDescriptor fdServer,
-			SocketImpl newSocket, FileDescriptor fdnewSocket, int timeout)
-			throws IOException {
-		acceptStreamSocketImpl(fdServer, newSocket, fdnewSocket, timeout);
-	}
-
-	public void createStreamSocket(FileDescriptor aFD, boolean preferIPv4Stack)
-			throws SocketException {
-		createStreamSocketImpl(aFD, preferIPv4Stack);
-	}
-
-	public void listenStreamSocket(FileDescriptor aFD, int backlog)
-			throws SocketException {
-		listenStreamSocketImpl(aFD, backlog);
-	}
-    
     public boolean isReachableByICMP(final InetAddress dest,
             InetAddress source, final int ttl, final int timeout) {
         return INETADDR_REACHABLE == isReachableByICMPImpl(dest, source, ttl,
                 timeout);
     }
 
-	/**
+    private native int isReachableByICMPImpl(InetAddress addr,
+            InetAddress local, int ttl, int timeout);
+
+    public native void listenStreamSocket(FileDescriptor aFD, int backlog)
+            throws SocketException;
+
+    public void oneTimeInitialization(boolean jcl_supports_ipv6) {
+        if (!isNetworkInited) {
+            oneTimeInitializationImpl(jcl_supports_ipv6);
+            isNetworkInited = true;
+        }
+    }
+
+    private native void oneTimeInitializationImpl(boolean jcl_supports_ipv6);
+
+    /**
+     * Peek on the socket, update <code>sender</code> address and answer the
+     * sender port.
+     * 
+     * @param fd
+     *            the socket FileDescriptor
+     * @param sender
+     *            an InetAddress, to be updated with the sender's address
+     * @param receiveTimeout
+     *            the maximum length of time the socket should block, reading
+     * @return the sender port
+     * 
+     * @throws IOException
+     *             upon an read error or timeout
+     */
+    public native int peekDatagram(FileDescriptor fd, InetAddress sender,
+            int receiveTimeout) throws IOException;
+
+    /**
+     * Read available bytes from the given file descriptor into a byte array.
+     * 
+     * The read has an optional timeout parameter, which if non-zero is the
+     * length of time that the read will wait on a select call to see if any
+     * bytes are available for reading. If the timeout expires the method
+     * returns zero to indicate no bytes were read.
+     * 
+     * @param fd
+     *            the socket file descriptor to read
+     * @param data
+     *            the byte array in which to store the results
+     * @param offset
+     *            the offset into the byte array in which to start reading the
+     *            results
+     * @param count
+     *            the maximum number of bytes to read
+     * @param timeout
+     *            the length of time to wait for the bytes, in milliseconds; or
+     *            zero to indicate no timeout applied. When there is no timeout
+     *            applied the read may block based upon socket options.
+     * @return number of bytes read, or zero if there were no bytes available
+     *         before the timeout occurred, or -1 to indicate the socket is
+     *         closed
+     * @throws IOException
+     *             if an underlying socket exception occurred
+     */
+    public native int read(FileDescriptor fd, byte[] data, int offset,
+            int count, int timeout) throws IOException;
+
+    /**
+     * Read available bytes from the given file descriptor into OS memory at a
+     * given address.
+     * 
+     * @param fd
+     *            the socket file descriptor to read
+     * @param address
+     *            the address of the memory in which to store the results
+     * @param count
+     *            the maximum number of bytes to read
+     * @param timeout
+     *            the length of time to wait for the bytes, in milliseconds
+     * @return number of bytes read, or zero if there were no bytes available
+     *         before the timeout occurred, or -1 to indicate the socket is
+     *         closed
+     * @throws IOException
+     *             if an underlying socket exception occurred
+     */
+    public native int readDirect(FileDescriptor fd, long address, int count,
+            int timeout) throws IOException;
+
+    /**
+     * Receive data on the socket into the specified buffer. The packet fields
+     * <code>data</code> & <code>length</code> are passed in addition to
+     * <code>packet</code> to eliminate the JNI field access calls.
+     * 
+     * @param fd
+     *            the socket FileDescriptor
+     * @param packet
+     *            the DatagramPacket to receive into
+     * @param data
+     *            the data buffer of the packet
+     * @param offset
+     *            the offset in the data buffer
+     * @param length
+     *            the length of the data buffer in the packet
+     * @param receiveTimeout
+     *            the maximum length of time the socket should block, reading
+     * @param peek
+     *            indicates to peek at the data
+     * @return number of data received
+     * @throws IOException
+     *             upon an read error or timeout
+     */
+    public native int receiveDatagram(FileDescriptor fd, DatagramPacket packet,
+            byte[] data, int offset, int length, int receiveTimeout,
+            boolean peek) throws IOException;
+
+    public native int receiveDatagramDirect(FileDescriptor fd,
+            DatagramPacket packet, long address, int offset, int length,
+            int receiveTimeout, boolean peek) throws IOException;
+
+    /**
+     * Receive at most <code>count</code> bytes into the buffer
+     * <code>data</code> at the <code>offset</code> on the socket.
+     * 
+     * @param aFD
+     *            the socket FileDescriptor
+     * @param data
+     *            the receive buffer
+     * @param offset
+     *            the offset into the buffer
+     * @param count
+     *            the max number of bytes to receive
+     * @param timeout
+     *            the max time the read operation should block waiting for data
+     * @return the actual number of bytes read
+     * @throws IOException
+     * @throws SocketException
+     *             if an error occurs while reading
+     * @deprecated use {@link #read(FileDescriptor, byte[], int, int, int)}
+     */
+    @Deprecated
+    public native int receiveStream(FileDescriptor aFD, byte[] data,
+            int offset, int count, int timeout) throws IOException;
+
+    /**
+     * Recieve 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.
+     * 
+     * @param fd
+     *            the socket FileDescriptor
+     * @param packet
+     *            the DatagramPacket to receive into
+     * @param data
+     *            the data buffer of the packet
+     * @param offset
+     *            the offset in the data buffer
+     * @param length
+     *            the length of the data buffer in the packet
+     * @param receiveTimeout
+     *            the maximum length of time the socket should block, reading
+     * @param peek
+     *            indicates to peek at the data
+     * @return number of data received
+     * @throws IOException
+     *             upon an read error or timeout
+     */
+    public native int recvConnectedDatagram(FileDescriptor fd,
+            DatagramPacket packet, byte[] data, int offset, int length,
+            int receiveTimeout, boolean peek) throws IOException;
+
+    public native int recvConnectedDatagramDirect(FileDescriptor fd,
+            DatagramPacket packet, long address, int offset, int length,
+            int receiveTimeout, boolean peek) throws IOException;
+
+    /**
      * Select the given file descriptors for read and write operations.
      * 
      * The file descriptors passed in as readFDs will be selected for read-ready
@@ -278,18 +333,17 @@
      * the select the behavior depends upon the underlying OS.
      * 
      * Upon return the result is a single array of length
-     * <code>readFDs.length</code> + <code>writeFDs.length</code> laid out
-     * as the result of the select operation on the corresponding file
-     * descriptors.
-     * 
-     * @param readChannels
-     *            all channels interested in read and accept
-     * @param writeChannels
-     *            all channels interested in write and connect
+     * <code>readFDs.length</code> + <code>writeFDs.length</code> laid out as
+     * the result of the select operation on the corresponding file descriptors.
+     * 
+     * @param readFDs
+     *            all sockets interested in read and accept
+     * @param writeFDs
+     *            all sockets interested in write and connect
      * @param timeout
-     *            timeout in millis
-     * @returns int array, each element describes the corresponding state of the
-     *          descriptor in the read and write arrays.
+     *            timeout in milliseconds
+     * @returns each element describes the corresponding state of the descriptor
+     *          in the read and write arrays.
      * @throws SocketException
      */
     public int[] select(FileDescriptor[] readFDs, FileDescriptor[] writeFDs,
@@ -302,7 +356,7 @@
         }
         int[] flags = new int[countRead + countWrite];
 
-        assert validateFDs(readFDs, writeFDs) : "Invalid file descriptor arrays";
+        assert validateFDs(readFDs, writeFDs) : "Invalid file descriptor arrays"; //$NON-NLS-1$
 
         // handle timeout in native
         result = selectImpl(readFDs, writeFDs, countRead, countWrite, flags,
@@ -317,6 +371,107 @@
         throw new SocketException();
     }
 
+    private native int selectImpl(FileDescriptor[] readfd,
+            FileDescriptor[] writefd, int cread, int cwirte, int[] flags,
+            long timeout);
+
+    /**
+     * Send the <code>data</code> to the address and port to which the was
+     * connected and <code>port</code>.
+     * 
+     * @param fd
+     *            the socket FileDescriptor
+     * @param data
+     *            the data buffer of the packet
+     * @param offset
+     *            the offset in the data buffer
+     * @param length
+     *            the length of the data buffer in the packet
+     * @param bindToDevice
+     *            not used, current kept in case needed as was the case for
+     *            sendDatagramImpl
+     * @return number of data send
+     * @throws IOException
+     *             upon an read error or timeout
+     */
+    public native int sendConnectedDatagram(FileDescriptor fd, byte[] data,
+            int offset, int length, boolean bindToDevice) throws IOException;
+
+    public native int sendConnectedDatagramDirect(FileDescriptor fd,
+            long address, int offset, int length, boolean bindToDevice)
+            throws IOException;
+
+    /**
+     * Send the <code>data</code> to the nominated target <code>address</code>
+     * and <code>port</code>. These values are derived from the DatagramPacket
+     * to reduce the field calls within JNI.
+     * 
+     * @param fd
+     *            the socket FileDescriptor
+     * @param data
+     *            the data buffer of the packet
+     * @param offset
+     *            the offset in the data buffer
+     * @param length
+     *            the length of the data buffer in the packet
+     * @param port
+     *            the target host port
+     * @param bindToDevice
+     *            if bind to device
+     * @param trafficClass
+     *            the traffic class to be used when the datagram is sent
+     * @param inetAddress
+     *            address to connect to.
+     * @return number of data send
+     * 
+     * @throws IOException
+     *             upon an read error or timeout
+     */
+    public native int sendDatagram(FileDescriptor fd, byte[] data, int offset,
+            int length, int port, boolean bindToDevice, int trafficClass,
+            InetAddress inetAddress) throws IOException;
+
+    public native int sendDatagram2(FileDescriptor fd, byte[] data, int offset,
+            int length, int port, InetAddress inetAddress) throws IOException;
+
+    public native int sendDatagramDirect(FileDescriptor fd, long address,
+            int offset, int length, int port, boolean bindToDevice,
+            int trafficClass, InetAddress inetAddress) throws IOException;
+
+    public native void sendUrgentData(FileDescriptor fd, byte value);
+
+    public native void setInetAddress(InetAddress sender, byte[] address);
+
+    public native void setNonBlocking(FileDescriptor fd, boolean block)
+            throws IOException;
+
+    /**
+     * Set the nominated socket option in the IP stack.
+     * 
+     * @param aFD
+     *            the socket descriptor @param opt the option selector @param
+     *            optVal the nominated option value
+     * 
+     * @throws SocketException
+     *             if the option is invalid or cannot be set
+     */
+    public native void setSocketOption(FileDescriptor aFD, int opt,
+            Object optVal) throws SocketException;
+
+    public native void shutdownInput(FileDescriptor fd) throws IOException;
+
+    public native void shutdownOutput(FileDescriptor fd) throws IOException;
+
+    /**
+     * Close the socket in the IP stack.
+     * 
+     * @param fd
+     *            the socket descriptor
+     */
+    public native void socketClose(FileDescriptor fd) throws IOException;
+
+    public native boolean supportsUrgentData(FileDescriptor fd);
+
     /*
      * Used to check if the file descriptor arrays are valid before passing them
      * into the select native call.
@@ -337,417 +492,41 @@
         return true;
     }
 
-	public InetAddress getSocketLocalAddress(FileDescriptor aFD,
-			boolean preferIPv6Addresses) {
-		return getSocketLocalAddressImpl(aFD, preferIPv6Addresses);
-	}
-
-	/*
-	 * Query the IP stack for the local port to which this socket is bound.
-	 * 
-	 * @param aFD the socket descriptor @param preferIPv6Addresses address
-	 * preference for nodes that support both IPv4 and IPv6 @return int the
-	 * local port to which the socket is bound
-	 */
-	public int getSocketLocalPort(FileDescriptor aFD,
-			boolean preferIPv6Addresses) {
-		return getSocketLocalPortImpl(aFD, preferIPv6Addresses);
-	}
-
-	/*
-	 * Query the IP stack for the nominated socket option.
-	 * 
-	 * @param aFD the socket descriptor @param opt the socket option type
-	 * @return the nominated socket option value
-	 * 
-	 * @throws SocketException if the option is invalid
-	 */
-	public Object getSocketOption(FileDescriptor aFD, int opt)
-			throws SocketException {
-		return getSocketOptionImpl(aFD, opt);
-	}
-
-	/*
-	 * Set the nominated socket option in the IP stack.
-	 * 
-	 * @param aFD the socket descriptor @param opt the option selector @param
-	 * optVal the nominated option value
-	 * 
-	 * @throws SocketException if the option is invalid or cannot be set
-	 */
-	public void setSocketOption(FileDescriptor aFD, int opt, Object optVal)
-			throws SocketException {
-		setSocketOptionImpl(aFD, opt, optVal);
-	}
-
-	public int getSocketFlags() {
-		return getSocketFlagsImpl();
-	}
-
-	/*
-	 * Close the socket in the IP stack.
-	 * 
-	 * @param aFD the socket descriptor
-	 */
-	public void socketClose(FileDescriptor aFD) throws IOException {
-		socketCloseImpl(aFD);
-	}
-
-	public InetAddress getHostByAddr(byte[] addr) throws UnknownHostException {
-		return getHostByAddrImpl(addr);
-	}
-
-	public InetAddress getHostByName(String addr, boolean preferIPv6Addresses)
-			throws UnknownHostException {
-		return getHostByNameImpl(addr, preferIPv6Addresses);
-	}
-
-	public void setInetAddress(InetAddress sender, byte[] address) {
-		setInetAddressImpl(sender, address);
-	}
-
-	// ---------------------------------------------------
-	// Native Codes
-	// ---------------------------------------------------
-
-	static native void createSocketImpl(FileDescriptor fd,
-			boolean preferIPv4Stack);
-
-	/*
-	 * Allocate a datagram socket in the IP stack. The socket is associated with
-	 * the <code>aFD</code>.
-	 * 
-	 * @param aFD the FileDescriptor to associate with the socket @param
-	 * preferIPv4Stack IP stack preference if underlying platform is V4/V6
-	 * @exception SocketException upon an allocation error
-	 */
-	static native void createDatagramSocketImpl(FileDescriptor aFD,
-			boolean preferIPv4Stack) throws SocketException;
-
-	static native int readSocketImpl(FileDescriptor aFD, byte[] data,
-			int offset, int count, int timeout) throws IOException;
-    
-    static native int readSocketDirectImpl(FileDescriptor aFD, long address,
-            int count, int timeout) throws IOException;
-
-	static native int writeSocketImpl(FileDescriptor fd, byte[] data,
-			int offset, int count) throws IOException;
-    
-    static native int writeSocketDirectImpl(FileDescriptor fd, long address,
+    /**
+     * Write bytes from a byte array to a socket.
+     * 
+     * @param fd
+     *            the socket on which to write the bytes
+     * @param data
+     *            the array containing the bytes to be written
+     * @param offset
+     *            the offset in the byte array from which to take the bytes
+     * @param count
+     *            the maximum number of bytes to be written. Callers are trusted
+     *            not to send values of length+count that are larger than
+     *            data.length
+     * @return the actual number of bytes written, which will be between zero
+     *         and count
+     * @throws IOException
+     *             if there is an underlying socket problem
+     */
+    public native int write(FileDescriptor fd, byte[] data, int offset,
             int count) throws IOException;
 
-	static native void setNonBlockingImpl(FileDescriptor aFD,
-			boolean block);
-
-	static native int connectSocketImpl(FileDescriptor aFD,
-			int trafficClass, InetAddress inetAddress, int port);
-
-	static native int connectWithTimeoutSocketImpl(
-			FileDescriptor aFD, int timeout, int trafficClass,
-			InetAddress hostname, int port, int step, Long context);
-
-	static native void connectStreamWithTimeoutSocketImpl(FileDescriptor aFD,
-			int aport, int timeout, int trafficClass, InetAddress inetAddress)
-			throws IOException;
-
-	static native void socketBindImpl(FileDescriptor aFD, int port,
-			InetAddress inetAddress) throws SocketException;
-
-	static native void listenStreamSocketImpl(FileDescriptor aFD, int backlog)
-			throws SocketException;
-
-	static native int availableStreamImpl(FileDescriptor aFD)
-			throws SocketException;
-
-	static native void acceptSocketImpl(FileDescriptor fdServer,
-			SocketImpl newSocket, FileDescriptor fdnewSocket, int timeout)
-			throws IOException;
-
-	static native boolean supportsUrgentDataImpl(FileDescriptor fd);
-
-	static native void sendUrgentDataImpl(FileDescriptor fd, byte value);
-
-	/*
-	 * Connect the socket to a port and address
-	 * 
-	 * @param aFD the FileDescriptor to associate with the socket @param port
-	 * the port to connect to @param trafficClass the traffic Class to be used
-	 * then the connection is made @param inetAddress address to connect to.
-	 * 
-	 * @exception SocketException if the connect fails
-	 */
-	static native void connectDatagramImpl2(FileDescriptor aFD,
-			int port, int trafficClass, InetAddress inetAddress)
-			throws SocketException;
-
-	/*
-	 * Disconnect the socket to a port and address
-	 * 
-	 * @param aFD the FileDescriptor to associate with the socket
-	 * 
-	 * @exception SocketException if the disconnect fails
-	 */
-	static native void disconnectDatagramImpl(FileDescriptor aFD)
-			throws SocketException;
-
-	/*
-	 * Allocate a datagram socket in the IP stack. The socket is associated with
-	 * the <code>aFD</code>.
-	 * 
-	 * @param aFD the FileDescriptor to associate with the socket @param
-	 * preferIPv4Stack IP stack preference if underlying platform is V4/V6
-	 * @exception SocketException upon an allocation error
-	 */
-
-	/*
-	 * Bind the socket to the port/localhost in the IP stack.
-	 * 
-	 * @param aFD the socket descriptor @param port the option selector @param
-	 * bindToDevice bind the socket to the specified interface @param
-	 * inetAddress address to connect to. @return if bind successful @exception
-	 * SocketException thrown if bind operation fails
-	 */
-	static native boolean socketBindImpl2(FileDescriptor aFD,
-			int port, boolean bindToDevice, InetAddress inetAddress)
-			throws SocketException;
-
-	/*
-	 * Peek on the socket, update <code>sender</code> address and answer the
-	 * sender port.
-	 * 
-	 * @param aFD the socket FileDescriptor @param sender an InetAddress, to be
-	 * updated with the sender's address @param receiveTimeout the maximum
-	 * length of time the socket should block, reading @return int the sender
-	 * port
-	 * 
-	 * @exception IOException upon an read error or timeout
-	 */
-	static native int peekDatagramImpl(FileDescriptor aFD,
-			InetAddress sender, int receiveTimeout) throws IOException;
-
-	/*
-	 * Recieve data on the socket into the specified buffer. The packet fields
-	 * <code>data</code> & <code>length</code> are passed in addition to
-	 * <code>packet</code> to eliminate the JNI field access calls.
-	 * 
-	 * @param aFD the socket FileDescriptor @param packet the DatagramPacket to
-	 * receive into @param data the data buffer of the packet @param offset the
-	 * offset in the data buffer @param length the length of the data buffer in
-	 * the packet @param receiveTimeout the maximum length of time the socket
-	 * should block, reading @param peek indicates to peek at the data @return
-	 * number of data received @exception IOException upon an read error or
-	 * timeout
-	 */
-	static native int receiveDatagramImpl(FileDescriptor aFD,
-			DatagramPacket packet, byte[] data, int offset, int length,
-			int receiveTimeout, boolean peek) throws IOException;
-    
-    static native int receiveDatagramDirectImpl(FileDescriptor aFD,
-            DatagramPacket packet, long address, int offset, int length,
-            int receiveTimeout, boolean peek) throws IOException;
-
-	/*
-	 * Recieve data on the connected socket into the specified buffer. The
-	 * packet fields <code>data</code> & <code>length</code> are passed in
-	 * addition to <code>packet</code> to eliminate the JNI field access
-	 * calls.
-	 * 
-	 * @param aFD the socket FileDescriptor @param packet the DatagramPacket to
-	 * receive into @param data the data buffer of the packet @param offset the
-	 * offset in the data buffer @param length the length of the data buffer in
-	 * the packet @param receiveTimeout the maximum length of time the socket
-	 * should block, reading @param peek indicates to peek at the data @return
-	 * number of data received @exception IOException upon an read error or
-	 * timeout
-	 */
-	static native int recvConnectedDatagramImpl(FileDescriptor aFD,
-			DatagramPacket packet, byte[] data, int offset, int length,
-			int receiveTimeout, boolean peek) throws IOException;
-    
-    static native int recvConnectedDatagramDirectImpl(FileDescriptor aFD,
-            DatagramPacket packet, long address, int offset, int length,
-            int receiveTimeout, boolean peek) throws IOException;
-
-	/*
-	 * Send the <code>data</code> to the nominated target <code>address</code>
-	 * and <code>port</code>. These values are derived from the
-	 * DatagramPacket to reduce the field calls within JNI.
-	 * 
-	 * @param fd the socket FileDescriptor @param data the data buffer of the
-	 * packet @param offset the offset in the data buffer @param length the
-	 * length of the data buffer in the packet @param port the target host port
-	 * @param bindToDevice if bind to device @param trafficClass the traffic
-	 * class to be used when the datagram is sent @param inetAddress address to
-	 * connect to. @return number of data send
-	 * 
-	 * @exception IOException upon an read error or timeout
-	 */
-	static native int sendDatagramImpl(FileDescriptor fd,
-			byte[] data, int offset, int length, int port,
-			boolean bindToDevice, int trafficClass, InetAddress inetAddress)
-			throws IOException;
-    
-    static native int sendDatagramDirectImpl(FileDescriptor fd,
-            long address, int offset, int length, int port,
-            boolean bindToDevice, int trafficClass, InetAddress inetAddress)
-            throws IOException;
-
-	/*
-	 * Send the <code>data</code> to the address and port to which the was
-	 * connnected and <code>port</code>.
-	 * 
-	 * @param fd the socket FileDescriptor @param data the data buffer of the
-	 * packet @param offset the offset in the data buffer @param length the
-	 * length of the data buffer in the packet @param bindToDevice not used,
-	 * current kept in case needed as was the case for sendDatagramImpl @return
-	 * number of data send @exception IOException upon an read error or timeout
-	 */
-	static native int sendConnectedDatagramImpl(FileDescriptor fd,
-			byte[] data, int offset, int length, boolean bindToDevice)
-			throws IOException;
-    
-    static native int sendConnectedDatagramDirectImpl(FileDescriptor fd,
-            long address, int offset, int length, boolean bindToDevice)
+    /**
+     * Write bytes from the given address to a socket.
+     * 
+     * @param fd
+     *            the socket on which to write the bytes
+     * @param address
+     *            the start address of the bytes to be written
+     * @param count
+     *            the maximum number of bytes to be written
+     * @return the actual number of bytes written, which will be between zero
+     *         and count
+     * @throws IOException
+     *             if there is an underlying socket problem
+     */
+    public native int writeDirect(FileDescriptor fd, long address, int count)
             throws IOException;
-
-	/*
-	 * Answer the result of attempting to create a server stream socket in the
-	 * IP stack. Any special options required for server sockets will be set by
-	 * this method.
-	 * 
-	 * @param aFD the socket FileDescriptor @param preferIPv4Stack if use IPV4
-	 * @exception SocketException if an error occurs while creating the socket
-	 */
-	static native void createServerStreamSocketImpl(FileDescriptor aFD,
-			boolean preferIPv4Stack) throws SocketException;
-
-	/*
-	 * Answer the result of attempting to create a multicast socket in the IP
-	 * stack. Any special options required for server sockets will be set by
-	 * this method.
-	 * 
-	 * @param aFD the socket FileDescriptor @param preferIPv4Stack if use IPV4
-	 * @exception SocketException if an error occurs while creating the socket
-	 */
-	static native void createMulticastSocketImpl(FileDescriptor aFD,
-			boolean preferIPv4Stack) throws SocketException;
-
-	/*
-	 * Recieve at most <code>count</code> bytes into the buffer <code>data</code>
-	 * at the <code>offset</code> on the socket.
-	 * 
-	 * @param aFD the socket FileDescriptor @param data the receive buffer
-	 * @param offset the offset into the buffer @param count the max number of
-	 * bytes to receive @param timeout the max time the read operation should
-	 * block waiting for data @return int the actual number of bytes read
-	 * @throws IOException @exception SocketException if an error occurs while
-	 * reading
-	 */
-	static native int receiveStreamImpl(FileDescriptor aFD, byte[] data,
-			int offset, int count, int timeout) throws IOException;
-
-	/*
-	 * 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
-	 */
-	static native int sendStreamImpl(FileDescriptor fd, byte[] data,
-			int offset, int count) throws IOException;
-
-	private native void shutdownInputImpl(FileDescriptor descriptor)
-			throws IOException;
-
-	private native void shutdownOutputImpl(FileDescriptor descriptor)
-			throws IOException;
-
-	static native void acceptStreamSocketImpl(FileDescriptor fdServer,
-			SocketImpl newSocket, FileDescriptor fdnewSocket, int timeout)
-			throws IOException;
-
-	static native void createStreamSocketImpl(FileDescriptor aFD,
-			boolean preferIPv4Stack) throws SocketException;
-
-	static native int sendDatagramImpl2(FileDescriptor fd, byte[] data,
-			int offset, int length, int port, InetAddress inetAddress)
-			throws IOException;
-
-	static native int selectImpl(FileDescriptor[] readfd,
-			FileDescriptor[] writefd, int cread, int cwirte, int[] flags,
-			long timeout);
-
-	static native InetAddress getSocketLocalAddressImpl(FileDescriptor aFD,
-			boolean preferIPv6Addresses);
-
-	/*
-	 * Query the IP stack for the local port to which this socket is bound.
-	 * 
-	 * @param aFD the socket descriptor @param preferIPv6Addresses address
-	 * preference for nodes that support both IPv4 and IPv6 @return int the
-	 * local port to which the socket is bound
-	 */
-	static native int getSocketLocalPortImpl(FileDescriptor aFD,
-			boolean preferIPv6Addresses);
-
-	/*
-	 * Query the IP stack for the nominated socket option.
-	 * 
-	 * @param aFD the socket descriptor @param opt the socket option type
-	 * @return the nominated socket option value
-	 * 
-	 * @throws SocketException if the option is invalid
-	 */
-	static native Object getSocketOptionImpl(FileDescriptor aFD, int opt)
-			throws SocketException;
-
-	/*
-	 * Set the nominated socket option in the IP stack.
-	 * 
-	 * @param aFD the socket descriptor @param opt the option selector @param
-	 * optVal the nominated option value
-	 * 
-	 * @throws SocketException if the option is invalid or cannot be set
-	 */
-	static native void setSocketOptionImpl(FileDescriptor aFD, int opt,
-			Object optVal) throws SocketException;
-
-	static native int getSocketFlagsImpl();
-
-	/*
-	 * Close the socket in the IP stack.
-	 * 
-	 * @param aFD the socket descriptor
-	 */
-	static native void socketCloseImpl(FileDescriptor aFD);
-
-	static native InetAddress getHostByAddrImpl(byte[] addr)
-			throws UnknownHostException;
-
-	static native InetAddress getHostByNameImpl(String addr,
-			boolean preferIPv6Addresses) throws UnknownHostException;
-
-	native void setInetAddressImpl(InetAddress sender, byte[] address);
-
-    native int isReachableByICMPImpl(InetAddress addr, InetAddress local,
-            int ttl, int timeout);
-    
-    native Channel inheritedChannelImpl();
-
-	public Channel inheritedChannel() {
-		return inheritedChannelImpl();
-	}
-    
-    public void oneTimeInitialization(boolean jcl_supports_ipv6){
-        if (!isNetworkInited){
-            oneTimeInitializationImpl(jcl_supports_ipv6);
-            isNetworkInited = true;
-        } 
-    }
-    
-    native void oneTimeInitializationImpl (boolean jcl_supports_ipv6);
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/Platform.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/Platform.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/Platform.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/luni/src/main/java/org/apache/harmony/luni/platform/Platform.java Thu Dec 18 01:46:12 2008
@@ -16,47 +16,69 @@
 
 package org.apache.harmony.luni.platform;
 
-
 import org.apache.harmony.kernel.vm.VM;
 
 /**
- * Platform
- *  
+ * The Platform class gives access to the low-level underlying capabilities of
+ * the operating system.
+ * 
+ * The platform is structured into operations on the process heap memory,
+ * network subsystem, and file system through different OS components.
+ * 
+ * OS components are 'dangerous' in that they pass through the calls and
+ * arguments to the OS with very little checking, and as such may cause fatal
+ * exceptions in the runtime. Access to the OS components is restricted to
+ * trusted code running on the system classpath.
+ * 
+ * @see IFileSystem
+ * @see INetworkSystem
+ * @see IMemorySystem
  */
 public class Platform {
 
-	static final IAdapterManager ADAPTER_MANAGER = new AdapterManager();
+    static final IFileSystem FILE_SYSTEM = OSFileSystem.getOSFileSystem();
 
-	static final IFileSystem FILE_SYSTEM = OSComponentFactory.getFileSystem();
+    static final IMemorySystem MEMORY_SYSTEM = OSMemory.getOSMemory();
 
-	static final IMemorySystem MEMORY_SYSTEM = OSComponentFactory
-			.getMemorySystem();
+    static final INetworkSystem NETWORK_SYSTEM = OSNetworkSystem.getOSNetworkSystem();
 
-	static final INetworkSystem NETWORK_SYSTEM = OSComponentFactory
-			.getNetworkSystem();
-
-	public static IAdapterManager getAdapterManager() {
-		return ADAPTER_MANAGER;
-	}
-
-	private static final void accessCheck() {
-		if (VM.callerClassLoader() != null) {
-			throw new SecurityException();
-		}
-	}
-
-	public static IFileSystem getFileSystem() {
-		accessCheck();
-		return FILE_SYSTEM;
-	}
-
-	public static IMemorySystem getMemorySystem() {
-		accessCheck();
-		return MEMORY_SYSTEM;
-	}
-
-	public static INetworkSystem getNetworkSystem() {
-		accessCheck();
-		return NETWORK_SYSTEM;
-	}
+    /**
+     * Checks to ensure that whoever is asking for the OS component is running
+     * on the system classpath.
+     */
+    private static final void accessCheck() {
+        if (VM.callerClassLoader() != null) {
+            throw new SecurityException();
+        }
+    }
+
+    /**
+     * Answers the instance that interacts directly with the OS file system.
+     * 
+     * @return a low-level file system interface.
+     */
+    public static IFileSystem getFileSystem() {
+        accessCheck();
+        return FILE_SYSTEM;
+    }
+
+    /**
+     * Answers the instance that interacts directly with the OS memory system.
+     * 
+     * @return a low-level memory system interface.
+     */
+    public static IMemorySystem getMemorySystem() {
+        accessCheck();
+        return MEMORY_SYSTEM;
+    }
+
+    /**
+     * Answers the instance that interacts directly with the OS network system.
+     * 
+     * @return a low-level network system interface.
+     */
+    public static INetworkSystem getNetworkSystem() {
+        accessCheck();
+        return NETWORK_SYSTEM;
+    }
 }

Propchange: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSMemory.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/classlib/branches/java6/modules/luni/src/main/native/luni/shared/OSMemory.h
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message