From 992d1ade00b9a37596aa28eb8c4dfba252259dd2 Mon Sep 17 00:00:00 2001 From: Doug Cutting Date: Wed, 31 Oct 2001 00:12:30 +0000 Subject: [PATCH] Fixed a bug where RAMInputStream could not read across more than across a single buffer boundary. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@149615 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/store/RAMDirectory.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/java/org/apache/lucene/store/RAMDirectory.java b/src/java/org/apache/lucene/store/RAMDirectory.java index 93dbc931012..629621a9152 100644 --- a/src/java/org/apache/lucene/store/RAMDirectory.java +++ b/src/java/org/apache/lucene/store/RAMDirectory.java @@ -160,21 +160,22 @@ final class RAMInputStream extends InputStream implements Cloneable { /** InputStream methods */ public final void readInternal(byte[] dest, int destOffset, int len) { - int bufferNumber = pointer/InputStream.BUFFER_SIZE; - int bufferOffset = pointer%InputStream.BUFFER_SIZE; - int bytesInBuffer = InputStream.BUFFER_SIZE - bufferOffset; - int bytesToCopy = bytesInBuffer >= len ? len : bytesInBuffer; - byte[] buffer = (byte[])file.buffers.elementAt(bufferNumber); - System.arraycopy(buffer, bufferOffset, dest, destOffset, bytesToCopy); - - if (bytesToCopy < len) { // not all in one buffer + int remainder = len; + int start = pointer; + while (remainder != 0) { + int bufferNumber = start/InputStream.BUFFER_SIZE; + int bufferOffset = start%InputStream.BUFFER_SIZE; + int bytesInBuffer = InputStream.BUFFER_SIZE - bufferOffset; + int bytesToCopy = bytesInBuffer >= remainder ? remainder : bytesInBuffer; + byte[] buffer = (byte[])file.buffers.elementAt(bufferNumber); + System.arraycopy(buffer, bufferOffset, dest, destOffset, bytesToCopy); destOffset += bytesToCopy; - bytesToCopy = len - bytesToCopy; // remaining bytes - buffer = (byte[])file.buffers.elementAt(bufferNumber+1); - System.arraycopy(buffer, 0, dest, destOffset, bytesToCopy); + start += bytesToCopy; + remainder -= bytesToCopy; } pointer += len; } + public final void close() { }