Skip to content

Commit 5077536

Browse files
committed
minor clean up
1 parent cefcbff commit 5077536

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

client/src/main/java/org/asynchttpclient/netty/request/body/NettyFileBody.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,13 @@ public String getContentType() {
7070
@Override
7171
public void write(Channel channel, NettyResponseFuture<?> future) throws IOException {
7272
@SuppressWarnings("resource")
73-
// Netty will close the ChunkedNioFile or the DefaultFileRegion
74-
final FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
73+
// netty will close the FileChannel
74+
FileChannel fileChannel = new RandomAccessFile(file, "r").getChannel();
75+
boolean noZeroCopy = ChannelManager.isSslHandlerConfigured(channel.pipeline()) || config.isDisableZeroCopy();
76+
Object body = noZeroCopy ? new ChunkedNioFile(fileChannel, offset, length, config.getChunkedFileChunkSize()) : new DefaultFileRegion(fileChannel, offset, length);
7577

76-
Object message = (ChannelManager.isSslHandlerConfigured(channel.pipeline()) || config.isDisableZeroCopy()) ? //
77-
new ChunkedNioFile(fileChannel, offset, length, config.getChunkedFileChunkSize())
78-
: new DefaultFileRegion(fileChannel, offset, length);
79-
80-
channel.write(message, channel.newProgressivePromise())//
81-
.addListener(new WriteProgressListener(future, false, getContentLength()));
78+
channel.write(body, channel.newProgressivePromise())//
79+
.addListener(new WriteProgressListener(future, false, length));
8280
channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, channel.voidPromise());
8381
}
8482
}

0 commit comments

Comments
 (0)