home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / ProgressMonitorInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.5 KB  |  95 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Component;
  4. import java.io.FilterInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.InterruptedIOException;
  8.  
  9. public class ProgressMonitorInputStream extends FilterInputStream {
  10.    private ProgressMonitor monitor;
  11.    private int nread = 0;
  12.    private int size = 0;
  13.  
  14.    public ProgressMonitorInputStream(Component var1, Object var2, InputStream var3) {
  15.       super(var3);
  16.  
  17.       try {
  18.          this.size = var3.available();
  19.       } catch (IOException var5) {
  20.          this.size = 0;
  21.       }
  22.  
  23.       this.monitor = new ProgressMonitor(var1, var2, (String)null, 0, this.size);
  24.    }
  25.  
  26.    public ProgressMonitor getProgressMonitor() {
  27.       return this.monitor;
  28.    }
  29.  
  30.    public int read() throws IOException {
  31.       int var1 = super.in.read();
  32.       if (var1 >= 0) {
  33.          this.monitor.setProgress(++this.nread);
  34.       }
  35.  
  36.       if (this.monitor.isCanceled()) {
  37.          InterruptedIOException var2 = new InterruptedIOException("progress");
  38.          var2.bytesTransferred = this.nread;
  39.          throw var2;
  40.       } else {
  41.          return var1;
  42.       }
  43.    }
  44.  
  45.    public int read(byte[] var1) throws IOException {
  46.       int var2 = super.in.read(var1);
  47.       if (var2 > 0) {
  48.          this.monitor.setProgress(this.nread += var2);
  49.       }
  50.  
  51.       if (this.monitor.isCanceled()) {
  52.          InterruptedIOException var3 = new InterruptedIOException("progress");
  53.          var3.bytesTransferred = this.nread;
  54.          throw var3;
  55.       } else {
  56.          return var2;
  57.       }
  58.    }
  59.  
  60.    public int read(byte[] var1, int var2, int var3) throws IOException {
  61.       int var4 = super.in.read(var1, var2, var3);
  62.       if (var4 > 0) {
  63.          this.monitor.setProgress(this.nread += var4);
  64.       }
  65.  
  66.       if (this.monitor.isCanceled()) {
  67.          InterruptedIOException var5 = new InterruptedIOException("progress");
  68.          var5.bytesTransferred = this.nread;
  69.          throw var5;
  70.       } else {
  71.          return var4;
  72.       }
  73.    }
  74.  
  75.    public long skip(long var1) throws IOException {
  76.       long var3 = super.in.skip(var1);
  77.       if (var3 > 0L) {
  78.          this.monitor.setProgress(this.nread = (int)((long)this.nread + var3));
  79.       }
  80.  
  81.       return var3;
  82.    }
  83.  
  84.    public void close() throws IOException {
  85.       super.in.close();
  86.       this.monitor.close();
  87.    }
  88.  
  89.    public synchronized void reset() throws IOException {
  90.       super.in.reset();
  91.       this.nread = this.size - super.in.available();
  92.       this.monitor.setProgress(this.nread);
  93.    }
  94. }
  95.