Package org.esa.snap.core.util.io
Class ObservableInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.esa.snap.core.util.io.ObservableInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ObservableInputStream extends FilterInputStream
An input stream which can be used to observer progress of reading from some other input stream.
-
-
Field Summary
-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description ObservableInputStream(InputStream in, long size, InputStreamObserver listener)
Constructs an object to observer the progress of an input stream.ObservableInputStream(InputStream in, InputStreamObserver listener)
Constructs an object to observer the progress of an input stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
OverridesFilterInputStream.close
to close the progress observer as well as the stream.long
getNumBytesRead()
long
getNumBytesTotal()
InputStreamObserver
getObserver()
int
read()
OverridesFilterInputStream.read
to update the progress observer after the read.int
read(byte[] b)
OverridesFilterInputStream.read
to update the progress observer after the read.int
read(byte[] b, int off, int len)
OverridesFilterInputStream.read
to update the progress observer after the read.void
reset()
OverridesFilterInputStream.reset
to reset the progress observer as well as the stream.long
skip(long n)
OverridesFilterInputStream.skip
to update the progress observer after the skip.-
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
ObservableInputStream
public ObservableInputStream(InputStream in, InputStreamObserver listener)
Constructs an object to observer the progress of an input stream.- Parameters:
in
- The input stream to be monitored.listener
- the listener to be informed
-
ObservableInputStream
public ObservableInputStream(InputStream in, long size, InputStreamObserver listener)
Constructs an object to observer the progress of an input stream.- Parameters:
in
- The input stream to be monitored.listener
- the listener to be informed
-
-
Method Detail
-
getNumBytesTotal
public long getNumBytesTotal()
-
getNumBytesRead
public long getNumBytesRead()
-
getObserver
public InputStreamObserver getObserver()
-
read
public int read() throws IOException
OverridesFilterInputStream.read
to update the progress observer after the read.- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
public int read(byte[] b) throws IOException
OverridesFilterInputStream.read
to update the progress observer after the read.- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
OverridesFilterInputStream.read
to update the progress observer after the read.- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
skip
public long skip(long n) throws IOException
OverridesFilterInputStream.skip
to update the progress observer after the skip.- Overrides:
skip
in classFilterInputStream
- Throws:
IOException
-
close
public void close() throws IOException
OverridesFilterInputStream.close
to close the progress observer as well as the stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
-
reset
public void reset() throws IOException
OverridesFilterInputStream.reset
to reset the progress observer as well as the stream.- Overrides:
reset
in classFilterInputStream
- Throws:
IOException
-
-