things.common.tools
Class TightByteArrayOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.ByteArrayOutputStream
          extended by things.common.tools.TightByteArrayOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class TightByteArrayOutputStream
extends java.io.ByteArrayOutputStream

A cousin to the ByteArrayOutputStream. Instead of just expanding it forever, throw an IOException.

Version:
1.0

Version History

EPG - Initial - 20 JUL 06
 
Author:
Erich P. Gatejen

Field Summary
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
TightByteArrayOutputStream()
          Construct.
 
Method Summary
 void copyMarkTo(java.io.OutputStream ous)
          Copy from the last mark (or start if not mark made) to the end of the buffer into a stream.
 byte[] get()
          Get the total buffer.
 int getFillSize()
          Get how much of the buffer is filled.
 int mark()
          Mark the next spot that will get a byte and return the value.
 
Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toByteArray, toString, toString, toString, write, write, writeTo
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TightByteArrayOutputStream

public TightByteArrayOutputStream()
                           throws java.lang.Throwable
Construct.

Throws:
java.lang.Throwable - if the data is not allowed.
Method Detail

get

public byte[] get()
Get the total buffer.

Returns:
the buffer.

getFillSize

public int getFillSize()
Get how much of the buffer is filled. This might be silly, but I really don't want people to copy a huge buffer array just to get access to this data. Get the buffer and then getFillSize().

Returns:
the fill size in bytes.

mark

public int mark()
Mark the next spot that will get a byte and return the value. If the array is bad you'll get a negative number.


copyMarkTo

public void copyMarkTo(java.io.OutputStream ous)
                throws java.io.IOException
Copy from the last mark (or start if not mark made) to the end of the buffer into a stream. Mark will be not be changed after the operation. If there is no difference between the mark and the next stop (meaning nothing was written since the last marking), nothing will out copied to the output stream.

Parameters:
ous - the output stream.
Throws:
java.io.IOException


Things.