Package org.jets3t.service.io
Class ProgressMonitoredInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.jets3t.service.io.ProgressMonitoredInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,InputStreamWrapper
public class ProgressMonitoredInputStream extends InputStream implements InputStreamWrapper
Input stream wrapper that tracks the number of bytes that have been read through the stream. When data is read through this stream the count of bytes is increased and the associatedBytesProgressWatcher
object is notified of the count of bytes read.- Author:
- James Murty
-
-
Constructor Summary
Constructors Constructor Description ProgressMonitoredInputStream(InputStream inputStream, 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 int
available()
void
close()
InputStream
getWrappedInputStream()
int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
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.-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Constructor Detail
-
ProgressMonitoredInputStream
public ProgressMonitoredInputStream(InputStream inputStream, 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:
inputStream
- the input 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()
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
getWrappedInputStream
public InputStream getWrappedInputStream()
- Specified by:
getWrappedInputStream
in interfaceInputStreamWrapper
- Returns:
- the underlying input stream wrapped by this class.
-
-