Class DataInput
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
ByteArrayDataInput
,ByteBuffersDataInput
,FST.BytesReader
,IndexInput
,InputStreamDataInput
,PagedBytes.PagedBytesDataInput
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, every DataInput
instance
must be cloned before used in another thread. Subclasses must therefore implement clone()
, returning a new DataInput
which operates on the same underlying resource, but
positioned independently.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionclone()
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).void
readFloats
(float[] floats, int offset, int len) Reads a specified number of floats into an array at the specified offset.int
readInt()
Reads four bytes and returns an int (LE byte order).long
readLong()
Reads eight bytes and returns a long (LE byte order).void
readLongs
(long[] dst, int offset, int length) Read a specified number of longs.Reads a Map<String,String> previously written withDataOutput.writeMapOfStrings(Map)
.Reads a Set<String> previously written withDataOutput.writeSetOfStrings(Set)
.short
Reads two bytes and returns a short (LE byte order).Reads a string.int
readVInt()
Reads an int stored in variable-length format.long
Reads a long stored in variable-length format.int
readZInt()
Read azig-zag
-encodedvariable-length
integer.long
Read azig-zag
-encodedvariable-length
integer.abstract void
skipBytes
(long numBytes) Skip overnumBytes
bytes.
-
Constructor Details
-
DataInput
public DataInput()
-
-
Method Details
-
readByte
Reads and returns a single byte.- Throws:
IOException
- See Also:
-
readBytes
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:
IOException
- See Also:
-
readBytes
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:
IOException
- See Also:
-
readShort
Reads two bytes and returns a short (LE byte order).- Throws:
IOException
- See Also:
-
readInt
Reads four bytes and returns an int (LE byte order).- Throws:
IOException
- See Also:
-
readVInt
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:
IOException
- See Also:
-
readZInt
Read azig-zag
-encodedvariable-length
integer.- Throws:
IOException
- See Also:
-
readLong
Reads eight bytes and returns a long (LE byte order).- Throws:
IOException
- See Also:
-
readLongs
Read a specified number of longs.- Throws:
IOException
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
readFloats
Reads 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:
IOException
-
readVLong
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:
IOException
- See Also:
-
readZLong
Read azig-zag
-encodedvariable-length
integer. Reads between one and ten bytes.- Throws:
IOException
- See Also:
-
readString
Reads a string.- Throws:
IOException
- See Also:
-
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
Reads a Map<String,String> previously written withDataOutput.writeMapOfStrings(Map)
.- Returns:
- An immutable map containing the written contents.
- Throws:
IOException
-
readSetOfStrings
Reads a Set<String> previously written withDataOutput.writeSetOfStrings(Set)
.- Returns:
- An immutable set containing the written contents.
- Throws:
IOException
-
skipBytes
Skip overnumBytes
bytes. 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, negativenumBytes
are not supported.- Throws:
IOException
-