From 3ea2cce5f2942153f8c51d39ec2444e4e19dcbdc Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sat, 25 Jul 2020 16:39:04 +0900 Subject: [PATCH] Optimize MultiBlobInputStream.read() Previously this allocated a byte array for every call. --- .../blobstore/config/LocalBlobStore.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java index e8d90e0cdf..20f5fc2c63 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java @@ -1010,12 +1010,21 @@ public final class LocalBlobStore implements BlobStore { @Override public int read() throws IOException { - byte[] b = new byte[1]; - int result = read(b, 0, b.length); - if (result == -1) { - return -1; + while (true) { + if (current == null) { + if (!blobs.hasNext()) { + return -1; + } + current = blobs.next().getPayload().openStream(); + } + int result = current.read(); + if (result == -1) { + current.close(); + current = null; + continue; + } + return result & 0x000000FF; } - return b[0] & 0x000000FF; } @Override