private void socketWrite ( byte b [ ] , int off , int len ) throws IOException { if ( len <= 0 || off < 0 || off + len > b . length ) { if ( len == 0 ) { return ; } throw new ArrayIndexOutOfBoundsException ( ) ; } Object traceContext = IoTrace . socketWriteBegin ( ) ; int bytesWritten = 0 ; FileDescriptor fd = impl . acquireFD ( ) ; try { BlockGuard . getThreadPolicy ( ) . onNetwork ( ) ; socketWrite0 ( fd , b , off , len ) ; bytesWritten = len ; } catch ( SocketException se ) { if ( se instanceof sun . net . ConnectionResetException ) { impl . setConnectionResetPending ( ) ; se = new SocketException ( "Connection reset" ) ; } if ( impl . isClosedOrPending ( ) ) { throw new SocketException ( "Socket closed" ) ; } else { throw se ; } } finally { IoTrace . socketWriteEnd ( traceContext , impl . address , impl . port , bytesWritten ) ; } }
Writes to the socket with appropriate locking of the FileDescriptor .