From e380298cf99a021be98894f9a6e78fee2045eba0 Mon Sep 17 00:00:00 2001 From: Lukas W Date: Fri, 2 Aug 2024 12:43:47 +0000 Subject: [PATCH] Improve project unzipping performance --- .../com/sheepit/client/ChunkInputStream.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/sheepit/client/ChunkInputStream.java b/src/main/java/com/sheepit/client/ChunkInputStream.java index e557b01..fd52b98 100644 --- a/src/main/java/com/sheepit/client/ChunkInputStream.java +++ b/src/main/java/com/sheepit/client/ChunkInputStream.java @@ -51,4 +51,25 @@ public class ChunkInputStream extends InputStream { return result; } + + /// Improve throughput by offering method to read whole block of bytes at once + @Override public int read(byte[] b, int off, int len) throws IOException { + int bytesRead = -1; + + while (bytesRead == -1) { + bytesRead = currentStream.read(b, off, len); + + if (bytesRead == -1) { + try { + prepareNextChunk(); + } + catch (NoSuchElementException e) { + /// This was the last chunk + return -1; + } + } + } + + return bytesRead; + } }