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 / java / util / zip / InflaterInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.2 KB  |  126 lines

  1. package java.util.zip;
  2.  
  3. import java.io.EOFException;
  4. import java.io.FilterInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7.  
  8. public class InflaterInputStream extends FilterInputStream {
  9.    protected Inflater inf;
  10.    protected byte[] buf;
  11.    protected int len;
  12.    private boolean closed;
  13.    private boolean reachEOF;
  14.  
  15.    private void ensureOpen() throws IOException {
  16.       if (this.closed) {
  17.          throw new IOException("Stream closed");
  18.       }
  19.    }
  20.  
  21.    public InflaterInputStream(InputStream var1, Inflater var2, int var3) {
  22.       super(var1);
  23.       this.closed = false;
  24.       this.reachEOF = false;
  25.       if (var1 != null && var2 != null) {
  26.          if (var3 <= 0) {
  27.             throw new IllegalArgumentException("buffer size <= 0");
  28.          } else {
  29.             this.inf = var2;
  30.             this.buf = new byte[var3];
  31.          }
  32.       } else {
  33.          throw new NullPointerException();
  34.       }
  35.    }
  36.  
  37.    public InflaterInputStream(InputStream var1, Inflater var2) {
  38.       this(var1, var2, 512);
  39.    }
  40.  
  41.    public InflaterInputStream(InputStream var1) {
  42.       this(var1, new Inflater());
  43.    }
  44.  
  45.    public int read() throws IOException {
  46.       this.ensureOpen();
  47.       byte[] var1 = new byte[1];
  48.       return this.read(var1, 0, 1) == -1 ? -1 : var1[0] & 255;
  49.    }
  50.  
  51.    public int read(byte[] var1, int var2, int var3) throws IOException {
  52.       this.ensureOpen();
  53.       if ((var2 | var3 | var2 + var3 | var1.length - (var2 + var3)) < 0) {
  54.          throw new IndexOutOfBoundsException();
  55.       } else if (var3 == 0) {
  56.          return 0;
  57.       } else {
  58.          try {
  59.             int var4;
  60.             while((var4 = this.inf.inflate(var1, var2, var3)) == 0) {
  61.                if (this.inf.finished() || this.inf.needsDictionary()) {
  62.                   this.reachEOF = true;
  63.                   return -1;
  64.                }
  65.  
  66.                if (this.inf.needsInput()) {
  67.                   this.fill();
  68.                }
  69.             }
  70.  
  71.             return var4;
  72.          } catch (DataFormatException var6) {
  73.             String var5 = ((Throwable)var6).getMessage();
  74.             throw new ZipException(var5 != null ? var5 : "Invalid ZLIB data format");
  75.          }
  76.       }
  77.    }
  78.  
  79.    public int available() throws IOException {
  80.       this.ensureOpen();
  81.       return this.reachEOF ? 0 : 1;
  82.    }
  83.  
  84.    public long skip(long var1) throws IOException {
  85.       if (var1 < 0L) {
  86.          throw new IllegalArgumentException("negative skip length");
  87.       } else {
  88.          this.ensureOpen();
  89.          int var3 = (int)Math.min(var1, 2147483647L);
  90.          int var4 = 0;
  91.  
  92.          int var7;
  93.          for(byte[] var5 = new byte[512]; var4 < var3; var4 += var7) {
  94.             var7 = var3 - var4;
  95.             if (var7 > var5.length) {
  96.                var7 = var5.length;
  97.             }
  98.  
  99.             var7 = this.read(var5, 0, var7);
  100.             if (var7 == -1) {
  101.                this.reachEOF = true;
  102.                break;
  103.             }
  104.          }
  105.  
  106.          return (long)var4;
  107.       }
  108.    }
  109.  
  110.    public void close() throws IOException {
  111.       this.inf.end();
  112.       super.in.close();
  113.       this.closed = true;
  114.    }
  115.  
  116.    protected void fill() throws IOException {
  117.       this.ensureOpen();
  118.       this.len = super.in.read(this.buf, 0, this.buf.length);
  119.       if (this.len == -1) {
  120.          throw new EOFException("Unexpected end of ZLIB input stream");
  121.       } else {
  122.          this.inf.setInput(this.buf, 0, this.len);
  123.       }
  124.    }
  125. }
  126.