Class DataInput
- java.lang.Object
-
- org.apache.lucene.store.DataInput
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
ByteArrayDataInput,ByteBuffersDataInput,ByteSliceReader,EndiannessReverserDataInput,FST.BytesReader,IndexInput,InputStreamDataInput,PagedBytes.PagedBytesDataInput
public abstract class DataInput extends java.lang.Object implements java.lang.CloneableAbstract 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).voidreadFloats(float[] floats, int offset, int len)Reads a specified number of floats into an array at the specified offset.intreadInt()Reads four bytes and returns an int (LE byte order).voidreadInts(int[] dst, int offset, int length)Reads a specified number of ints into an array at the specified offset.longreadLong()Reads eight bytes and returns a long (LE byte order).voidreadLongs(long[] dst, int offset, int length)Read a specified number of longs.java.util.Map<java.lang.String,java.lang.String>readMapOfStrings()Reads a Map<String,String> previously written withDataOutput.writeMapOfStrings(Map).java.util.Set<java.lang.String>readSetOfStrings()Reads a Set<String> previously written withDataOutput.writeSetOfStrings(Set).shortreadShort()Reads two bytes and returns a short (LE byte order).java.lang.StringreadString()Reads a string.intreadVInt()Reads an int stored in variable-length format.longreadVLong()Reads a long stored in variable-length format.private longreadVLong(boolean allowNegative)intreadZInt()Read azig-zag-encodedvariable-lengthinteger.longreadZLong()Read azig-zag-encodedvariable-lengthinteger.abstract voidskipBytes(long numBytes)Skip overnumBytesbytes.
-
-
-
Method Detail
-
readByte
public abstract byte readByte() throws java.io.IOExceptionReads and returns a single byte.- Throws:
java.io.IOException- See Also:
DataOutput.writeByte(byte)
-
readBytes
public abstract void readBytes(byte[] b, int offset, int len) throws java.io.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:
java.io.IOException- See Also:
DataOutput.writeBytes(byte[],int)
-
readBytes
public void readBytes(byte[] b, int offset, int len, boolean useBuffer) throws java.io.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:
java.io.IOException- See Also:
DataOutput.writeBytes(byte[],int)
-
readShort
public short readShort() throws java.io.IOExceptionReads two bytes and returns a short (LE byte order).- Throws:
java.io.IOException- See Also:
DataOutput.writeShort(short),BitUtil.VH_LE_SHORT
-
readInt
public int readInt() throws java.io.IOExceptionReads four bytes and returns an int (LE byte order).- Throws:
java.io.IOException- See Also:
DataOutput.writeInt(int),BitUtil.VH_LE_INT
-
readVInt
public int readVInt() throws java.io.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:
java.io.IOException- See Also:
DataOutput.writeVInt(int)
-
readZInt
public int readZInt() throws java.io.IOExceptionRead azig-zag-encodedvariable-lengthinteger.- Throws:
java.io.IOException- See Also:
DataOutput.writeZInt(int)
-
readLong
public long readLong() throws java.io.IOExceptionReads eight bytes and returns a long (LE byte order).- Throws:
java.io.IOException- See Also:
DataOutput.writeLong(long),BitUtil.VH_LE_LONG
-
readLongs
public void readLongs(long[] dst, int offset, int length) throws java.io.IOExceptionRead a specified number of longs.- Throws:
java.io.IOException
-
readInts
public void readInts(int[] dst, int offset, int length) throws java.io.IOExceptionReads a specified number of ints into an array at the specified offset.- Parameters:
dst- the array to read bytes intooffset- the offset in the array to start storing intslength- the number of ints to read- Throws:
java.io.IOException
-
readFloats
public void readFloats(float[] floats, int offset, int len) throws java.io.IOExceptionReads a specified number of floats into an array at the specified offset.- Parameters:
floats- the array to read bytes intooffset- the offset in the array to start storing floatslen- the number of floats to read- Throws:
java.io.IOException
-
readVLong
public long readVLong() throws java.io.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:
java.io.IOException- See Also:
DataOutput.writeVLong(long)
-
readVLong
private long readVLong(boolean allowNegative) throws java.io.IOException- Throws:
java.io.IOException
-
readZLong
public long readZLong() throws java.io.IOExceptionRead azig-zag-encodedvariable-lengthinteger. Reads between one and ten bytes.- Throws:
java.io.IOException- See Also:
DataOutput.writeZLong(long)
-
readString
public java.lang.String readString() throws java.io.IOExceptionReads a string.- Throws:
java.io.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.
- Overrides:
clonein classjava.lang.Object
-
readMapOfStrings
public java.util.Map<java.lang.String,java.lang.String> readMapOfStrings() throws java.io.IOExceptionReads a Map<String,String> previously written withDataOutput.writeMapOfStrings(Map).- Returns:
- An immutable map containing the written contents.
- Throws:
java.io.IOException
-
readSetOfStrings
public java.util.Set<java.lang.String> readSetOfStrings() throws java.io.IOExceptionReads a Set<String> previously written withDataOutput.writeSetOfStrings(Set).- Returns:
- An immutable set containing the written contents.
- Throws:
java.io.IOException
-
skipBytes
public abstract void skipBytes(long numBytes) throws java.io.IOExceptionSkip overnumBytesbytes. This method may skip bytes in whatever way is most optimal, and may not have the same behavior as reading the skipped bytes. In general, negativenumBytesare not supported.- Throws:
java.io.IOException
-
-