write to memmapped file in 8kb increments

pull/53/head
Zlatin Balevsky 2020-04-08 13:25:08 +01:00
parent 85ad3109f9
commit 9b6a2fd952
1 changed files with 4 additions and 5 deletions

View File

@ -183,15 +183,14 @@ class DownloadSession {
mapped.position(position) mapped.position(position)
byte[] tmp = new byte[0x1 << 13] byte[] tmp = new byte[0x1 << 13]
DataInputStream dis = new DataInputStream(is)
while(mapped.hasRemaining()) { while(mapped.hasRemaining()) {
if (mapped.remaining() < tmp.length) if (mapped.remaining() < tmp.length)
tmp = new byte[mapped.remaining()] tmp = new byte[mapped.remaining()]
int read = is.read(tmp) dis.readFully(tmp)
if (read == -1)
throw new IOException()
synchronized(this) { synchronized(this) {
mapped.put(tmp, 0, read) mapped.put(tmp)
dataSinceLastRead.addAndGet(read) dataSinceLastRead.addAndGet(tmp.length)
pieces.markPartial(piece, mapped.position()) pieces.markPartial(piece, mapped.position())
} }
} }