1 package org.apache.lucene.index; 2 3 18 19 import org.apache.lucene.store.InputStream; 20 21 import java.io.IOException ; 22 23 public class MockInputStream extends InputStream { 24 private byte[] buffer; 25 private int pointer = 0; 26 27 public MockInputStream(byte[] bytes) { 28 buffer = bytes; 29 length = bytes.length; 30 } 31 32 protected void readInternal(byte[] dest, int destOffset, int len) 33 throws IOException { 34 int remainder = len; 35 int start = pointer; 36 while (remainder != 0) { 37 int bufferOffset = start % buffer.length; 39 int bytesInBuffer = buffer.length - bufferOffset; 40 int bytesToCopy = bytesInBuffer >= remainder ? remainder : bytesInBuffer; 41 System.arraycopy(buffer, bufferOffset, dest, destOffset, bytesToCopy); 42 destOffset += bytesToCopy; 43 start += bytesToCopy; 44 remainder -= bytesToCopy; 45 } 46 pointer += len; 47 } 48 49 public void close() throws IOException { 50 } 52 53 protected void seekInternal(long pos) throws IOException { 54 pointer = (int) pos; 55 } 56 } 57 | Popular Tags |