Package ca.cgjennings.algo
Class MonitoredInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- ca.cgjennings.algo.MonitoredInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class MonitoredInputStream extends java.io.FilterInputStreamAn input stream that can be monitored using aProgressListener. This is similar to aProgressMonitorInputStream, except that it is more flexible in how the progress updates are used.- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description MonitoredInputStream(ProgressListener li, long size, java.io.InputStream in)Creates a new monitored input stream.MonitoredInputStream(ProgressListener li, java.io.File in)Creates a new monitored input stream that reads from a file.MonitoredInputStream(ProgressListener li, java.io.InputStream in)Creates a new monitored input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intread()OverridesFilterInputStream.readto update progress after the read.intread(byte[] b)OverridesFilterInputStream.readto update progress after the read.intread(byte[] b, int off, int len)OverridesFilterInputStream.readto update progress after the read.voidreset()OverridesFilterInputStream.resetto reset progress listener as well as the stream.longskip(long n)OverridesFilterInputStream.skipto update progress after the skip.
-
-
-
Constructor Detail
-
MonitoredInputStream
public MonitoredInputStream(ProgressListener li, java.io.InputStream in) throws java.io.IOException
Creates a new monitored input stream. The size of the incoming input stream will be estimated automatically.- Parameters:
li- the listener to updatein- the input stream to monitor- Throws:
java.io.IOException- if an I/O error occurs
-
MonitoredInputStream
public MonitoredInputStream(ProgressListener li, long size, java.io.InputStream in) throws java.io.IOException
Creates a new monitored input stream.- Parameters:
li- the listener to updatesize- the number of bytes in the input streamin- the input stream to monitor- Throws:
java.io.IOException- if an I/O error occurs
-
MonitoredInputStream
public MonitoredInputStream(ProgressListener li, java.io.File in) throws java.io.IOException
Creates a new monitored input stream that reads from a file.- Parameters:
li- the listener to updatein- the file to monitor- Throws:
java.io.IOException- if an I/O error occurs
-
-
Method Detail
-
read
public int read() throws java.io.IOExceptionOverridesFilterInputStream.readto update progress after the read.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOExceptionOverridesFilterInputStream.readto update progress after the read.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionOverridesFilterInputStream.readto update progress after the read.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOExceptionOverridesFilterInputStream.skipto update progress after the skip.- Overrides:
skipin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
reset
public void reset() throws java.io.IOExceptionOverridesFilterInputStream.resetto reset progress listener as well as the stream.- Overrides:
resetin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
-