DataOutputBuffer (Hadoop 1.2.1 API)
Date: 2013-07-22

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.hadoop.io
Class DataOutputBuffer

    java.lang.Object
      java.io.OutputStream
          java.io.FilterOutputStream
              java.io.DataOutputStream
                  org.apache.hadoop.io.DataOutputBuffer

All Implemented Interfaces:
  Closeable, DataOutput, Flushable

    public class DataOutputBuffer

extends DataOutputStream

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 ...
     }

Field Summary

Fields inherited from class java.io.DataOutputStream
`written`

Fields inherited from class java.io.FilterOutputStream
`out`

Constructor Summary
`DataOutputBuffer()` Constructs a new empty buffer.
`DataOutputBuffer(int size)`

Method Summary
`byte[]` | `getData()` Returns the current contents of the buffer.
`int` | `getLength()` Returns the length of the valid data currently in the buffer.
`DataOutputBuffer` | `reset()` Resets the buffer to empty.
`void` | `write(DataInput in, int length)` Writes bytes from a DataInput directly into the buffer.
`void` | `writeTo(OutputStream out)` Write to a file stream

Methods inherited from class java.io.DataOutputStream
`flush, size, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF`

Methods inherited from class java.io.FilterOutputStream
`close, write`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface java.io.DataOutput
`write`

Constructor Detail

### DataOutputBuffer

    public DataOutputBuffer()

  Constructs a new empty buffer.

### DataOutputBuffer

    public DataOutputBuffer(int size)

Method Detail

### getData

    public byte[] getData()

  Returns the current contents of the buffer. Data is only valid to `getLength()`.

### getLength

    public int getLength()

  Returns the length of the valid data currently in the buffer.

### reset

    public DataOutputBuffer reset()

  Resets the buffer to empty.

### write

    public void write(DataInput in,
                      int length)
               throws IOException

  Writes bytes from a DataInput directly into the buffer.

  Throws:
    `IOException`

### writeTo

    public void writeTo(OutputStream out)
                 throws IOException

  Write to a file stream

  Throws:
    `IOException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2009 The Apache Software Foundation