javax.swing
Class ProgressMonitorInputStream

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.io.InputStream sample code for java.io.InputStream definition code for java.io.InputStream 
      extended by java.io.FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream 
          extended by javax.swing.ProgressMonitorInputStream
All Implemented Interfaces:
Closeable sample code for java.io.Closeable definition code for java.io.Closeable

public class ProgressMonitorInputStream
extends FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream

Monitors the progress of reading from some InputStream. This ProgressMonitor is normally invoked in roughly this form:

 InputStream in = new BufferedInputStream(
                          new ProgressMonitorInputStream(
                                  parentComponent,
                                  "Reading " + fileName,
                                  new FileInputStream(fileName)));
 

This creates a progress monitor to monitor the progress of reading the input stream. If it's taking a while, a ProgressDialog will be popped up to inform the user. If the user hits the Cancel button an InterruptedIOException will be thrown on the next read. All the right cleanup is done when the stream is closed.

For further documentation and examples see How to Monitor Progress, a section in The Java Tutorial.

See Also:
ProgressMonitor sample code for javax.swing.ProgressMonitor definition code for javax.swing.ProgressMonitor , JOptionPane sample code for javax.swing.JOptionPane definition code for javax.swing.JOptionPane

Field Summary
 
Fields inherited from class java.io.FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream
in sample code for java.io.FilterInputStream.in definition code for java.io.FilterInputStream.in
 
Constructor Summary
ProgressMonitorInputStream sample code for javax.swing.ProgressMonitorInputStream.ProgressMonitorInputStream(java.awt.Component, java.lang.Object, java.io.InputStream) definition code for javax.swing.ProgressMonitorInputStream.ProgressMonitorInputStream(java.awt.Component, java.lang.Object, java.io.InputStream) (Component sample code for java.awt.Component definition code for java.awt.Component  parentComponent, Object sample code for java.lang.Object definition code for java.lang.Object  message, InputStream sample code for java.io.InputStream definition code for java.io.InputStream  in)
          Constructs an object to monitor the progress of an input stream.
 
Method Summary
 void close sample code for javax.swing.ProgressMonitorInputStream.close() definition code for javax.swing.ProgressMonitorInputStream.close() ()
          Overrides FilterInputStream.close to close the progress monitor as well as the stream.
 ProgressMonitor sample code for javax.swing.ProgressMonitor definition code for javax.swing.ProgressMonitor getProgressMonitor sample code for javax.swing.ProgressMonitorInputStream.getProgressMonitor() definition code for javax.swing.ProgressMonitorInputStream.getProgressMonitor() ()
          Get the ProgressMonitor object being used by this stream.
 int read sample code for javax.swing.ProgressMonitorInputStream.read() definition code for javax.swing.ProgressMonitorInputStream.read() ()
          Overrides FilterInputStream.read to update the progress monitor after the read.
 int read sample code for javax.swing.ProgressMonitorInputStream.read(byte[]) definition code for javax.swing.ProgressMonitorInputStream.read(byte[]) (byte[] b)
          Overrides FilterInputStream.read to update the progress monitor after the read.
 int read sample code for javax.swing.ProgressMonitorInputStream.read(byte[], int, int) definition code for javax.swing.ProgressMonitorInputStream.read(byte[], int, int) (byte[] b, int off, int len)
          Overrides FilterInputStream.read to update the progress monitor after the read.
 void reset sample code for javax.swing.ProgressMonitorInputStream.reset() definition code for javax.swing.ProgressMonitorInputStream.reset() ()
          Overrides FilterInputStream.reset to reset the progress monitor as well as the stream.
 long skip sample code for javax.swing.ProgressMonitorInputStream.skip(long) definition code for javax.swing.ProgressMonitorInputStream.skip(long) (long n)
          Overrides FilterInputStream.skip to update the progress monitor after the skip.
 
Methods inherited from class java.io.FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream
available sample code for java.io.FilterInputStream.available() definition code for java.io.FilterInputStream.available() , mark sample code for java.io.FilterInputStream.mark(int) definition code for java.io.FilterInputStream.mark(int) , markSupported sample code for java.io.FilterInputStream.markSupported() definition code for java.io.FilterInputStream.markSupported()
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

ProgressMonitorInputStream sample code for javax.swing.ProgressMonitorInputStream(java.awt.Component, java.lang.Object, java.io.InputStream) definition code for javax.swing.ProgressMonitorInputStream(java.awt.Component, java.lang.Object, java.io.InputStream)

