APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing

public Class ProgressMonitorInputStream

extends FilterInputStream
Class Inheritance
Imports
java.io.*, java.awt.Component

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.

Author
James Gosling
Since
1.2
See Also
ProgressMonitor, JOptionPane

Field Summary

Modifier and TypeField and Description
pack-priv Object
private ProgressMonitor
private int
pack-priv Component
private int
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
ProgressMonitorInputStream(Component
The component triggering the operation being monitored.
parentComponent
,
Object
Descriptive text to be placed in the dialog box if one is popped up.
message
,
InputStream
The input stream to be monitored.
in
)

Constructs an object to monitor the progress of an input stream.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Overrides FilterInputStream.close to close the progress monitor as well as the stream.

public ProgressMonitor

Returns:

the ProgressMonitor object used by this object
getProgressMonitor
()

Get the ProgressMonitor object being used by this stream.

public int
read()

Overrides java.io.FilterInputStream.read.

Overrides FilterInputStream.read to update the progress monitor after the read.

public int
read(byte[] b)

Overrides java.io.FilterInputStream.read.

Overrides FilterInputStream.read to update the progress monitor after the read.

public int
read(byte[] b, int off, int len)

Overrides java.io.FilterInputStream.read.

Overrides FilterInputStream.read to update the progress monitor after the read.

public synchronized void
reset()

Overrides java.io.FilterInputStream.reset.

Overrides FilterInputStream.reset to reset the progress monitor as well as the stream.

private void
setProgress(int nr)

public long
skip(long n)

Overrides java.io.FilterInputStream.skip.

Overrides FilterInputStream.skip to update the progress monitor after the skip.

Inherited from java.io.FilterInputStream:
availablemarkmarkSupported

Field Detail

messageback to summary
pack-priv Object message
monitorback to summary
private ProgressMonitor monitor
nreadback to summary
private int nread
parentComponentback to summary
pack-priv Component parentComponent
sizeback to summary
private int size

Constructor Detail

ProgressMonitorInputStreamback to summary
public ProgressMonitorInputStream(Component parentComponent, Object message, InputStream in)

Constructs an object to monitor the progress of an input stream.

Parameters
parentComponent:Component

The component triggering the operation being monitored.

message:Object

Descriptive text to be placed in the dialog box if one is popped up.

in:InputStream

The input stream to be monitored.

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.FilterInputStream.close.

Implements java.io.Closeable.close.

Overrides FilterInputStream.close to close the progress monitor as well as the stream.

Exceptions
IOException:

Doc from java.io.FilterInputStream.close.

if an I/O error occurs.

getProgressMonitorback to summary
public 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:ProgressMonitor

the ProgressMonitor object used by this object

readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Overrides FilterInputStream.read to update the progress monitor after the read.

Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.

readback to summary
public int read(byte[] b) throws IOException

Overrides java.io.FilterInputStream.read.

Overrides FilterInputStream.read to update the progress monitor after the read.

Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.

readback to summary
public int read(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterInputStream.read.

Overrides FilterInputStream.read to update the progress monitor after the read.

Exceptions
IOException:

Doc from java.io.FilterInputStream.read.

if an I/O error occurs.

resetback to summary
public synchronized void reset() throws IOException

Overrides java.io.FilterInputStream.reset.

Overrides FilterInputStream.reset to reset the progress monitor as well as the stream.

Exceptions
IOException:

Doc from java.io.FilterInputStream.reset.

if this stream has not been marked or if the mark has been invalidated.

setProgressback to summary
private void setProgress(int nr) throws IOException
skipback to summary
public long skip(long n) throws IOException

Overrides java.io.FilterInputStream.skip.

Overrides FilterInputStream.skip to update the progress monitor after the skip.

Exceptions
IOException:

Doc from java.io.FilterInputStream.skip.

if in.skip(n) throws an IOException.