[#1414] Use gathering writes in AbstractMemoryHttpData if the buffer is backed by multiple ByteBuffers

* This fix the bug which caused an UnsupportedOperationException when renameTo(...) was called and the underlying ByteBuf was backed by multiple ByteBuffers
This commit is contained in:
Norman Maurer 2013-06-10 07:58:59 +02:00
parent fa6999cd42
commit e71a521284

View File

@ -210,11 +210,19 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
int length = byteBuf.readableBytes();
FileOutputStream outputStream = new FileOutputStream(dest);
FileChannel fileChannel = outputStream.getChannel();
ByteBuffer byteBuffer = byteBuf.nioBuffer();
int written = 0;
while (written < length) {
written += fileChannel.write(byteBuffer);
if (byteBuf.nioBufferCount() == 1) {
ByteBuffer byteBuffer = byteBuf.nioBuffer();
while (written < length) {
written += fileChannel.write(byteBuffer);
}
} else {
ByteBuffer[] byteBuffers = byteBuf.nioBuffers();
while (written < length) {
written += fileChannel.write(byteBuffers);
}
}
fileChannel.force(false);
fileChannel.close();
outputStream.close();