From 2ab1f102c51eae2d71794eb56fc72786ad654300 Mon Sep 17 00:00:00 2001 From: Tamara Braun Date: Wed, 2 Sep 2020 21:38:55 +0200 Subject: [PATCH] Speed up WrappedByteArrayOutputStream This stream is used in downloading to a byte array and forced any data downloaded to run through a hot byte-byte copy loop taking up to 15% of the runtime when downloading a blob in profiling. --- .../storage/core/WrappedByteArrayOutputStream.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/microsoft-azure-storage/src/com/microsoft/azure/storage/core/WrappedByteArrayOutputStream.java b/microsoft-azure-storage/src/com/microsoft/azure/storage/core/WrappedByteArrayOutputStream.java index 9627c9c17..edb1d8ec7 100644 --- a/microsoft-azure-storage/src/com/microsoft/azure/storage/core/WrappedByteArrayOutputStream.java +++ b/microsoft-azure-storage/src/com/microsoft/azure/storage/core/WrappedByteArrayOutputStream.java @@ -46,4 +46,14 @@ public void write(int b) throws IOException { this.buffer[this.offset] = (byte) b; this.offset++; } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + if (this.offset + len > this.buffer.length) { + throw new IOException(SR.CONTENT_LENGTH_MISMATCH); + } + + System.arraycopy(b, off, this.buffer, this.offset, len); + this.offset += len; + } }