[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Patch for java.util.zip.InflaterInputStream
From: |
Ingo Prötel |
Subject: |
Patch for java.util.zip.InflaterInputStream |
Date: |
Mon, 05 Apr 2004 17:47:18 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040113 |
I suggest the following patch to skip more than 2k bytes:
2004-04-05 IngoProetel <address@hidden>
* java/util/zip/InflaterInputStream.java (skip): Copied implementation
from java.io.InputStream.
ingo
--
Ingo Prötel address@hidden
aicas GmbH http://www.aicas.com
Haid-und-Neu-Str. 18 phone +49 721 663 968-32
76131 Karlsruhe fax +49 721 663 968-93
Germany
Index: java/util/zip/InflaterInputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/zip/InflaterInputStream.java,v
retrieving revision 1.10
diff -u -r1.10 InflaterInputStream.java
--- java/util/zip/InflaterInputStream.java 4 Nov 2003 10:04:16 -0000
1.10
+++ java/util/zip/InflaterInputStream.java 5 Apr 2004 15:41:10 -0000
@@ -215,13 +215,23 @@
*/
public long skip(long n) throws IOException
{
- if (n < 0)
- throw new IllegalArgumentException();
- int len = 2048;
- if (n < len)
- len = (int) n;
- byte[] tmp = new byte[len];
- return (long) read(tmp);
+ // 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;
+ byte[] tmpbuf = new byte[buflen];
+ final long origN = n;
+
+ while (n > 0L)
+ {
+ int numread = read(tmpbuf, 0, n > buflen ? buflen : (int) n);
+ if (numread <= 0)
+ break;
+ n -= numread;
+ }
+
+ return origN - n;
+
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Patch for java.util.zip.InflaterInputStream,
Ingo Prötel <=