Change back to FileChannel but by block
This commit is contained in:
parent
7c34781672
commit
1f696fa2f1
@ -287,20 +287,19 @@ public abstract class AbstractDiskHttpData extends AbstractHttpData {
|
||||
// must copy
|
||||
FileInputStream inputStream = new FileInputStream(file);
|
||||
FileOutputStream outputStream = new FileOutputStream(dest);
|
||||
byte [] buffer = new byte[8192];
|
||||
long destsize = 0;
|
||||
while (true) {
|
||||
int len = inputStream.read(buffer);
|
||||
if (len < 0) {
|
||||
break;
|
||||
FileChannel in = inputStream.getChannel();
|
||||
FileChannel out = outputStream.getChannel();
|
||||
int chunkSize = 8196;
|
||||
long position = 0;
|
||||
while (position < size) {
|
||||
if (chunksize < size - position) {
|
||||
chunksize = size - position;
|
||||
}
|
||||
destsize += len;
|
||||
outputStream.write(buffer, 0, len);
|
||||
position += in.transferTo(position, chunkSize , out);
|
||||
}
|
||||
outputStream.flush();
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
if (destsize == size) {
|
||||
in.close();
|
||||
out.close();
|
||||
if (position == size) {
|
||||
file.delete();
|
||||
file = dest;
|
||||
isRenamed = true;
|
||||
|
Loading…
Reference in New Issue
Block a user