summaryrefslogtreecommitdiff
path: root/java/util/zip/InflaterInputStream.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2004-06-15 10:37:14 +0000
committerMichael Koch <konqueror@gmx.de>2004-06-15 10:37:14 +0000
commit0beaeb8e539bb3596b4c847639d991890b079d73 (patch)
tree3ecfbc9741b2c4fddf8266c824b7a083a6ac4f47 /java/util/zip/InflaterInputStream.java
parent6744aad4954f307e684dbc58edb872993f318ade (diff)
downloadclasspath-0beaeb8e539bb3596b4c847639d991890b079d73.tar.gz
2004-06-15 Michael Koch <konqueror@gmx.de>
* java/util/zip/DeflaterOutputStream.java: Reformatted. * java/util/zip/InflaterInputStream.java (InflaterInputStream): Removed redundant initialization of len to 0. (available): Check for closed stream. (read): Likewise. (skip): Check for closed stream, simplified implementation.
Diffstat (limited to 'java/util/zip/InflaterInputStream.java')
-rw-r--r--java/util/zip/InflaterInputStream.java28
1 files changed, 16 insertions, 12 deletions
diff --git a/java/util/zip/InflaterInputStream.java b/java/util/zip/InflaterInputStream.java
index 3c75e0115..ef04c5885 100644
--- a/java/util/zip/InflaterInputStream.java
+++ b/java/util/zip/InflaterInputStream.java
@@ -109,14 +109,13 @@ public class InflaterInputStream extends FilterInputStream
public InflaterInputStream(InputStream in, Inflater inf, int size)
{
super(in);
- this.len = 0;
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];
@@ -130,6 +129,8 @@ public class InflaterInputStream extends FilterInputStream
{
// 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;
}
@@ -183,12 +184,14 @@ public class InflaterInputStream extends FilterInputStream
*/
public int read(byte[] b, int off, int len) throws IOException
{
+ if (inf == null)
+ throw new IOException("stream closed");
if (len == 0)
return 0;
+ int count = 0;
for (;;)
{
- int count;
try
{
@@ -219,27 +222,28 @@ public class InflaterInputStream extends FilterInputStream
*/
public long skip(long n) throws IOException
{
+ if (inf == null)
+ throw new IOException("stream closed");
if (n < 0)
throw new IllegalArgumentException();
if (n == 0)
return 0;
- // Implementation copied from InputStream
- // Throw away n bytes by reading them into a temp byte[].
- // Limit the temp array to 2Kb so we don't grab too much memory.
- final int buflen = n > 2048 ? 2048 : (int) n;
+ int buflen = (int) Math.min(n, 2048);
byte[] tmpbuf = new byte[buflen];
- final long origN = n;
+ long skipped = 0L;
while (n > 0L)
{
- int numread = read(tmpbuf, 0, n > buflen ? buflen : (int) n);
+ int numread = read(tmpbuf, 0, buflen);
if (numread <= 0)
break;
n -= numread;
+ skipped += numread;
+ buflen = (int) Math.min(n, 2048);
}
- return origN - n;
+ return skipped;
}
}