java - ByteBuffer and partial write -


if bytebuffer written partially, position updated , next _channel.write call resume last position, yep?

compact() not necessary?

private asynchronoussocketchannel _channel; private bytebuffer _buffer;  final completionhandler<integer, logstashclientstream> _writecompletionhandler = new completionhandler<integer, logstashclientstream>(){     @override     public void completed(integer sent, logstashclientstream self) {         if( _buffer.remaining() == 0 ){             _buffer.clear();             //...         }                                else {             // partial write             self.send();         }     }      @override     public void failed(throwable exc, logstashclientstream self) {         //...     } };  private void send(){     try{         _channel.write( _buffer, this, _writecompletionhandler);     } catch(throwable e){         //...     } } 

yes, resume, , no, compact() not necessary here. it's useful in cases when want fill rest of buffer input stream before invoking write() again.


Comments