Package org.jets3t.service.io
Class ProgressMonitoredOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.jets3t.service.io.ProgressMonitoredOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,OutputStreamWrapper
public class ProgressMonitoredOutputStream extends 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) aBytesProgressWatcherimplementation is notified of the count of bytes read since the last notification.- Author:
- James Murty
-
-
Constructor Summary
Constructors Constructor Description ProgressMonitoredOutputStream(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()OutputStreamgetWrappedOutputStream()voidresetProgressMonitor()voidsendNotificationUpdate(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.voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)-
Methods inherited from class java.io.OutputStream
flush, nullOutputStream
-
-
-
-
Constructor Detail
-
ProgressMonitoredOutputStream
public ProgressMonitoredOutputStream(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 IOException- Specified by:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
write
public void write(byte[] b) throws IOException- Overrides:
writein classOutputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
getWrappedOutputStream
public OutputStream getWrappedOutputStream()
- Specified by:
getWrappedOutputStreamin interfaceOutputStreamWrapper- Returns:
- the underlying input stream wrapped by this class.
-
-