Class DataInput
- java.lang.Object
-
- org.apache.lucene.store.DataInput
-
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
ByteArrayDataInput,ByteBuffersDataInput,FST.BytesReader,IndexInput,InputStreamDataInput,PagedBytes.PagedBytesDataInput
public abstract class DataInput extends Object implements Cloneable
Abstract base class for performing read operations of Lucene's low-level data types.DataInputmay only be used from one thread, because it is not thread safe (it keeps internal state like file position). To allow multithreaded use, everyDataInputinstance must be cloned before used in another thread. Subclasses must therefore implementclone(), returning a newDataInputwhich operates on the same underlying resource, but positioned independently.
-
-
Constructor Summary
Constructors Constructor Description DataInput()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DataInputclone()Returns a clone of this stream.abstract bytereadByte()Reads and returns a single byte.abstract voidreadBytes(byte[] b, int offset, int len)Reads a specified number of bytes into an array at the specified offset.voidreadBytes(byte[] b, int offset, int len, boolean useBuffer)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).intreadInt()Reads four bytes and returns an int.voidreadLELongs(long[] dst, int offset, int length)Read a specified number of longs with the little endian byte order.longreadLong()Reads eight bytes and returns a long.Map<String,String>readMapOfStrings()Reads a Map<String,String> previously written withDataOutput.writeMapOfStrings(Map).Set<String>readSetOfStrings()Reads a Set<String> previously written withDataOutput.writeSetOfStrings(Set).shortreadShort()Reads two bytes and returns a short.StringreadString()Reads a string.intreadVInt()Reads an int stored in variable-length format.longreadVLong()Reads a long stored in variable-length format.intreadZInt()Read azig-zag-encodedvariable-lengthinteger.longreadZLong()Read azig-zag-encodedvariable-lengthinteger.voidskipBytes(long numBytes)Skip overnumBytesbytes.
-
-
-
Method Detail
-
readByte
public abstract byte readByte() throws IOExceptionReads and returns a single byte.- Throws:
IOException- See Also:
DataOutput.writeByte(byte)
-
readBytes
public abstract void readBytes(byte[] b, int offset, int len) throws IOExceptionReads a specified number of bytes into an array at the specified offset.- Parameters:
b- the array to read bytes intooffset- the offset in the array to start storing byteslen- the number of bytes to read- Throws:
IOException- See Also:
DataOutput.writeBytes(byte[],int)
-
readBytes
public void readBytes(byte[] b, int offset, int len, boolean useBuffer) throws IOExceptionReads 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 onlyBufferedIndexInputrespects this parameter.- Parameters:
b- the array to read bytes intooffset- the offset in the array to start storing byteslen- the number of bytes to readuseBuffer- set to false if the caller will handle buffering.- Throws:
IOException- See Also:
DataOutput.writeBytes(byte[],int)
-
readShort
public short readShort() throws IOExceptionReads two bytes and returns a short.- Throws:
IOException- See Also:
DataOutput.writeByte(byte)
-
readInt
public int readInt() throws IOExceptionReads four bytes and returns an int.- Throws:
IOException- See Also:
DataOutput.writeInt(int)
-
readVInt
public int readVInt() throws IOExceptionReads an int stored in variable-length format. Reads between one and five bytes. Smaller values take fewer bytes. Negative numbers are supported, but should be avoided.The format is described further in
DataOutput.writeVInt(int).- Throws:
IOException- See Also:
DataOutput.writeVInt(int)
-
readZInt
public int readZInt() throws IOExceptionRead azig-zag-encodedvariable-lengthinteger.- Throws:
IOException- See Also:
DataOutput.writeZInt(int)
-
readLong
public long readLong() throws IOExceptionReads eight bytes and returns a long.- Throws:
IOException- See Also:
DataOutput.writeLong(long)
-
readLELongs
public void readLELongs(long[] dst, int offset, int length) throws IOExceptionRead a specified number of longs with the little endian byte order.This method can be used to read longs whose bytes have been
reversedat write time:for (long l : longs) { output.writeLong(Long.reverseBytes(l)); }- Throws:
IOException- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
readVLong
public long readVLong() throws IOExceptionReads a long stored in variable-length format. Reads between one and nine bytes. Smaller values take fewer bytes. Negative numbers are not supported.The format is described further in
DataOutput.writeVInt(int).- Throws:
IOException- See Also:
DataOutput.writeVLong(long)
-
readZLong
public long readZLong() throws IOExceptionRead azig-zag-encodedvariable-lengthinteger. Reads between one and ten bytes.- Throws:
IOException- See Also:
DataOutput.writeZLong(long)
-
readString
public String readString() throws IOException
Reads a string.- Throws:
IOException- See Also:
DataOutput.writeString(String)
-
clone
public DataInput 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.
-
readMapOfStrings
public Map<String,String> readMapOfStrings() throws IOException
Reads a Map<String,String> previously written withDataOutput.writeMapOfStrings(Map).- Returns:
- An immutable map containing the written contents.
- Throws:
IOException
-
readSetOfStrings
public Set<String> readSetOfStrings() throws IOException
Reads a Set<String> previously written withDataOutput.writeSetOfStrings(Set).- Returns:
- An immutable set containing the written contents.
- Throws:
IOException
-
skipBytes
public void skipBytes(long numBytes) throws IOExceptionSkip overnumBytesbytes. The contract on this method is that it should have the same behavior as reading the same number of bytes into a buffer and discarding its content. Negative values ofnumBytesare not supported.- Throws:
IOException
-
-