home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / net / www / MeteredStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  1.6 KB  |  89 lines

  1. package sun.net.www;
  2.  
  3. import java.io.FilterInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import sun.net.ProgressData;
  7. import sun.net.ProgressEntry;
  8.  
  9. public class MeteredStream extends FilterInputStream {
  10.    protected boolean closed = false;
  11.    protected int expected;
  12.    protected int count;
  13.    // $FF: renamed from: te sun.net.ProgressEntry
  14.    protected ProgressEntry field_0;
  15.  
  16.    public MeteredStream(InputStream var1, ProgressEntry var2) {
  17.       super(var1);
  18.       this.field_0 = var2;
  19.       this.expected = var2.need;
  20.       ProgressData.pdata.update(var2);
  21.    }
  22.  
  23.    private final void justRead(int var1) throws IOException {
  24.       if (var1 == -1) {
  25.          this.close();
  26.       } else {
  27.          this.count += var1;
  28.          this.field_0.update(this.count, this.expected);
  29.          ProgressData.pdata.update(this.field_0);
  30.          if (this.count >= this.expected) {
  31.             this.close();
  32.          }
  33.  
  34.       }
  35.    }
  36.  
  37.    public synchronized int read() throws IOException {
  38.       if (this.closed) {
  39.          return -1;
  40.       } else {
  41.          int var1 = super.in.read();
  42.          if (var1 != -1) {
  43.             this.justRead(1);
  44.          } else {
  45.             this.close();
  46.          }
  47.  
  48.          return var1;
  49.       }
  50.    }
  51.  
  52.    public synchronized int read(byte[] var1, int var2, int var3) throws IOException {
  53.       if (this.closed) {
  54.          return -1;
  55.       } else {
  56.          int var4 = super.in.read(var1, var2, var3);
  57.          this.justRead(var4);
  58.          return var4;
  59.       }
  60.    }
  61.  
  62.    public synchronized long skip(long var1) throws IOException {
  63.       if (this.closed) {
  64.          return 0L;
  65.       } else {
  66.          int var3 = var1 > (long)(this.expected - this.count) ? this.expected - this.count : (int)var1;
  67.          var1 = super.in.skip((long)var3);
  68.          this.justRead((int)var1);
  69.          return var1;
  70.       }
  71.    }
  72.  
  73.    public void close() throws IOException {
  74.       if (!this.closed) {
  75.          ProgressData.pdata.unregister(this.field_0);
  76.          this.closed = true;
  77.          super.in.close();
  78.       }
  79.    }
  80.  
  81.    public synchronized int available() throws IOException {
  82.       return this.closed ? 0 : super.in.available();
  83.    }
  84.  
  85.    protected void finalize() {
  86.       this.field_0.what = 3;
  87.    }
  88. }
  89.