org.jets3t.service.io
Class ProgressMonitoredOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.jets3t.service.io.ProgressMonitoredOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, OutputStreamWrapper

public class ProgressMonitoredOutputStream
extends java.io.OutputStream
implements OutputStreamWrapper

Output stream wrapper that tracks the number of bytes that have been written through the stream. When data is written through this stream the count of bytes is increased, and at a set minimum interval (eg after at least 1024 bytes) a BytesTransferredWatcher implementation is notified of the count of bytes read since the last notification.

Author:
James Murty

Constructor Summary
ProgressMonitoredOutputStream(java.io.OutputStream outputStream, BytesProgressWatcher progressWatcher)
          Construts the input stream around an underlying stream and sends notification messages to a progress watcher when bytes are read from the stream.
 
Method Summary
 void close()
           
 java.io.OutputStream getWrappedOutputStream()
           
 void resetProgressMonitor()
           
 void sendNotificationUpdate(long bytesTransmitted)
          Checks how many bytes have been transferred since the last notification, and sends a notification message if this number exceeds the minimum bytes transferred value.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
Methods inherited from class java.io.OutputStream
flush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProgressMonitoredOutputStream

public ProgressMonitoredOutputStream(java.io.OutputStream outputStream,
                                     BytesProgressWatcher progressWatcher)
Construts the input stream around an underlying stream and sends notification messages to a progress watcher when bytes are read from the stream.

Parameters:
outputStream - the output stream to wrap, whose byte transfer count will be monitored.
progressWatcher - a watcher object that stores information about the bytes read from a stream, and allows calculations to be perfomed using this information.
Method Detail

sendNotificationUpdate

public void sendNotificationUpdate(long bytesTransmitted)
Checks how many bytes have been transferred since the last notification, and sends a notification message if this number exceeds the minimum bytes transferred value.

Parameters:
bytesTransmitted -

resetProgressMonitor

public void resetProgressMonitor()

write

public void write(int b)
           throws java.io.IOException
Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException
Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException

getWrappedOutputStream

public java.io.OutputStream getWrappedOutputStream()
Specified by:
getWrappedOutputStream in interface OutputStreamWrapper
Returns:
the underlying input stream wrapped by this class.