1 package org.apache.lucene.store; 2 3 18 19 24 25 class RAMInputStream extends BufferedIndexInput implements Cloneable { 26 private RAMFile file; 27 private int pointer = 0; 28 private long length; 29 30 public RAMInputStream(RAMFile f) { 31 file = f; 32 length = file.length; 33 } 34 35 public void readInternal(byte[] dest, int destOffset, int len) { 36 int remainder = len; 37 int start = pointer; 38 while (remainder != 0) { 39 int bufferNumber = start/BUFFER_SIZE; 40 int bufferOffset = start%BUFFER_SIZE; 41 int bytesInBuffer = BUFFER_SIZE - bufferOffset; 42 int bytesToCopy = bytesInBuffer >= remainder ? remainder : bytesInBuffer; 43 byte[] buffer = (byte[])file.buffers.elementAt(bufferNumber); 44 System.arraycopy(buffer, bufferOffset, dest, destOffset, bytesToCopy); 45 destOffset += bytesToCopy; 46 start += bytesToCopy; 47 remainder -= bytesToCopy; 48 } 49 pointer += len; 50 } 51 52 public void close() { 53 } 54 55 public void seekInternal(long pos) { 56 pointer = (int)pos; 57 } 58 59 public long length() { 60 return length; 61 } 62 63 } 64 | Popular Tags |