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; + } }