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..663b7861b2 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 @@ -15,6 +15,9 @@ */ package io.netty.handler.codec.http; +import io.netty.buffer.ChannelBuffer; +import io.netty.buffer.ChannelBuffers; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -24,9 +27,6 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; - /** * Abstract Disk HttpData implementation */ @@ -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; @@ -198,6 +198,8 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData { localfileChannel.force(false); read = inputStream.read(bytes); } + localfileChannel.force(false); + localfileChannel.close(); size = written; if (definedSize > 0 && definedSize < size) { file.delete(); @@ -300,6 +302,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; diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/AbstractMemoryHttpData.java b/codec-http/src/main/java/io/netty/handler/codec/http/AbstractMemoryHttpData.java index bdd24455f3..90ae800fb5 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/AbstractMemoryHttpData.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/AbstractMemoryHttpData.java @@ -15,6 +15,9 @@ */ package io.netty.handler.codec.http; +import io.netty.buffer.ChannelBuffer; +import io.netty.buffer.ChannelBuffers; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -24,9 +27,6 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; -import io.netty.buffer.ChannelBuffer; -import io.netty.buffer.ChannelBuffers; - /** * Abstract Memory HttpData implementation */ @@ -212,8 +212,8 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData { int written = 0; while (written < length) { written += fileChannel.write(byteBuffer); - fileChannel.force(false); } + fileChannel.force(false); fileChannel.close(); isRenamed = true; return written == length;