Example usage for io.netty.handler.stream ChunkedWriteHandler resumeTransfer

List of usage examples for io.netty.handler.stream ChunkedWriteHandler resumeTransfer

Introduction

In this page you can find the example usage for io.netty.handler.stream ChunkedWriteHandler resumeTransfer.

Prototype

public void resumeTransfer() 

Source Link

Document

Continues to fetch the chunks from the input.

Usage

From source file:org.asynchttpclient.netty.request.body.NettyBodyBody.java

License:Open Source License

@Override
public void write(final Channel channel, NettyResponseFuture<?> future) throws IOException {

    Object msg;/*  w  w  w  .  j a v a2 s . c  o  m*/
    if (body instanceof RandomAccessBody && !ChannelManager.isSslHandlerConfigured(channel.pipeline())
            && !config.isDisableZeroCopy()) {
        msg = new BodyFileRegion((RandomAccessBody) body);

    } else {
        msg = new BodyChunkedInput(body);

        BodyGenerator bg = future.getTargetRequest().getBodyGenerator();
        if (bg instanceof FeedableBodyGenerator && !(bg instanceof ReactiveStreamsBodyGenerator)) {
            final ChunkedWriteHandler chunkedWriteHandler = channel.pipeline().get(ChunkedWriteHandler.class);
            FeedableBodyGenerator.class.cast(bg).setListener(new FeedListener() {
                @Override
                public void onContentAdded() {
                    chunkedWriteHandler.resumeTransfer();
                }

                @Override
                public void onError(Throwable t) {
                }
            });
        }
    }

    ChannelFuture writeFuture = channel.write(msg, channel.newProgressivePromise());
    writeFuture.addListener(new WriteProgressListener(future, false, getContentLength()) {
        public void operationComplete(ChannelProgressiveFuture cf) {
            closeSilently(body);
            super.operationComplete(cf);
        }
    });
    channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, channel.voidPromise());
}