01: package org.apache.lucene.index;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import org.apache.lucene.store.BufferedIndexInput;
21:
22: public class MockIndexInput extends BufferedIndexInput {
23: private byte[] buffer;
24: private int pointer = 0;
25: private long length;
26:
27: public MockIndexInput(byte[] bytes) {
28: buffer = bytes;
29: length = bytes.length;
30: }
31:
32: protected void readInternal(byte[] dest, int destOffset, int len) {
33: int remainder = len;
34: int start = pointer;
35: while (remainder != 0) {
36: // int bufferNumber = start / buffer.length;
37: int bufferOffset = start % buffer.length;
38: int bytesInBuffer = buffer.length - bufferOffset;
39: int bytesToCopy = bytesInBuffer >= remainder ? remainder
40: : bytesInBuffer;
41: System.arraycopy(buffer, bufferOffset, dest, destOffset,
42: bytesToCopy);
43: destOffset += bytesToCopy;
44: start += bytesToCopy;
45: remainder -= bytesToCopy;
46: }
47: pointer += len;
48: }
49:
50: public void close() {
51: // ignore
52: }
53:
54: protected void seekInternal(long pos) {
55: pointer = (int) pos;
56: }
57:
58: public long length() {
59: return length;
60: }
61:
62: }
|