net.sourceforge.java.util.io
Class ProgressMonitorInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended bynet.sourceforge.java.util.io.ProgressMonitorInputStream

public class ProgressMonitorInputStream
extends FilterInputStream

InputStream extension that is bindable to a IProgressMonitor to report the progress of a read operation.

Author:
Sebastian Machhausen

Field Summary
private  int bytesRead
           The number of bytes read
private  IProgressMonitor monitor
           The IProgressMonitor to report the reading status to
private  int totalBytes
           The total number of bytes to be read
 
Fields inherited from class java.io.FilterInputStream
in
 
Fields inherited from class java.io.InputStream
 
Constructor Summary
ProgressMonitorInputStream(InputStream in, IProgressMonitor monitor)
           Creates a new ProgressMonitorInputStream to monitor the progress of the specified InputStream and report the progress status to the specified IProgressMonitor.
ProgressMonitorInputStream(InputStream in, IProgressMonitor monitor, long size)
           Creates a new ProgressMonitorInputStream to monitor the progress of the specified InputStream and report the progress status to the specified IProgressMonitor.
 
Method Summary
 void close()
           Overrides FilterInputStream.close() to close the IProgressMonitor as well as the InputStream.
 int read()
           Overrides FilterInputStream.read() to update the IProgressMonitor after the read operation.
 int read(byte[] buffer)
           Overrides FilterInputStream.read(byte[]) to update the IProgressMonitor after the read operation.
 int read(byte[] buffer, int off, int len)
           Overrides FilterInputStream.read(byte[], int, int) to update the IProgressMonitor after the read operation.
 void reset()
           Overrides FilterInputStream.reset() to reset the IProgressMonitor as well as the InputStream.
 long skip(long n)
           Overrides FilterInputStream.skip(long) to update the progress monitor after the skip operation.
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

monitor

private IProgressMonitor monitor

The IProgressMonitor to report the reading status to


bytesRead

private int bytesRead

The number of bytes read


totalBytes

private int totalBytes

The total number of bytes to be read

Constructor Detail

ProgressMonitorInputStream

public ProgressMonitorInputStream(InputStream in,
                                  IProgressMonitor monitor)

Creates a new ProgressMonitorInputStream to monitor the progress of the specified InputStream and report the progress status to the specified IProgressMonitor.

Parameters:
in - the InputStream to monitor
monitor - the IProgressMonitor to report the progress status to

ProgressMonitorInputStream

public ProgressMonitorInputStream(InputStream in,
                                  IProgressMonitor monitor,
                                  long size)

Creates a new ProgressMonitorInputStream to monitor the progress of the specified InputStream and report the progress status to the specified IProgressMonitor.

Parameters:
in - the InputStream to monitor
monitor - the IProgressMonitor to report the progress status to
size - the size in bytes of the InputStream
Method Detail

read

public int read()
         throws IOException

Overrides FilterInputStream.read() to update the IProgressMonitor after the read operation.

Returns:
the value read or -1 if the end of the stream has been reached
Throws:
IOException - if an io error occured during the read operation

read

public int read(byte[] buffer)
         throws IOException

Overrides FilterInputStream.read(byte[]) to update the IProgressMonitor after the read operation.

Parameters:
buffer - the buffer to read into
Returns:
the number of bytes read or -1 if the end of the stream has been reached
Throws:
IOException - if an io error occured during the read operation

read

public int read(byte[] buffer,
                int off,
                int len)
         throws IOException

Overrides FilterInputStream.read(byte[], int, int) to update the IProgressMonitor after the read operation.

Parameters:
buffer - the buffer to read into
off - the offset at which to start storing byte values
len - the maximum number of bytes to read
Returns:
the number of bytes read or -1 if the end of the stream has been reached
Throws:
IOException - if an io error occured during the read operation

skip

public long skip(long n)
          throws IOException

Overrides FilterInputStream.skip(long) to update the progress monitor after the skip operation.

Parameters:
n - the number of bytes to skip
Returns:
the number of bytes actually skipped
Throws:
IllegalArgumentException - If n is negative.
IOException - if an io error occured during the skip operation

reset

public void reset()
           throws IOException

Overrides FilterInputStream.reset() to reset the IProgressMonitor as well as the InputStream.

Throws:
IOException

close

public void close()
           throws IOException

Overrides FilterInputStream.close() to close the IProgressMonitor as well as the InputStream.

Throws:
IOException - if an io error occured during the close operation