public abstract class DataInput
extends java.lang.Object
implements java.lang.Cloneable
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 and Description |
|---|
DataInput() |
| Modifier and Type | Method and 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.
|
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
with
DataOutput.writeMapOfStrings(Map). |
java.util.Set<java.lang.String> |
readSetOfStrings()
Reads a Set<String> previously written
with
DataOutput.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.
|
int |
readZInt()
Read a
zig-zag-encoded
variable-length integer. |
long |
readZLong()
Read a
zig-zag-encoded
variable-length integer. |
void |
skipBytes(long numBytes)
Skip over
numBytes bytes. |
public abstract byte readByte()
throws java.io.IOException
java.io.IOExceptionDataOutput.writeByte(byte)public abstract void readBytes(byte[] b,
int offset,
int len)
throws java.io.IOException
b - the array to read bytes intooffset - the offset in the array to start storing byteslen - the number of bytes to readjava.io.IOExceptionDataOutput.writeBytes(byte[],int)public void readBytes(byte[] b,
int offset,
int len,
boolean useBuffer)
throws java.io.IOException
BufferedIndexInput respects this parameter.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.java.io.IOExceptionDataOutput.writeBytes(byte[],int)public short readShort()
throws java.io.IOException
java.io.IOExceptionDataOutput.writeByte(byte)public int readInt()
throws java.io.IOException
java.io.IOExceptionDataOutput.writeInt(int)public int readVInt()
throws java.io.IOException
The format is described further in DataOutput.writeVInt(int).
java.io.IOExceptionDataOutput.writeVInt(int)public int readZInt()
throws java.io.IOException
zig-zag-encoded
variable-length integer.java.io.IOExceptionDataOutput.writeZInt(int)public long readLong()
throws java.io.IOException
java.io.IOExceptionDataOutput.writeLong(long)public long readVLong()
throws java.io.IOException
The format is described further in DataOutput.writeVInt(int).
java.io.IOExceptionDataOutput.writeVLong(long)public long readZLong()
throws java.io.IOException
zig-zag-encoded
variable-length integer. Reads between one and ten
bytes.java.io.IOExceptionDataOutput.writeZLong(long)public java.lang.String readString()
throws java.io.IOException
java.io.IOExceptionDataOutput.writeString(String)public DataInput clone()
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.
clone in class java.lang.Objectpublic java.util.Map<java.lang.String,java.lang.String> readMapOfStrings()
throws java.io.IOException
DataOutput.writeMapOfStrings(Map).java.io.IOExceptionpublic java.util.Set<java.lang.String> readSetOfStrings()
throws java.io.IOException
DataOutput.writeSetOfStrings(Set).java.io.IOExceptionpublic void skipBytes(long numBytes)
throws java.io.IOException
numBytes 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 of numBytes
are not supported.java.io.IOExceptionCopyright © 2000–2025 The Apache Software Foundation. All rights reserved.