Class DataInput
- java.lang.Object
-
- org.apache.lucene.store.DataInput
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
ByteArrayDataInput
,ByteBuffersDataInput
,ByteSliceReader
,FST.BytesReader
,IndexInput
,InputStreamDataInput
,PagedBytes.PagedBytesDataInput
public abstract class DataInput extends java.lang.Object implements java.lang.Cloneable
Abstract base class for performing read operations of Lucene's low-level data types.DataInput
may only be used from one thread, because it is not thread safe (it keeps internal state like file position). To allow multithreaded use, everyDataInput
instance must be cloned before used in another thread. Subclasses must therefore implementclone()
, returning a newDataInput
which operates on the same underlying resource, but positioned independently.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
SKIP_BUFFER_SIZE
private byte[]
skipBuffer
-
Constructor Summary
Constructors Constructor Description DataInput()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description DataInput
clone()
Returns a clone of this stream.abstract byte
readByte()
Reads and returns a single byte.abstract void
readBytes(byte[] b, int offset, int len)
Reads a specified number of bytes into an array at the specified offset.void
readBytes(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).int
readInt()
Reads four bytes and returns an int.void
readLELongs(long[] dst, int offset, int length)
Read a specified number of longs with the little endian byte order.long
readLong()
Reads eight bytes and returns a long.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)
.short
readShort()
Reads two bytes and returns a short.java.lang.String
readString()
Reads a string.int
readVInt()
Reads an int stored in variable-length format.long
readVLong()
Reads a long stored in variable-length format.private long
readVLong(boolean allowNegative)
int
readZInt()
Read azig-zag
-encodedvariable-length
integer.long
readZLong()
Read azig-zag
-encodedvariable-length
integer.void
skipBytes(long numBytes)
Skip overnumBytes
bytes.
-
-
-
Field Detail
-
SKIP_BUFFER_SIZE
private static final int SKIP_BUFFER_SIZE
- See Also:
- Constant Field Values
-
skipBuffer
private byte[] skipBuffer
-
-
Method Detail
-
readByte
public abstract byte readByte() throws java.io.IOException
Reads 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.IOException
Reads 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.IOException
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 onlyBufferedIndexInput
respects 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.IOException
Reads two bytes and returns a short.- Throws:
java.io.IOException
- See Also:
DataOutput.writeByte(byte)
-
readInt
public int readInt() throws java.io.IOException
Reads four bytes and returns an int.- Throws:
java.io.IOException
- See Also:
DataOutput.writeInt(int)
-
readVInt
public int readVInt() throws java.io.IOException
Reads 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.IOException
Read azig-zag
-encodedvariable-length
integer.- Throws:
java.io.IOException
- See Also:
DataOutput.writeZInt(int)
-
readLong
public long readLong() throws java.io.IOException
Reads eight bytes and returns a long.- Throws:
java.io.IOException
- See Also:
DataOutput.writeLong(long)
-
readLELongs
public void readLELongs(long[] dst, int offset, int length) throws java.io.IOException
Read a specified number of longs with the little endian byte order.This method can be used to read longs whose bytes have been
reversed
at write time:for (long l : longs) { output.writeLong(Long.reverseBytes(l)); }
- Throws:
java.io.IOException
-
readVLong
public long readVLong() throws java.io.IOException
Reads 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.IOException
Read azig-zag
-encodedvariable-length
integer. Reads between one and ten bytes.- Throws:
java.io.IOException
- See Also:
DataOutput.writeZLong(long)
-
readString
public java.lang.String readString() throws java.io.IOException
Reads 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:
clone
in classjava.lang.Object
-
readMapOfStrings
public java.util.Map<java.lang.String,java.lang.String> readMapOfStrings() throws java.io.IOException
Reads 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.IOException
Reads a Set<String> previously written withDataOutput.writeSetOfStrings(Set)
.- Returns:
- An immutable set containing the written contents.
- Throws:
java.io.IOException
-
skipBytes
public void skipBytes(long numBytes) throws java.io.IOException
Skip overnumBytes
bytes. 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 ofnumBytes
are not supported.- Throws:
java.io.IOException
-
-