public ProgressMonitorInputStream(Component sample code for java.awt.Component definition code for java.awt.Component  parentComponent,
                                  Object sample code for java.lang.Object definition code for java.lang.Object  message,
                                  InputStream sample code for java.io.InputStream definition code for java.io.InputStream  in)
Constructs an object to monitor the progress of an input stream.

Parameters:
message - Descriptive text to be placed in the dialog box if one is popped up.
parentComponent - The component triggering the operation being monitored.
in - The input stream to be monitored.
Method Detail

getProgressMonitor sample code for javax.swing.ProgressMonitorInputStream.getProgressMonitor() definition code for javax.swing.ProgressMonitorInputStream.getProgressMonitor()

public ProgressMonitor sample code for javax.swing.ProgressMonitor definition code for javax.swing.ProgressMonitor  getProgressMonitor()
Get the ProgressMonitor object being used by this stream. Normally this isn't needed unless you want to do something like change the descriptive text partway through reading the file.

Returns:
the ProgressMonitor object used by this object

read sample code for javax.swing.ProgressMonitorInputStream.read() definition code for javax.swing.ProgressMonitorInputStream.read()

public int read()
         throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Overrides FilterInputStream.read to update the progress monitor after the read.

Overrides:
read sample code for java.io.FilterInputStream.read() definition code for java.io.FilterInputStream.read() in class FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs.
See Also:
FilterInputStream.in sample code for java.io.FilterInputStream.in definition code for java.io.FilterInputStream.in

read sample code for javax.swing.ProgressMonitorInputStream.read(byte[]) definition code for javax.swing.ProgressMonitorInputStream.read(byte[])

public int read(byte[] b)
         throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Overrides FilterInputStream.read to update the progress monitor after the read.

Overrides:
read sample code for java.io.FilterInputStream.read(byte[]) definition code for java.io.FilterInputStream.read(byte[]) in class FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream
Parameters:
b - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs.
See Also:
FilterInputStream.read(byte[], int, int) sample code for java.io.FilterInputStream.read(byte[], int, int) definition code for java.io.FilterInputStream.read(byte[], int, int)

read sample code for javax.swing.ProgressMonitorInputStream.read(byte[], int, int) definition code for javax.swing.ProgressMonitorInputStream.read(byte[], int, int)

public int read(byte[] b,
                int off,
                int len)
         throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Overrides FilterInputStream.read to update the progress monitor after the read.

Overrides:
read sample code for java.io.FilterInputStream.read(byte[], int, int) definition code for java.io.FilterInputStream.read(byte[], int, int) in class FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream
Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the maximum number of bytes read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs.
See Also:
FilterInputStream.in sample code for java.io.FilterInputStream.in definition code for java.io.FilterInputStream.in

skip sample code for javax.swing.ProgressMonitorInputStream.skip(long) definition code for javax.swing.ProgressMonitorInputStream.skip(long)

public long skip(long n)
          throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Overrides FilterInputStream.skip to update the progress monitor after the skip.

Overrides:
skip sample code for java.io.FilterInputStream.skip(long) definition code for java.io.FilterInputStream.skip(long) in class FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs.

close sample code for javax.swing.ProgressMonitorInputStream.close() definition code for javax.swing.ProgressMonitorInputStream.close()

public void close()
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Overrides FilterInputStream.close to close the progress monitor as well as the stream.

Specified by:
close sample code for java.io.Closeable.close() definition code for java.io.Closeable.close() in interface Closeable sample code for java.io.Closeable definition code for java.io.Closeable
Overrides:
close sample code for java.io.FilterInputStream.close() definition code for java.io.FilterInputStream.close() in class FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs.
See Also:
FilterInputStream.in sample code for java.io.FilterInputStream.in definition code for java.io.FilterInputStream.in

reset sample code for javax.swing.ProgressMonitorInputStream.reset() definition code for javax.swing.ProgressMonitorInputStream.reset()

public void reset()
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Overrides FilterInputStream.reset to reset the progress monitor as well as the stream.

Overrides:
reset sample code for java.io.FilterInputStream.reset() definition code for java.io.FilterInputStream.reset() in class FilterInputStream sample code for java.io.FilterInputStream definition code for java.io.FilterInputStream
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if the stream has not been marked or if the mark has been invalidated.
See Also:
FilterInputStream.in sample code for java.io.FilterInputStream.in definition code for java.io.FilterInputStream.in , FilterInputStream.mark(int) sample code for java.io.FilterInputStream.mark(int) definition code for java.io.FilterInputStream.mark(int)