com.threerings.io
Class ByteBufferOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.threerings.io.ByteBufferOutputStream
All Implemented Interfaces:
Closeable, Flushable
Direct Known Subclasses:
FramingOutputStream

public class ByteBufferOutputStream
extends OutputStream

Stores output in an ByteBuffer that grows automatically to accommodate the data.


Field Summary
protected  ByteBuffer _buffer
          The buffer in which we store our frame data.
protected static int INITIAL_BUFFER_SIZE
          The default initial size of the internal buffer.
 
Constructor Summary
ByteBufferOutputStream()
          Creates a new byte buffer output stream.
 
Method Summary
protected  void expand(int needed)
          Expands our buffer to accomodate the specified capacity.
 ByteBuffer flip()
          Flips and returns the buffer.
 ByteBuffer getBuffer()
          Returns a reference to the underlying buffer.
 void reset()
          Resets our internal buffer.
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_buffer

protected ByteBuffer _buffer
The buffer in which we store our frame data.


INITIAL_BUFFER_SIZE

protected static final int INITIAL_BUFFER_SIZE
The default initial size of the internal buffer.

See Also:
Constant Field Values
Constructor Detail

ByteBufferOutputStream

public ByteBufferOutputStream()
Creates a new byte buffer output stream.

Method Detail

getBuffer

public ByteBuffer getBuffer()
Returns a reference to the underlying buffer.


flip

public ByteBuffer flip()
Flips and returns the buffer. The returned buffer will have a position of zero and a limit equal to the number of bytes written. Call reset() to reset the buffer before writing again.


reset

public void reset()
Resets our internal buffer.


write

public void write(int b)
Specified by:
write in class OutputStream

write

public void write(byte[] b,
                  int off,
                  int len)
Overrides:
write in class OutputStream

expand

protected final void expand(int needed)
Expands our buffer to accomodate the specified capacity.