Save This Page
Home » hadoop-0.14.4 » org.apache » hadoop » io » [javadoc | source]
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 ...
}
Constructor:
 public DataOutputBuffer() 
Method from org.apache.hadoop.io.DataOutputBuffer Summary:
getData,   getLength,   reset,   write
Methods from java.io.DataOutputStream:
flush,   size,   write,   write,   writeBoolean,   writeByte,   writeBytes,   writeChar,   writeChars,   writeDouble,   writeFloat,   writeInt,   writeLong,   writeShort,   writeUTF
Methods from java.io.FilterOutputStream:
close,   flush,   write,   write,   write
Methods from java.io.OutputStream:
close,   flush,   write,   write,   write
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.hadoop.io.DataOutputBuffer Detail:
 public byte[] getData() 
    Returns the current contents of the buffer. Data is only valid to #getLength() .
 public int getLength() 
    Returns the length of the valid data currently in the buffer.
 public DataOutputBuffer reset() 
    Resets the buffer to empty.
 public  void write(DataInput in,
    int length) throws IOException 
    Writes bytes from a DataInput directly into the buffer.