Code example for ByteBuffer

Methods: compact, flip, hasRemaining

0
    } 
 
    public void produceContent( 
            final ContentEncoder encoder,
            final IOControl ioctrl) throws IOException {
        final int i = this.channel.read(this.buffer);
        this.buffer.flip();
        encoder.write(this.buffer);
        final boolean buffering = this.buffer.hasRemaining();
        this.buffer.compact();
        if (i == -1 && !buffering) {
            encoder.complete();
            this.channel.close();
        } 
    } 
 
    public void finish() { 
        try { 
            this.channel.close();
        } catch (final IOException ignore) {
        }