Code example for ByteBuffer

Methods: compact, hasRemaining

0
    /** 
     * Sets input mode. The buffer can now be written into. 
     */ 
    protected void setInputMode() { 
        if (this.mode != INPUT_MODE) {
            if (this.buffer.hasRemaining()) {
                this.buffer.compact();
            } else { 
                this.buffer.clear();
            } 
            this.mode = INPUT_MODE;
        } 
    } 
 
    private void expandCapacity(final int capacity) {
        final ByteBuffer oldbuffer = this.buffer;
        this.buffer = allocator.allocate(capacity);
        oldbuffer.flip();
        this.buffer.put(oldbuffer);
    }