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 OutputBuffer

    java.lang.Object
      java.io.OutputStream
          java.io.FilterOutputStream
              org.apache.hadoop.io.OutputBuffer

All Implemented Interfaces:
  Closeable, Flushable

    public class OutputBuffer

extends FilterOutputStream

A reusable `OutputStream` implementation that writes to an in-memory buffer.

This saves memory over creating a new OutputStream and ByteArrayOutputStream each time data is written.

Typical usage is something like the following:

     OutputBuffer buffer = new OutputBuffer();
     while (... loop condition ...) {
       buffer.reset();
       ... write buffer using OutputStream methods ...
       byte[] data = buffer.getData();
       int dataLength = buffer.getLength();
       ... write data to its ultimate destination ...
     }

See Also:
  `DataOutputBuffer`, `InputBuffer`

Field Summary

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

Constructor Summary
`OutputBuffer()` Constructs a new empty buffer.

Method Summary
`byte[]` | `getData()` Returns the current contents of the buffer.
`int` | `getLength()` Returns the length of the valid data currently in the buffer.
`OutputBuffer` | `reset()` Resets the buffer to empty.
`void` | `write(InputStream in, int length)` Writes bytes from a InputStream directly into the buffer.

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

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

Constructor Detail

### OutputBuffer

    public OutputBuffer()

  Constructs a new empty buffer.

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 OutputBuffer reset()

  Resets the buffer to empty.

### write

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

  Writes bytes from a InputStream directly into the buffer.

  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