Code example for ReadableByteChannel

Methods: closeread

0
    public void produceContent( 
            final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
        if (this.channel == null) {
            this.channel = Channels.newChannel(this.entity.getContent());
        } 
        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();
            close(); 
        } 
    } 
 
    public boolean isRepeatable() { 
        return this.entity.isRepeatable();
    } 
 
    public void close() throws IOException { 
        final ReadableByteChannel local = this.channel;
        this.channel = null;
        if (local != null) {
            local.close();
        } 
        if (this.entity.isStreaming()) {
            final InputStream instream = this.entity.getContent();
            instream.close();
        }