From 9b6a2fd95268c35032ba9bb41e29aefc98680980 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Wed, 8 Apr 2020 13:25:08 +0100 Subject: [PATCH] write to memmapped file in 8kb increments --- .../com/muwire/core/download/DownloadSession.groovy | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/download/DownloadSession.groovy b/core/src/main/groovy/com/muwire/core/download/DownloadSession.groovy index f48407f7..9042bb5c 100644 --- a/core/src/main/groovy/com/muwire/core/download/DownloadSession.groovy +++ b/core/src/main/groovy/com/muwire/core/download/DownloadSession.groovy @@ -183,15 +183,14 @@ class DownloadSession { mapped.position(position) byte[] tmp = new byte[0x1 << 13] + DataInputStream dis = new DataInputStream(is) while(mapped.hasRemaining()) { if (mapped.remaining() < tmp.length) tmp = new byte[mapped.remaining()] - int read = is.read(tmp) - if (read == -1) - throw new IOException() + dis.readFully(tmp) synchronized(this) { - mapped.put(tmp, 0, read) - dataSinceLastRead.addAndGet(read) + mapped.put(tmp) + dataSinceLastRead.addAndGet(tmp.length) pieces.markPartial(piece, mapped.position()) } }