1 package org.apache.lucene.store;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.io.IOException;
21 import java.io.Closeable;
23 /** Abstract base class for input from a file in a {@link Directory}. A
24 * random-access input stream. Used for all Lucene index input operations.
27 public abstract class IndexInput extends DataInput implements Cloneable,Closeable {
29 protected byte[] copyBuf = null;
34 * Similar to {@link #readChars(char[], int, int)} but does not do any conversion operations on the bytes it is reading in. It still
35 * has to invoke {@link #readByte()} just as {@link #readChars(char[], int, int)} does, but it does not need a buffer to store anything
36 * and it does not have to do any of the bitwise operations, since we don't actually care what is in the byte except to determine
37 * how many more bytes to read
38 * @param length The number of chars to read
39 * @deprecated this method operates on old "modified utf8" encoded
43 public void skipChars(int length) throws IOException{
44 for (int i = 0; i < length; i++) {
47 //do nothing, we only need one byte
48 } else if ((b & 0xE0) != 0xE0) {
49 readByte();//read an additional byte
51 //read two additional bytes.
58 /** Closes the stream to further operations. */
59 public abstract void close() throws IOException;
61 /** Returns the current position in this file, where the next read will
65 public abstract long getFilePointer();
67 /** Sets current position in this file, where the next read will occur.
68 * @see #getFilePointer()
70 public abstract void seek(long pos) throws IOException;
72 /** The number of bytes in the file. */
73 public abstract long length();
76 * Copies <code>numBytes</code> bytes to the given {@link IndexOutput}.
78 * <b>NOTE:</b> this method uses an intermediate buffer to copy the bytes.
79 * Consider overriding it in your implementation, if you can make a better,
82 * <b>NOTE</b> ensure that there are enough bytes in the input to copy to
83 * output. Otherwise, different exceptions may be thrown, depending on the
86 public void copyBytes(IndexOutput out, long numBytes) throws IOException {
87 assert numBytes >= 0: "numBytes=" + numBytes;
89 if (copyBuf == null) {
90 copyBuf = new byte[BufferedIndexInput.BUFFER_SIZE];
93 while (numBytes > 0) {
94 final int toCopy = (int) (numBytes > copyBuf.length ? copyBuf.length : numBytes);
95 readBytes(copyBuf, 0, toCopy);
96 out.writeBytes(copyBuf, 0, toCopy);