org.apache.http.nio.ContentDecoder Java Examples

The following examples show how to use org.apache.http.nio.ContentDecoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CXFHttpAsyncResponseConsumer.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void consumeContent(final ContentDecoder dec, final IOControl ioc) throws IOException {
    // Only consume content when the work was accepted by the work queue
    if (outstream.retrySetHttpResponse(response)) {
        buf.consumeContent(dec, ioc);
    }
}
 
Example #2
Source File: AbstractResponseConsumer.java    From fc-java-sdk with MIT License 4 votes vote down vote up
protected void onContentReceived(ContentDecoder decoder, IOControl ioControl) throws IOException {
    this.buf.consumeContent(decoder);
}
 
Example #3
Source File: PoolingAsyncResponseConsumer.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected void onContentReceived(
        final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
    this.buffer.getSource().consumeContent(decoder);
}
 
Example #4
Source File: ResponseConsumer.java    From aliyun-tablestore-java-sdk with Apache License 2.0 4 votes vote down vote up
@Override
protected void onContentReceived(final ContentDecoder decoder,
        final IOControl ioctrl) throws IOException {
    Preconditions.checkNotNull(this.buf, "Content buffer should not be null.");
    this.buf.consumeContent(decoder);
}
 
Example #5
Source File: ForwardingHttpAsyncResponseConsumer.java    From logbook with MIT License 4 votes vote down vote up
@Override
public void consumeContent(final ContentDecoder decoder, final IOControl control) throws IOException {
    delegate().consumeContent(decoder, control);
}
 
Example #6
Source File: HttpAsyncResponseConsumerWrapper.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public void consumeContent(ContentDecoder decoder, IOControl ioctrl) throws IOException {
    consumer.consumeContent(decoder, ioctrl);
}
 
Example #7
Source File: SharedInputBuffer.java    From cxf with Apache License 2.0 4 votes vote down vote up
public int consumeContent(final ContentDecoder decoder, final IOControl ioc) throws IOException {
    if (this.shutdown) {
        //something bad happened, we need to shutdown the connection
        //as we're not going to read the data at all and we
        //don't want to keep getting read notices and such
        ioc.shutdown();
        return -1;
    }
    this.lock.lock();
    try {
        this.ioctrl = ioc;
        setInputMode();
        int totalRead = 0;
        int bytesRead;
        if (waitingBuffer != null && this.buffer.position() == 0) {
            while ((bytesRead = decoder.read(this.waitingBuffer)) > 0) {
                totalRead += bytesRead;
            }
        }
        //read more
        while ((bytesRead = decoder.read(this.buffer)) > 0) {
            totalRead += bytesRead;
        }
        if (bytesRead == -1 || decoder.isCompleted()) {
            this.endOfStream = true;
        }
        if (!this.buffer.hasRemaining() && this.ioctrl != null && !this.endOfStream) {
            this.ioctrl.suspendInput();
        }
        this.condition.signalAll();

        if (totalRead > 0) {
            return totalRead;
        }
        if (this.endOfStream) {
            return -1;
        }
        return 0;
    } finally {
        this.lock.unlock();
    }
}
 
Example #8
Source File: TracingHttpAsyncClientBuilder.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public void consumeContent(ContentDecoder decoder, IOControl ioctrl)
  throws IOException {
  responseConsumer.consumeContent(decoder, ioctrl);
}
 
Example #9
Source File: PoolingAsyncResponseConsumerTest.java    From log4j2-elasticsearch with Apache License 2.0 3 votes vote down vote up
@Test
public void onContentReceivedPassedDecoderToBuffer() throws IOException, PoolResourceException {

    // given
    ItemSourcePool<SimpleInputBuffer> itemSourcePool = mock(ItemSourcePool.class);

    ItemSource<SimpleInputBuffer> itemSource = mock(ItemSource.class);
    when(itemSourcePool.getPooled()).thenReturn(itemSource);

    SimpleInputBuffer buffer = mock(SimpleInputBuffer.class);
    when(itemSource.getSource()).thenReturn(buffer);

    PoolingAsyncResponseConsumer consumer = createDefaultTestObject(itemSourcePool);
    consumer.onResponseReceived(mock(HttpResponse.class));

    HttpEntity httpEntity = mock(HttpEntity.class);
    consumer.onEntityEnclosed(httpEntity, ContentType.create("application/json"));

    ContentDecoder contentDecoder = mock(ContentDecoder.class);

    // when
    consumer.onContentReceived(contentDecoder, mock(IOControl.class));

    // then
    verify(buffer, times(1)).consumeContent(eq(contentDecoder));

}