public void writeTo ( SocketChannel channel ) throws IOException { channel . write ( buffer ) ; // only if buffer is empty if ( buffer . remaining ( ) == 0 ) { buffer . clear ( ) ; state = BufferState . READY_TO_WRITE ; } }
This method try to write data from buffer to channel . Buffer changes state to READY_TO_READ only if all data were wrote to channel in other case you should call this method again