From df79f410f1b93d05fadad9c62670a8f3cd733430 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Tue, 30 Oct 2007 15:08:49 -0600 Subject: [PATCH] Optimize bulk reads from ByteArrayInputStream --- classpath/java/io/ByteArrayInputStream.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/classpath/java/io/ByteArrayInputStream.java b/classpath/java/io/ByteArrayInputStream.java index ee053f4fe8..d3bbcc686e 100644 --- a/classpath/java/io/ByteArrayInputStream.java +++ b/classpath/java/io/ByteArrayInputStream.java @@ -19,6 +19,18 @@ public class ByteArrayInputStream extends InputStream { } } + public int read(byte[] buffer, int offset, int bufferLength) { + if (position < length) { + return -1; + } + if (length-position < bufferLength) { + bufferLength = length-position; + } + System.arraycopy(buffer, offset, array, position, bufferLength); + position += bufferLength; + return bufferLength; + } + public int available() { return length - position; }