Package org.apache.hadoop.io
Class DataInputBuffer
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.DataInputStream
org.apache.hadoop.io.DataInputBuffer
- All Implemented Interfaces:
Closeable,DataInput,AutoCloseable
@LimitedPrivate({"HDFS","MapReduce"})
@Unstable
public class DataInputBuffer
extends DataInputStream
A reusable
DataInput implementation
that reads from an in-memory buffer.
This saves memory over creating a new DataInputStream and ByteArrayInputStream each time data is read.
Typical usage is something like the following:
DataInputBuffer buffer = new DataInputBuffer();
while (... loop condition ...) {
byte[] data = ... get data ...;
int dataLength = ... get data length ...;
buffer.reset(data, dataLength);
... read buffer using DataInput methods ...
}
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]getData()intReturns the index one greater than the last valid character in the input stream buffer.intReturns the current position in the input.voidreset(byte[] input, int length) Resets the data that the buffer reads.voidreset(byte[] input, int start, int length) Resets the data that the buffer reads.Methods inherited from class java.io.DataInputStream
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytesMethods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skipMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
DataInputBuffer
public DataInputBuffer()Constructs a new empty buffer.
-
-
Method Details
-
reset
public void reset(byte[] input, int length) Resets the data that the buffer reads.- Parameters:
input- input.length- length.
-
reset
public void reset(byte[] input, int start, int length) Resets the data that the buffer reads.- Parameters:
input- input.start- start.length- length.
-
getData
public byte[] getData() -
getPosition
public int getPosition()Returns the current position in the input.- Returns:
- position.
-
getLength
public int getLength()Returns the index one greater than the last valid character in the input stream buffer.- Returns:
- length.
-