org.apache.hadoop.io
public class: DataOutputBuffer [javadoc |
source]
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.DataOutputStream
org.apache.hadoop.io.DataOutputBuffer
All Implemented Interfaces:
DataOutput, Closeable, Flushable
A reusable
DataOutput implementation that writes to an in-memory
buffer.
This saves memory over creating a new DataOutputStream and
ByteArrayOutputStream each time data is written.
Typical usage is something like the following:
DataOutputBuffer buffer = new DataOutputBuffer();
while (... loop condition ...) {
buffer.reset();
... write buffer using DataOutput methods ...
byte[] data = buffer.getData();
int dataLength = buffer.getLength();
... write data to its ultimate destination ...
}
| Methods from java.io.DataOutputStream: |
|---|
|
flush, size, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF |
| Method from org.apache.hadoop.io.DataOutputBuffer Detail: |
public byte[] getData() {
return buffer.getData();
}
Returns the current contents of the buffer.
Data is only valid to #getLength() . |
public int getLength() {
return buffer.getLength();
}
Returns the length of the valid data currently in the buffer. |
public DataOutputBuffer reset() {
this.written = 0;
buffer.reset();
return this;
}
Resets the buffer to empty. |
public void write(DataInput in,
int length) throws IOException {
buffer.write(in, length);
}
Writes bytes from a DataInput directly into the buffer. |