Permalink
Browse files

Merge pull request #399 from fredericBregier/3

Proposal to fix issue #398 by replacing transferTo by using loop on FileChannel
  • Loading branch information...
fredericBregier committed Jun 15, 2012
2 parents df11cfa + 1f696fa commit 6d29d2feb193214b5e548f570f3b8e25a1e3637e
@@ -289,10 +289,17 @@ public boolean renameTo(File dest) throws IOException {
FileOutputStream outputStream = new FileOutputStream(dest);
FileChannel in = inputStream.getChannel();
FileChannel out = outputStream.getChannel();
- long destsize = in.transferTo(0, size, out);
+ int chunkSize = 8196;
+ long position = 0;
+ while (position < size) {
+ if (chunksize < size - position) {
+ chunksize = size - position;
+ }
+ position += in.transferTo(position, chunkSize , out);
+ }
in.close();
out.close();
- if (destsize == size) {
+ if (position == size) {
file.delete();
file = dest;
isRenamed = true;

0 comments on commit 6d29d2f

Please sign in to comment.