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.FilterInputStream
An 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 int
read()
OverridesFilterInputStream.read
to update progress after the read.int
read(byte[] b)
OverridesFilterInputStream.read
to update progress after the read.int
read(byte[] b, int off, int len)
OverridesFilterInputStream.read
to update progress after the read.void
reset()
OverridesFilterInputStream.reset
to reset progress listener as well as the stream.long
skip(long n)
OverridesFilterInputStream.skip
to 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.IOException
OverridesFilterInputStream.read
to update progress after the read.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException
OverridesFilterInputStream.read
to update progress after the read.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
OverridesFilterInputStream.read
to update progress after the read.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
OverridesFilterInputStream.skip
to update progress after the skip.- Overrides:
skip
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
reset
public void reset() throws java.io.IOException
OverridesFilterInputStream.reset
to reset progress listener as well as the stream.- Overrides:
reset
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
-