public class MonitoredInputStream extends InputStream
InputStream that invokes a progress(long, long) method
after each read, reporting the number of bytes processed. Applications can
subclass and override this method to provide features such as a progress
bar.| Constructor and Description |
|---|
MonitoredInputStream(InputStream delegate) |
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Returns the number of bytes available from the underlying stream.
|
void |
close()
Closes the underlying stream.
|
void |
mark(int readlimit)
Sets a mark on the underlying stream.
|
boolean |
markSupported()
Returns whether the underlying stream supports
mark(int). |
void |
progress(long lastRead,
long totalBytes)
Called after each operation that reads bytes, to report the number of
bytes read.
|
int |
read()
Reads a single byte from the underlying stream, blocking if necessary.
|
int |
read(byte[] b)
Reads up bytes from the underlying stream into the passed buffer,
blocking if necessary.
|
int |
read(byte[] b,
int off,
int len)
Reads up to the specified number of bytes from the underlying stream,
blocking if necessary.
|
void |
reset()
Resets the underlying stream to a previous mark.
|
long |
skip(long n)
Skips up to a specified number of bytes in the underlying stream.
|
public MonitoredInputStream(InputStream delegate)
public int available()
throws IOException
available in class InputStreamIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionpublic int read()
throws IOException
progress(long, long) after the byte has been read, reporting either
1 or 0 (depending on whether the stream is at its end).read in class InputStreamIOExceptionpublic int read(byte[] b)
throws IOException
progress(long, long) after the read
completes, reporting the actual number of bytes read.read in class InputStreamIOExceptionpublic int read(byte[] b,
int off,
int len)
throws IOException
progress(long, long) after the read completes,
reporting the actual number of bytes read.read in class InputStreamIOExceptionpublic boolean markSupported()
mark(int).markSupported in class InputStreampublic void mark(int readlimit)
mark in class InputStreampublic void reset()
throws IOException
reset in class InputStreamIOExceptionpublic long skip(long n)
throws IOException
progress(long, long) after the skip completes, with the number of
bytes skipped.skip in class InputStreamIOExceptionpublic void progress(long lastRead,
long totalBytes)
lastRead - Number of bytes in last read operation. Note that
this may be 0.totalBytes - Total number of bytes read or skipped since this
class was instantiated.