Index: src/java/org/apache/lucene/store/RAMInputStream.java =================================================================== --- src/java/org/apache/lucene/store/RAMInputStream.java (revision 598680) +++ src/java/org/apache/lucene/store/RAMInputStream.java (working copy) @@ -84,11 +84,11 @@ } private final void switchCurrentBuffer() throws IOException { - if (currentBufferIndex >= file.buffers.size()) { + if (currentBufferIndex >= file.numBuffers()) { // end of file reached, no more buffers left throw new IOException("Read past EOF"); } else { - currentBuffer = (byte[]) file.buffers.get(currentBufferIndex); + currentBuffer = (byte[]) file.getBuffer(currentBufferIndex); bufferPosition = 0; bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex; long buflen = length - bufferStart; Index: src/java/org/apache/lucene/store/RAMOutputStream.java =================================================================== --- src/java/org/apache/lucene/store/RAMOutputStream.java (revision 598680) +++ src/java/org/apache/lucene/store/RAMOutputStream.java (working copy) @@ -63,7 +63,7 @@ if (nextPos > end) { // at the last buffer length = (int)(end - pos); } - out.writeBytes((byte[])file.buffers.get(buffer++), length); + out.writeBytes((byte[])file.getBuffer(buffer++), length); pos = nextPos; } } @@ -124,10 +124,10 @@ } private final void switchCurrentBuffer() throws IOException { - if (currentBufferIndex == file.buffers.size()) { + if (currentBufferIndex == file.numBuffers()) { currentBuffer = file.addBuffer(BUFFER_SIZE); } else { - currentBuffer = (byte[]) file.buffers.get(currentBufferIndex); + currentBuffer = (byte[]) file.getBuffer(currentBufferIndex); } bufferPosition = 0; bufferStart = (long) BUFFER_SIZE * (long) currentBufferIndex; Index: src/java/org/apache/lucene/store/RAMFile.java =================================================================== --- src/java/org/apache/lucene/store/RAMFile.java (revision 598680) +++ src/java/org/apache/lucene/store/RAMFile.java (working copy) @@ -24,8 +24,7 @@ private static final long serialVersionUID = 1l; - // Direct read-only access to state supported for streams since a writing stream implies no other concurrent streams - ArrayList buffers = new ArrayList(); + private ArrayList buffers = new ArrayList(); long length; RAMDirectory directory; long sizeInBytes; // Only maintained if in a directory; updates synchronized on directory @@ -58,8 +57,7 @@ this.lastModified = lastModified; } - // Only one writing stream with no concurrent reading streams, so no file synchronization required - final byte[] addBuffer(int size) { + final synchronized byte[] addBuffer(int size) { byte[] buffer = newBuffer(size); if (directory!=null) synchronized (directory) { // Ensure addition of buffer and adjustment to directory size are atomic wrt directory @@ -72,6 +70,14 @@ return buffer; } + final synchronized byte[] getBuffer(int index) { + return (byte[]) buffers.get(index); + } + + final synchronized int numBuffers() { + return buffers.size(); + } + /** * Expert: allocate a new buffer. * Subclasses can allocate differently.