Proposal to fix issue #398 by replacing FileChannel.transferTo by manual loop to prevent usage of mmap unde the wood by the JVM, while the optimization will be less efficient.

This commit is contained in:
Frédéric Brégier 2012-06-15 09:14:37 +03:00
parent df11cfab25
commit 7c34781672

View File

@ -287,11 +287,19 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
// must copy
FileInputStream inputStream = new FileInputStream(file);
FileOutputStream outputStream = new FileOutputStream(dest);
FileChannel in = inputStream.getChannel();
FileChannel out = outputStream.getChannel();
long destsize = in.transferTo(0, size, out);
in.close();
out.close();
byte [] buffer = new byte[8192];
long destsize = 0;
while (true) {
int len = inputStream.read(buffer);
if (len < 0) {
break;
}
destsize += len;
outputStream.write(buffer, 0, len);
}
outputStream.flush();
inputStream.close();
outputStream.close();
if (destsize == size) {
file.delete();
file = dest;