@@ -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