summaryrefslogtreecommitdiff
path: root/libjava/java/util/zip/InflaterInputStream.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2004-07-09 15:22:19 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2004-07-09 15:22:19 +0000
commitd642571f32e52d00e0a287c6238dd5d9faeea82d (patch)
treeda8856033bd84b9270468089c3a2f34c2c565b0a /libjava/java/util/zip/InflaterInputStream.java
parentfbc40a17c9aeaa3342d4122c45356fec7faa14e3 (diff)
DeflaterOutputStream.java, [...]: Reformatted.
2004-07-09 Michael Koch <konqueror@gmx.de> * java/util/zip/DeflaterOutputStream.java, java/util/zip/GZIPInputStream.java, java/util/zip/GZIPOutputStream.java, java/util/zip/InflaterInputStream.java: Reformatted. Added javadocs. Reordered all stuff. Renamed variables to be more clear. From-SVN: r84380
Diffstat (limited to 'libjava/java/util/zip/InflaterInputStream.java')
-rw-r--r--libjava/java/util/zip/InflaterInputStream.java99
1 files changed, 53 insertions, 46 deletions
diff --git a/libjava/java/util/zip/InflaterInputStream.java b/libjava/java/util/zip/InflaterInputStream.java
index 9fac83fc6dc..60442e474af 100644
--- a/libjava/java/util/zip/InflaterInputStream.java
+++ b/libjava/java/util/zip/InflaterInputStream.java
@@ -70,12 +70,6 @@ public class InflaterInputStream extends FilterInputStream
*/
protected int len;
- protected void fill () throws IOException
- {
- len = in.read(buf, 0, buf.length);
- if (len != -1)
- inf.setInput(buf, 0, len);
- }
/**
* Create an InflaterInputStream with the default decompresseor
@@ -85,7 +79,7 @@ public class InflaterInputStream extends FilterInputStream
*/
public InflaterInputStream(InputStream in)
{
- this (in, new Inflater (), 512);
+ this(in, new Inflater(), 512);
}
/**
@@ -97,7 +91,7 @@ public class InflaterInputStream extends FilterInputStream
*/
public InflaterInputStream(InputStream in, Inflater inf)
{
- this (in, inf, 512);
+ this(in, inf, 512);
}
/**
@@ -113,25 +107,51 @@ public class InflaterInputStream extends FilterInputStream
super(in);
if (in == null)
- throw new NullPointerException ("in may not be null");
+ throw new NullPointerException("in may not be null");
if (inf == null)
- throw new NullPointerException ("inf may not be null");
+ throw new NullPointerException("inf may not be null");
if (size < 0)
- throw new IllegalArgumentException ("size may not be negative");
+ throw new IllegalArgumentException("size may not be negative");
this.inf = inf;
this.buf = new byte [size];
}
- public int read () throws IOException
+ /**
+ * Returns 0 once the end of the stream (EOF) has been reached.
+ * Otherwise returns 1.
+ */
+ public int available() throws IOException
+ {
+ // According to the JDK 1.2 docs, this should only ever return 0
+ // or 1 and should not be relied upon by Java programs.
+ if (inf == null)
+ throw new IOException("stream closed");
+ return inf.finished() ? 0 : 1;
+ }
+
+ /**
+ * Closes the input stream
+ */
+ public synchronized void close() throws IOException
{
- byte[] buf = new byte[1];
- int r = read (buf, 0, 1);
- if (r != -1)
- r = buf[0] & 0xff;
- return r;
+ inf = null;
+ super.close();
}
+ /**
+ * Fills the buffer with more data to decompress.
+ */
+ protected void fill() throws IOException
+ {
+ if (in == null)
+ throw new ZipException ("InflaterInputStream is closed");
+
+ len = in.read(buf, 0, buf.length);
+
+ if (len != -1)
+ inf.setInput(buf, 0, len);
+ }
/**
* Decompresses data into the byte array
@@ -143,7 +163,7 @@ public class InflaterInputStream extends FilterInputStream
public int read(byte[] b, int off, int len) throws IOException
{
if (inf == null)
- throw new IOException ("stream closed");
+ throw new IOException("stream closed");
if (len == 0)
return 0;
if (inf.finished())
@@ -153,7 +173,7 @@ public class InflaterInputStream extends FilterInputStream
while (count == 0)
{
if (inf.needsInput())
- fill ();
+ fill();
try
{
@@ -166,7 +186,7 @@ public class InflaterInputStream extends FilterInputStream
return -1;
}
if (inf.needsDictionary())
- throw new ZipException ("Inflater needs Dictionary");
+ throw new ZipException("Inflater needs Dictionary");
}
}
catch (DataFormatException dfe)
@@ -177,21 +197,6 @@ public class InflaterInputStream extends FilterInputStream
return count;
}
- public void close () throws IOException
- {
- inf = null;
- super.close ();
- }
-
- public int available () throws IOException
- {
- // According to the JDK 1.2 docs, this should only ever return 0
- // or 1 and should not be relied upon by Java programs.
- if (inf == null)
- throw new IOException ("stream closed");
- return inf.finished () ? 0 : 1;
- }
-
/**
* Skip specified number of bytes of uncompressed data
*
@@ -200,25 +205,27 @@ public class InflaterInputStream extends FilterInputStream
public long skip(long n) throws IOException
{
if (inf == null)
- throw new IOException ("stream closed");
+ throw new IOException("stream closed");
+ if (n < 0)
+ throw new IllegalArgumentException();
if (n == 0)
return 0;
- int min = (int) Math.min(n, 1024);
- byte[] buf = new byte[min];
+ int buflen = (int) Math.min(n, 1024);
+ byte[] tmpbuf = new byte[buflen];
- long s = 0;
- while (n > 0)
+ long skipped = 0L;
+ while (n > 0L)
{
- int r = read (buf, 0, min);
- if (r == -1)
+ int numread = read(tmpbuf, 0, buflen);
+ if (numread == -1)
break;
- n -= r;
- s += r;
- min = (int) Math.min(n, 1024);
+ n -= numread;
+ skipped += numread;
+ buflen = (int) Math.min(n, 1024);
}
- return s;
+ return skipped;
}
}