Motivation: This is small fixes for #10453 PR according @njhill and @normanmaurer conversation. Modification: Simple refactor and takes into account remainder when calculate size. Result: Behavior is correct
This commit is contained in:
parent
6150a0e3c5
commit
ce132b15d5
@ -161,21 +161,21 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
RandomAccessFile accessFile = new RandomAccessFile(file, "rw");
|
RandomAccessFile accessFile = new RandomAccessFile(file, "rw");
|
||||||
fileChannel = accessFile.getChannel();
|
fileChannel = accessFile.getChannel();
|
||||||
}
|
}
|
||||||
int totalWritten = 0;
|
int remaining = localsize;
|
||||||
long position = fileChannel.position();
|
long position = fileChannel.position();
|
||||||
int index = buffer.readerIndex();
|
int index = buffer.readerIndex();
|
||||||
while (totalWritten < localsize) {
|
while (remaining > 0) {
|
||||||
int written = buffer.getBytes(index, fileChannel, position, localsize - totalWritten);
|
int written = buffer.getBytes(index, fileChannel, position, remaining);
|
||||||
if (written < 0) {
|
if (written < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
totalWritten += written;
|
remaining -= written;
|
||||||
position += written;
|
position += written;
|
||||||
index += written;
|
index += written;
|
||||||
}
|
}
|
||||||
fileChannel.position(position);
|
fileChannel.position(position);
|
||||||
buffer.readerIndex(index);
|
buffer.readerIndex(index);
|
||||||
size += localsize;
|
size += localsize - remaining;
|
||||||
} finally {
|
} finally {
|
||||||
// Release the buffer as it was retained before and we not need a reference to it at all
|
// Release the buffer as it was retained before and we not need a reference to it at all
|
||||||
// See https://github.com/netty/netty/issues/1516
|
// See https://github.com/netty/netty/issues/1516
|
||||||
|
Loading…
x
Reference in New Issue
Block a user