< prev index next >

src/java.desktop/share/classes/javax/swing/ProgressMonitorInputStream.java

Print this page




  87         }
  88         catch(IOException ioe) {
  89             size = 0;
  90         }
  91         monitor = new ProgressMonitor(parentComponent, message, null, 0, size);
  92     }
  93 
  94 
  95     /**
  96      * Get the ProgressMonitor object being used by this stream. Normally
  97      * this isn't needed unless you want to do something like change the
  98      * descriptive text partway through reading the file.
  99      * @return the ProgressMonitor object used by this object
 100      */
 101     public ProgressMonitor getProgressMonitor() {
 102         return monitor;
 103     }
 104 
 105 
 106     /**
 107      * Overrides <code>FilterInputStream.read</code>
 108      * to update the progress monitor after the read.
 109      */
 110     public int read() throws IOException {
 111         int c = in.read();
 112         if (c >= 0) monitor.setProgress(++nread);
 113         if (monitor.isCanceled()) {
 114             InterruptedIOException exc =
 115                                     new InterruptedIOException("progress");
 116             exc.bytesTransferred = nread;
 117             throw exc;
 118         }
 119         return c;
 120     }
 121 
 122 
 123     /**
 124      * Overrides <code>FilterInputStream.read</code>
 125      * to update the progress monitor after the read.
 126      */
 127     public int read(byte b[]) throws IOException {
 128         int nr = in.read(b);
 129         if (nr > 0) monitor.setProgress(nread += nr);
 130         if (monitor.isCanceled()) {
 131             InterruptedIOException exc =
 132                                     new InterruptedIOException("progress");
 133             exc.bytesTransferred = nread;
 134             throw exc;
 135         }
 136         return nr;
 137     }
 138 
 139 
 140     /**
 141      * Overrides <code>FilterInputStream.read</code>
 142      * to update the progress monitor after the read.
 143      */
 144     public int read(byte b[],
 145                     int off,
 146                     int len) throws IOException {
 147         int nr = in.read(b, off, len);
 148         if (nr > 0) monitor.setProgress(nread += nr);
 149         if (monitor.isCanceled()) {
 150             InterruptedIOException exc =
 151                                     new InterruptedIOException("progress");
 152             exc.bytesTransferred = nread;
 153             throw exc;
 154         }
 155         return nr;
 156     }
 157 
 158 
 159     /**
 160      * Overrides <code>FilterInputStream.skip</code>
 161      * to update the progress monitor after the skip.
 162      */
 163     public long skip(long n) throws IOException {
 164         long nr = in.skip(n);
 165         if (nr > 0) monitor.setProgress(nread += nr);
 166         return nr;
 167     }
 168 
 169 
 170     /**
 171      * Overrides <code>FilterInputStream.close</code>
 172      * to close the progress monitor as well as the stream.
 173      */
 174     public void close() throws IOException {
 175         in.close();
 176         monitor.close();
 177     }
 178 
 179 
 180     /**
 181      * Overrides <code>FilterInputStream.reset</code>
 182      * to reset the progress monitor as well as the stream.
 183      */
 184     public synchronized void reset() throws IOException {
 185         in.reset();
 186         nread = size - in.available();
 187         monitor.setProgress(nread);
 188     }
 189 }


  87         }
  88         catch(IOException ioe) {
  89             size = 0;
  90         }
  91         monitor = new ProgressMonitor(parentComponent, message, null, 0, size);
  92     }
  93 
  94 
  95     /**
  96      * Get the ProgressMonitor object being used by this stream. Normally
  97      * this isn't needed unless you want to do something like change the
  98      * descriptive text partway through reading the file.
  99      * @return the ProgressMonitor object used by this object
 100      */
 101     public ProgressMonitor getProgressMonitor() {
 102         return monitor;
 103     }
 104 
 105 
 106     /**
 107      * Overrides {@code FilterInputStream.read}
 108      * to update the progress monitor after the read.
 109      */
 110     public int read() throws IOException {
 111         int c = in.read();
 112         if (c >= 0) monitor.setProgress(++nread);
 113         if (monitor.isCanceled()) {
 114             InterruptedIOException exc =
 115                                     new InterruptedIOException("progress");
 116             exc.bytesTransferred = nread;
 117             throw exc;
 118         }
 119         return c;
 120     }
 121 
 122 
 123     /**
 124      * Overrides {@code FilterInputStream.read}
 125      * to update the progress monitor after the read.
 126      */
 127     public int read(byte b[]) throws IOException {
 128         int nr = in.read(b);
 129         if (nr > 0) monitor.setProgress(nread += nr);
 130         if (monitor.isCanceled()) {
 131             InterruptedIOException exc =
 132                                     new InterruptedIOException("progress");
 133             exc.bytesTransferred = nread;
 134             throw exc;
 135         }
 136         return nr;
 137     }
 138 
 139 
 140     /**
 141      * Overrides {@code FilterInputStream.read}
 142      * to update the progress monitor after the read.
 143      */
 144     public int read(byte b[],
 145                     int off,
 146                     int len) throws IOException {
 147         int nr = in.read(b, off, len);
 148         if (nr > 0) monitor.setProgress(nread += nr);
 149         if (monitor.isCanceled()) {
 150             InterruptedIOException exc =
 151                                     new InterruptedIOException("progress");
 152             exc.bytesTransferred = nread;
 153             throw exc;
 154         }
 155         return nr;
 156     }
 157 
 158 
 159     /**
 160      * Overrides {@code FilterInputStream.skip}
 161      * to update the progress monitor after the skip.
 162      */
 163     public long skip(long n) throws IOException {
 164         long nr = in.skip(n);
 165         if (nr > 0) monitor.setProgress(nread += nr);
 166         return nr;
 167     }
 168 
 169 
 170     /**
 171      * Overrides {@code FilterInputStream.close}
 172      * to close the progress monitor as well as the stream.
 173      */
 174     public void close() throws IOException {
 175         in.close();
 176         monitor.close();
 177     }
 178 
 179 
 180     /**
 181      * Overrides {@code FilterInputStream.reset}
 182      * to reset the progress monitor as well as the stream.
 183      */
 184     public synchronized void reset() throws IOException {
 185         in.reset();
 186         nread = size - in.available();
 187         monitor.setProgress(nread);
 188     }
 189 }
< prev index next >