use of org.asynchttpclient.netty.request.WriteProgressListener in project async-http-client by AsyncHttpClient.
the class NettyBodyBody method write.
@Override
public void write(final Channel channel, NettyResponseFuture<?> future) throws IOException {
Object msg;
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) {
}
});
}
}
//
channel.write(msg, channel.newProgressivePromise()).addListener(new WriteProgressListener(future, false, getContentLength()) {
public void operationComplete(ChannelProgressiveFuture cf) {
closeSilently(body);
super.operationComplete(cf);
}
});
channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, channel.voidPromise());
}
use of org.asynchttpclient.netty.request.WriteProgressListener in project async-http-client by AsyncHttpClient.
the class NettyInputStreamBody method write.
@Override
public void write(Channel channel, NettyResponseFuture<?> future) throws IOException {
final InputStream is = inputStream;
if (future.isStreamConsumed()) {
if (is.markSupported())
is.reset();
else {
LOGGER.warn("Stream has already been consumed and cannot be reset");
return;
}
} else {
future.setStreamConsumed(true);
}
channel.write(new ChunkedStream(is), channel.newProgressivePromise()).addListener(new WriteProgressListener(future, false, getContentLength()) {
public void operationComplete(ChannelProgressiveFuture cf) {
closeSilently(is);
super.operationComplete(cf);
}
});
channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, channel.voidPromise());
}
use of org.asynchttpclient.netty.request.WriteProgressListener in project async-http-client by AsyncHttpClient.
the class NettyFileBody method write.
@Override
public void write(Channel channel, NettyResponseFuture<?> future) throws IOException {
@SuppressWarnings("resource") final FileChannel // Netty will close the ChunkedNioFile or the DefaultFileRegion
fileChannel = new RandomAccessFile(file, "r").getChannel();
Object message = //
(ChannelManager.isSslHandlerConfigured(channel.pipeline()) || config.isDisableZeroCopy()) ? new ChunkedNioFile(fileChannel, offset, length, config.getChunkedFileChunkSize()) : new DefaultFileRegion(fileChannel, offset, length);
//
channel.write(message, channel.newProgressivePromise()).addListener(new WriteProgressListener(future, false, getContentLength()));
channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, channel.voidPromise());
}
Aggregations