< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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);


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 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);


< prev index next >