org.joe_e.array
Class ByteArray.BuilderOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.joe_e.array.ByteArray.BuilderOutputStream
All Implemented Interfaces:
Closeable, Flushable
Enclosing class:
ByteArray

public static final class ByteArray.BuilderOutputStream
extends OutputStream

A ByteArray factory that extends OutputStream. All methods are simple wrappers around those provided by ByteArray.Builder.


Constructor Summary
ByteArray.BuilderOutputStream()
          Create an output stream using a new underlying ByteArray.Builder with the default internal array length
ByteArray.BuilderOutputStream(ByteArray.Builder toWrap)
          Suppressed.
          Create an output stream that wraps the specified ByteArray.Builder
ByteArray.BuilderOutputStream(int estimate)
          Create an output stream using a new underlying ByteArray.Builder
 
Method Summary
 int length()
          Gets the number of bytes written to the underlying ByteArray.Builder
 ByteArray snapshot()
          Create a snapshot of the current content.
 void write(byte[] b)
          Append a byte array to the underlying ByteArray.Builder
 void write(byte[] b, int off, int len)
          Append part of a byte array to the underlying ByteArray.Builder
 void write(int b)
          Append a byte to the underlying ByteArray.Builder
 
Methods inherited from class java.io.OutputStream
close, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArray.BuilderOutputStream

public ByteArray.BuilderOutputStream()
Create an output stream using a new underlying ByteArray.Builder with the default internal array length


ByteArray.BuilderOutputStream

public ByteArray.BuilderOutputStream(int estimate)
Create an output stream using a new underlying ByteArray.Builder

Parameters:
estimate - estimated array length

ByteArray.BuilderOutputStream

public ByteArray.BuilderOutputStream(ByteArray.Builder toWrap)
Policy unspecified!

Create an output stream that wraps the specified ByteArray.Builder

Parameters:
toWrap - the Builder to wrap
Method Detail

write

public void write(int b)
Append a byte to the underlying ByteArray.Builder

Specified by:
write in class OutputStream
Parameters:
b - the element to add

write

public void write(byte[] b)
Append a byte array to the underlying ByteArray.Builder

Overrides:
write in class OutputStream
Parameters:
b - the elements to add
See Also:
OutputStream.write(byte[], int, int)

write

public void write(byte[] b,
                  int off,
                  int len)
Append part of a byte array to the underlying ByteArray.Builder

Overrides:
write in class OutputStream
Parameters:
b - the elements to add
off - the index of the first element to add
len - the number of elements to add

length

public int length()
Gets the number of bytes written to the underlying ByteArray.Builder

Returns:
the number of elements that have been appended

snapshot

public ByteArray snapshot()
Create a snapshot of the current content.

Returns:
a ByteArray containing the elements so far