@@ -70,15 +70,13 @@ public String getContentType() {
70
70
@ Override
71
71
public void write (Channel channel , NettyResponseFuture <?> future ) throws IOException {
72
72
@ 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 );
75
77
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 ));
82
80
channel .writeAndFlush (LastHttpContent .EMPTY_LAST_CONTENT , channel .voidPromise ());
83
81
}
84
82
}
0 commit comments