fix download large file problem. #2135

This commit is contained in:
hengyunabc 2022-03-25 16:34:26 +08:00
parent f4ba958911
commit 23d1edee6e

View File

@ -175,13 +175,7 @@ public class DirectoryBrowser {
return null;
}
RandomAccessFile raf;
try {
raf = new RandomAccessFile(file, "r");
} catch (Exception ignore) {
return null;
}
long fileLength = raf.length();
long fileLength = file.length();
if (fileLength < MIN_NETTY_DIRECT_SEND_SIZE){
FileInputStream fileInputStream = new FileInputStream(file);
try {
@ -210,6 +204,7 @@ public class DirectoryBrowser {
// Write the content.
ChannelFuture sendFileFuture;
ChannelFuture lastContentFuture;
RandomAccessFile raf = new RandomAccessFile(file, "r"); // will closed by netty
if (ctx.pipeline().get(SslHandler.class) == null) {
sendFileFuture =
ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise());