. A
random-access input stream. Used for all Lucene index input operations.
Method from org.apache.lucene.store.IndexInput Detail: |
public Object clone() {
IndexInput clone = null;
try {
clone = (IndexInput)super.clone();
} catch (CloneNotSupportedException e) {}
clone.bytes = null;
clone.chars = null;
return clone;
}
Returns a clone of this stream.
Clones of a stream access the same data, and are positioned at the same
point as the stream they were cloned from.
Expert: Subclasses must ensure that clones may be positioned at
different points in the input from each other and from the stream they
were cloned from. |
abstract public void close() throws IOException
Closes the stream to further operations. |
abstract public long getFilePointer()
Returns the current position in this file, where the next read will
occur. |
abstract public long length()
The number of bytes in the file. |
abstract public byte readByte() throws IOException
Reads and returns a single byte. |
abstract public void readBytes(byte[] b,
int offset,
int len) throws IOException
Reads a specified number of bytes into an array at the specified offset. |
public void readBytes(byte[] b,
int offset,
int len,
boolean useBuffer) throws IOException {
// Default to ignoring useBuffer entirely
readBytes(b, offset, len);
}
Reads a specified number of bytes into an array at the
specified offset with control over whether the read
should be buffered (callers who have their own buffer
should pass in "false" for useBuffer). Currently only
BufferedIndexInput respects this parameter. |
public void readChars(char[] buffer,
int start,
int length) throws IOException {
final int end = start + length;
for (int i = start; i < end; i++) {
byte b = readByte();
if ((b & 0x80) == 0)
buffer[i] = (char)(b & 0x7F);
else if ((b & 0xE0) != 0xE0) {
buffer[i] = (char)(((b & 0x1F) < < 6)
| (readByte() & 0x3F));
} else
buffer[i] = (char)(((b & 0x0F) < < 12)
| ((readByte() & 0x3F) < < 6)
| (readByte() & 0x3F));
}
} Deprecated! -- - please use readString or readBytes
instead, and construct the string
from those utf8 bytes
Reads Lucene's old "modified UTF-8" encoded
characters into an array. |
public int readInt() throws IOException {
return ((readByte() & 0xFF) < < 24) | ((readByte() & 0xFF) < < 16)
| ((readByte() & 0xFF) < < 8) | (readByte() & 0xFF);
}
Reads four bytes and returns an int. |
public long readLong() throws IOException {
return (((long)readInt()) < < 32) | (readInt() & 0xFFFFFFFFL);
}
Reads eight bytes and returns a long. |
public String readString() throws IOException {
if (preUTF8Strings)
return readModifiedUTF8String();
int length = readVInt();
if (bytes == null || length > bytes.length)
bytes = new byte[(int) (length*1.25)];
readBytes(bytes, 0, length);
return new String(bytes, 0, length, "UTF-8");
}
|
public Map<String, String> readStringStringMap() throws IOException {
final Map< String,String > map = new HashMap< String,String >();
final int count = readInt();
for(int i=0;i< count;i++) {
final String key = readString();
final String val = readString();
map.put(key, val);
}
return map;
}
|
public int readVInt() throws IOException {
byte b = readByte();
int i = b & 0x7F;
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
b = readByte();
i |= (b & 0x7F) < < shift;
}
return i;
}
Reads an int stored in variable-length format. Reads between one and
five bytes. Smaller values take fewer bytes. Negative numbers are not
supported. |
public long readVLong() throws IOException {
byte b = readByte();
long i = b & 0x7F;
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
b = readByte();
i |= (b & 0x7FL) < < shift;
}
return i;
}
Reads a long stored in variable-length format. Reads between one and
nine bytes. Smaller values take fewer bytes. Negative numbers are not
supported. |
abstract public void seek(long pos) throws IOException
Sets current position in this file, where the next read will occur. |
public void setModifiedUTF8StringsMode() {
preUTF8Strings = true;
}
Call this if readString should read characters stored
in the old modified UTF8 format (length in java chars
and java's modified UTF8 encoding). This is used for
indices written pre-2.4 See LUCENE-510 for details. |
public void skipChars(int length) throws IOException {
for (int i = 0; i < length; i++) {
byte b = readByte();
if ((b & 0x80) == 0){
//do nothing, we only need one byte
}
else if ((b & 0xE0) != 0xE0) {
readByte();//read an additional byte
} else{
//read two additional bytes.
readByte();
readByte();
}
}
} Deprecated! this - method operates on old "modified utf8" encoded
strings
Expert
Similar to #readChars(char[], int, int) but does not do any conversion operations on the bytes it is reading in. It still
has to invoke #readByte() just as #readChars(char[], int, int) does, but it does not need a buffer to store anything
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
how many more bytes to read |