home *** CD-ROM | disk | FTP | other *** search
- package sun.net.www;
-
- import java.io.FilterInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import sun.net.ProgressData;
- import sun.net.ProgressEntry;
-
- public class MeteredStream extends FilterInputStream {
- protected boolean closed = false;
- protected int expected;
- protected int count;
- // $FF: renamed from: te sun.net.ProgressEntry
- protected ProgressEntry field_0;
-
- public MeteredStream(InputStream var1, ProgressEntry var2) {
- super(var1);
- this.field_0 = var2;
- this.expected = var2.need;
- ProgressData.pdata.update(var2);
- }
-
- private final void justRead(int var1) throws IOException {
- if (var1 == -1) {
- this.close();
- } else {
- this.count += var1;
- this.field_0.update(this.count, this.expected);
- ProgressData.pdata.update(this.field_0);
- if (this.count >= this.expected) {
- this.close();
- }
-
- }
- }
-
- public synchronized int read() throws IOException {
- if (this.closed) {
- return -1;
- } else {
- int var1 = super.in.read();
- if (var1 != -1) {
- this.justRead(1);
- } else {
- this.close();
- }
-
- return var1;
- }
- }
-
- public synchronized int read(byte[] var1, int var2, int var3) throws IOException {
- if (this.closed) {
- return -1;
- } else {
- int var4 = super.in.read(var1, var2, var3);
- this.justRead(var4);
- return var4;
- }
- }
-
- public synchronized long skip(long var1) throws IOException {
- if (this.closed) {
- return 0L;
- } else {
- int var3 = var1 > (long)(this.expected - this.count) ? this.expected - this.count : (int)var1;
- var1 = super.in.skip((long)var3);
- this.justRead((int)var1);
- return var1;
- }
- }
-
- public void close() throws IOException {
- if (!this.closed) {
- ProgressData.pdata.unregister(this.field_0);
- this.closed = true;
- super.in.close();
- }
- }
-
- public synchronized int available() throws IOException {
- return this.closed ? 0 : super.in.available();
- }
-
- protected void finalize() {
- this.field_0.what = 3;
- }
- }
-