com.imagero.uio.io
Class ByteArrayOutputStreamExt

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.ByteArrayOutputStream
          extended bycom.imagero.uio.io.ByteArrayOutputStreamExt

public class ByteArrayOutputStreamExt
extends java.io.ByteArrayOutputStream

ByteArrayOutputStreamExt extends ByteArrayOutputStream with posibility to drain off data into user specified buffer. ActionEvent is fired if buffer is full and going to grow.


Field Summary
static java.lang.String BUFFER_FULL
           
 
Fields inherited from class java.io.ByteArrayOutputStream
buf, count
 
Constructor Summary
ByteArrayOutputStreamExt()
           
ByteArrayOutputStreamExt(java.awt.event.ActionListener l)
           
ByteArrayOutputStreamExt(int size)
           
ByteArrayOutputStreamExt(int size, java.awt.event.ActionListener l)
           
 
Method Summary
 void close()
           
 byte[] closeStream()
           
 byte[] drain()
          Retrieve internal buffer.
 int drain(byte[] dest)
          Fill destination buffer with data which is removed from start of this buffer.
protected  void fireBufferFullEvent()
           
 void setBufferListener(java.awt.event.ActionListener bufferListener)
           
 void write(byte[] b, int off, int len)
          Writes len bytes from given byte array starting at offset off to this buffer.
 void write(int b)
           
 void writeTo(java.io.DataOutput out)
           
 
Methods inherited from class java.io.ByteArrayOutputStream
reset, size, toByteArray, toString, toString, toString, 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
 

Field Detail

BUFFER_FULL

public static final java.lang.String BUFFER_FULL
See Also:
Constant Field Values
Constructor Detail

ByteArrayOutputStreamExt

public ByteArrayOutputStreamExt()

ByteArrayOutputStreamExt

public ByteArrayOutputStreamExt(int size)

ByteArrayOutputStreamExt

public ByteArrayOutputStreamExt(java.awt.event.ActionListener l)

ByteArrayOutputStreamExt

public ByteArrayOutputStreamExt(int size,
                                java.awt.event.ActionListener l)
Method Detail

fireBufferFullEvent

protected void fireBufferFullEvent()

drain

public int drain(byte[] dest)
Fill destination buffer with data which is removed from start of this buffer.

Parameters:
dest - destination buffer
Returns:
how much bytes was moved from this buffer into destination buffer.

write

public void write(int b)

write

public void write(byte[] b,
                  int off,
                  int len)
Writes len bytes from given byte array starting at offset off to this buffer. If capacity of buffer is not enough for incoming data, then, at-first, buffer filled with data, then fired "buffer is full" event, thus giving the user possibility to "drain" buffer. If buffer was drained, then rest of data is written to buffer, otherwise buffer capacity is increased before writing.

Parameters:
b -
off -
len -

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

setBufferListener

public void setBufferListener(java.awt.event.ActionListener bufferListener)

drain

public byte[] drain()
Retrieve internal buffer. Recommended use - immediately after receiving "buffer full" event. Internal buffer is returned and replaced with new empty buffer.


writeTo

public void writeTo(java.io.DataOutput out)
             throws java.io.IOException
Throws:
java.io.IOException

closeStream

public byte[] closeStream()