resource leak: FileInputStream was never closed

This commit is contained in:
radimch 2013-08-09 12:18:16 +02:00 committed by Norman Maurer
parent 65fd9c0b12
commit 9acf130adb

View File

@ -101,9 +101,11 @@ public class FileServer {
return; return;
} }
ctx.write(file + " " + file.length() + '\n'); ctx.write(file + " " + file.length() + '\n');
FileRegion region = new DefaultFileRegion(new FileInputStream(file).getChannel(), 0, file.length()); FileInputStream fis = new FileInputStream(file);
FileRegion region = new DefaultFileRegion(fis.getChannel(), 0, file.length());
ctx.write(region); ctx.write(region);
ctx.writeAndFlush("\n"); ctx.writeAndFlush("\n");
fis.close();
} else { } else {
ctx.writeAndFlush("File not found: " + file + '\n'); ctx.writeAndFlush("File not found: " + file + '\n');
} }