com.anthonyeden.lib.io
Class ByteCountOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.FilterOutputStream
          extended bycom.anthonyeden.lib.io.ByteCountOutputStream

public class ByteCountOutputStream
extends java.io.FilterOutputStream

A FilterOutputStream which will keep track of the number of bytes written to the underlying stream. Callers who want to know how many bytes have been written should attach a ChangeListener and call getCount() whenever a change event is fired.

If no ChangeListeners are attached then this stream will not fire events. This improves performance by only firing events when at least one object is expecting them.

Author:
Anthony Eden

Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
ByteCountOutputStream(java.io.OutputStream out)
           
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener l)
          Add a changeListeners.
protected  void fireStateChanged()
          Fire a ChangeEvent.
protected  java.util.ArrayList getChangeListeners()
          Get a List of attached ChangeListeners.
 long getCount()
          Get the number of bytes written so far.
 void removeChangeListener(javax.swing.event.ChangeListener l)
          Remove a ChangeListener.
 void write(byte[] buffer)
          Write the buffer to the stream.
 void write(byte[] buffer, int offset, int length)
          Write the buffer to the stream with bytes starting at the given offset of the buffer and reading for length number of bytes.
 void write(int b)
          Write one byte.
 
Methods inherited from class java.io.FilterOutputStream
close, flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteCountOutputStream

public ByteCountOutputStream(java.io.OutputStream out)
Method Detail

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener l)
Add a changeListeners.

Parameters:
l - The ChangeListener

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener l)
Remove a ChangeListener.

Parameters:
l - The ChangeListener

write

public void write(byte[] buffer)
           throws java.io.IOException
Write the buffer to the stream.

Parameters:
buffer - The buffer to write
Returns:
The number of bytes written
Throws:
java.io.IOException

write

public void write(byte[] buffer,
                  int offset,
                  int length)
           throws java.io.IOException
Write the buffer to the stream with bytes starting at the given offset of the buffer and reading for length number of bytes.

Parameters:
buffer - The buffer
offset - The buffer offset
length - The number of bytes to write
Returns:
The number of bytes written
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException
Write one byte.

Returns:
The byte
Throws:
java.io.IOException

getCount

public long getCount()
Get the number of bytes written so far.

Returns:
The byte count

getChangeListeners

protected java.util.ArrayList getChangeListeners()
Get a List of attached ChangeListeners.

Returns:
The List of ChangeListeners

fireStateChanged

protected void fireStateChanged()
Fire a ChangeEvent.



Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.