Code example for ByteBuffer

Methods: fliphasRemainingcompact

0
    } 
 
    public void react(SelectionKey key) throws IOException {
        try { 
            SocketChannel sc = (SocketChannel) key.channel();
            buffer.flip();
            int count = sc.write(buffer);
 
            if (!buffer.hasRemaining())
                // Nothing left to write: OK to start reading again 
                sc.register(key.selector(), SelectionKey.OP_READ, new Reader(buffer));
        } 
        finally { 
            buffer.compact();
        } 
    } 
} 
Contextual code suggestions in your IDE  Get Codota for Java