From 65876fa7fbe2f63a73a590b5f2583daecf63984f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Br=C3=A9gier?= Date: Mon, 30 Apr 2012 12:29:05 +0300 Subject: [PATCH] Close channel when needed and optimize force() position after multiple writes not at each step --- .../netty/handler/codec/http/AbstractDiskHttpData.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/AbstractDiskHttpData.java b/codec-http/src/main/java/io/netty/handler/codec/http/AbstractDiskHttpData.java index ebb4290b5d..04b3147447 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/AbstractDiskHttpData.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/AbstractDiskHttpData.java @@ -116,9 +116,9 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData { int written = 0; while (written < size) { written += localfileChannel.write(byteBuffer); - localfileChannel.force(false); } buffer.readerIndex(buffer.readerIndex() + written); + localfileChannel.force(false); localfileChannel.close(); completed = true; } @@ -143,7 +143,6 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData { } while (written < localsize) { written += fileChannel.write(byteBuffer); - fileChannel.force(false); } size += localsize; buffer.readerIndex(buffer.readerIndex() + written); @@ -156,6 +155,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData { FileOutputStream outputStream = new FileOutputStream(file); fileChannel = outputStream.getChannel(); } + fileChannel.force(false); fileChannel.close(); fileChannel = null; completed = true; @@ -195,9 +195,10 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData { while (read > 0) { byteBuffer.position(read).flip(); written += localfileChannel.write(byteBuffer); - localfileChannel.force(false); read = inputStream.read(bytes); } + localfileChannel.force(false); + localfileChannel.close(); size = written; if (definedSize > 0 && definedSize < size) { file.delete(); @@ -300,6 +301,8 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData { FileChannel in = inputStream.getChannel(); FileChannel out = outputStream.getChannel(); long destsize = in.transferTo(0, size, out); + in.close(); + out.close(); if (destsize == size) { file.delete(); file = dest;