forked from I2P_Developers/i2p.i2p
* i2psnark: File allocation cleanup to use less heap
This commit is contained in:
@ -762,27 +762,19 @@ public class Storage
|
|||||||
openRAF(nr, false); // RW
|
openRAF(nr, false); // RW
|
||||||
// XXX - Is this the best way to make sure we have enough space for
|
// XXX - Is this the best way to make sure we have enough space for
|
||||||
// the whole file?
|
// the whole file?
|
||||||
|
long remaining = lengths[nr];
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
listener.storageCreateFile(this, names[nr], lengths[nr]);
|
listener.storageCreateFile(this, names[nr], remaining);
|
||||||
final int ZEROBLOCKSIZE = piece_size;
|
final int ZEROBLOCKSIZE = (int) Math.min(remaining, 32*1024);
|
||||||
byte[] zeros;
|
byte[] zeros = new byte[ZEROBLOCKSIZE];
|
||||||
try {
|
while (remaining > 0) {
|
||||||
zeros = new byte[ZEROBLOCKSIZE];
|
int size = (int) Math.min(remaining, ZEROBLOCKSIZE);
|
||||||
} catch (OutOfMemoryError oom) {
|
rafs[nr].write(zeros, 0, size);
|
||||||
throw new IOException(oom.toString());
|
remaining -= size;
|
||||||
}
|
}
|
||||||
int i;
|
|
||||||
for (i = 0; i < lengths[nr]/ZEROBLOCKSIZE; i++)
|
|
||||||
{
|
|
||||||
rafs[nr].write(zeros);
|
|
||||||
if (listener != null)
|
|
||||||
listener.storageAllocated(this, ZEROBLOCKSIZE);
|
|
||||||
}
|
|
||||||
int size = (int)(lengths[nr] - i*ZEROBLOCKSIZE);
|
|
||||||
rafs[nr].write(zeros, 0, size);
|
|
||||||
// caller will close rafs[nr]
|
// caller will close rafs[nr]
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
listener.storageAllocated(this, size);
|
listener.storageAllocated(this, lengths[nr]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user