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.
ProgressMonitor, JOptionPane
| Modifier and Type | Field and Description |
|---|---|
| pack-priv Object | |
| private ProgressMonitor | |
| private int | |
| pack-priv Component | |
| private int |
| Access | Constructor 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. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Overrides java. Implements java. Overrides |
| public ProgressMonitor | Returns: the ProgressMonitor object used by this objectGet the ProgressMonitor object being used by this stream. |
| public int | read()
Overrides java. Overrides |
| public int | read(byte[] b)
Overrides java. Overrides |
| public int | read(byte[] b, int off, int len)
Overrides java. Overrides |
| public synchronized void | reset()
Overrides java. Overrides |
| private void | |
| public long | skip(long n)
Overrides java. Overrides |
| message | back to summary |
|---|---|
| pack-priv Object message | |
| monitor | back to summary |
|---|---|
| private ProgressMonitor monitor | |
| nread | back to summary |
|---|---|
| private int nread | |
| parentComponent | back to summary |
|---|---|
| pack-priv Component parentComponent | |
| size | back to summary |
|---|---|
| private int size | |
| ProgressMonitorInputStream | back to summary |
|---|---|
| public ProgressMonitorInputStream(Component parentComponent, Object message, InputStream in) Constructs an object to monitor the progress of an input stream.
| |
| close | back to summary |
|---|---|
| public void close() throws IOException Overrides java. Implements java. Overrides
| |
| getProgressMonitor | back 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.
| |
| read | back to summary |
|---|---|
| public int read() throws IOException Overrides java. Overrides
| |
| read | back to summary |
|---|---|
| public int read(byte[] b) throws IOException Overrides java. Overrides
| |
| read | back to summary |
|---|---|
| public int read(byte[] b, int off, int len) throws IOException Overrides java. Overrides
| |
| reset | back to summary |
|---|---|
| public synchronized void reset() throws IOException Overrides java. Overrides
| |
| setProgress | back to summary |
|---|---|
| private void setProgress(int nr) throws IOException | |
| skip | back to summary |
|---|---|
| public long skip(long n) throws IOException Overrides java. Overrides
| |