Close channel when needed and optimize force() position after multiple writes not at each step
This commit is contained in:
parent
94b10d2d02
commit
65876fa7fb
@ -116,9 +116,9 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
int written = 0;
|
int written = 0;
|
||||||
while (written < size) {
|
while (written < size) {
|
||||||
written += localfileChannel.write(byteBuffer);
|
written += localfileChannel.write(byteBuffer);
|
||||||
localfileChannel.force(false);
|
|
||||||
}
|
}
|
||||||
buffer.readerIndex(buffer.readerIndex() + written);
|
buffer.readerIndex(buffer.readerIndex() + written);
|
||||||
|
localfileChannel.force(false);
|
||||||
localfileChannel.close();
|
localfileChannel.close();
|
||||||
completed = true;
|
completed = true;
|
||||||
}
|
}
|
||||||
@ -143,7 +143,6 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
}
|
}
|
||||||
while (written < localsize) {
|
while (written < localsize) {
|
||||||
written += fileChannel.write(byteBuffer);
|
written += fileChannel.write(byteBuffer);
|
||||||
fileChannel.force(false);
|
|
||||||
}
|
}
|
||||||
size += localsize;
|
size += localsize;
|
||||||
buffer.readerIndex(buffer.readerIndex() + written);
|
buffer.readerIndex(buffer.readerIndex() + written);
|
||||||
@ -156,6 +155,7 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
FileOutputStream outputStream = new FileOutputStream(file);
|
FileOutputStream outputStream = new FileOutputStream(file);
|
||||||
fileChannel = outputStream.getChannel();
|
fileChannel = outputStream.getChannel();
|
||||||
}
|
}
|
||||||
|
fileChannel.force(false);
|
||||||
fileChannel.close();
|
fileChannel.close();
|
||||||
fileChannel = null;
|
fileChannel = null;
|
||||||
completed = true;
|
completed = true;
|
||||||
@ -195,9 +195,10 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
while (read > 0) {
|
while (read > 0) {
|
||||||
byteBuffer.position(read).flip();
|
byteBuffer.position(read).flip();
|
||||||
written += localfileChannel.write(byteBuffer);
|
written += localfileChannel.write(byteBuffer);
|
||||||
localfileChannel.force(false);
|
|
||||||
read = inputStream.read(bytes);
|
read = inputStream.read(bytes);
|
||||||
}
|
}
|
||||||
|
localfileChannel.force(false);
|
||||||
|
localfileChannel.close();
|
||||||
size = written;
|
size = written;
|
||||||
if (definedSize > 0 && definedSize < size) {
|
if (definedSize > 0 && definedSize < size) {
|
||||||
file.delete();
|
file.delete();
|
||||||
@ -300,6 +301,8 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
|||||||
FileChannel in = inputStream.getChannel();
|
FileChannel in = inputStream.getChannel();
|
||||||
FileChannel out = outputStream.getChannel();
|
FileChannel out = outputStream.getChannel();
|
||||||
long destsize = in.transferTo(0, size, out);
|
long destsize = in.transferTo(0, size, out);
|
||||||
|
in.close();
|
||||||
|
out.close();
|
||||||
if (destsize == size) {
|
if (destsize == size) {
|
||||||
file.delete();
|
file.delete();
|
||||||
file = dest;
|
file = dest;
|
||||||
|
Loading…
Reference in New Issue
Block a user