This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: InflaterInputStream fix and misc tweaks


InflaterInputStream would erronously return -1 if it had consumed all
its input data but if zlib still had data to output left in its
buffers, which would occur if it was used with a small output buffer.
This patch fixes that and also adds a few minor efficiency
improvmenets to some stream classes. I'm checking it in.

regards

  [ bryce ]


2000-11-29  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/util/zip/InflaterInputStream (read): Don't return -1 unless
	the inflate() call didn't deliver any output. Throw a ZipException if
	the needsDictionary() call returns true.
	(fill): Don't check for closed stream.
	* java/io/ByteArrayInputStream (read): Remove redundant bounds checks.
	* java/io/InputStreamReader: Use the default buffer size for the
	contained BufferedInputStream.

Index: java/util/zip/InflaterInputStream.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/zip/InflaterInputStream.java,v
retrieving revision 1.10
diff -u -r1.10 InflaterInputStream.java
--- InflaterInputStream.java	2000/11/17 21:42:28	1.10
+++ InflaterInputStream.java	2000/11/29 09:57:29
@@ -44,8 +44,6 @@
 {
   protected void fill () throws IOException
   {
-    if (inf == null)
-      throw new IOException ("stream closed");
     len = in.read(buf, 0, buf.length);
     if (len != -1)
       inf.setInput(buf, 0, len);
@@ -85,18 +83,23 @@
       return -1;
     if (inf.needsInput())
       fill ();
-    if (this.len == -1)
-      return -1; // Couldn't get any more data to feed to the Inflater
-    if (inf.needsDictionary())
-      return -1;
+    int count;
     try
       {
-	return inf.inflate(buf, off, len);
+	count = inf.inflate(buf, off, len);	
+	if (count == 0)
+	  {
+	    if (len == -1)
+	      return -1; // Couldn't get any more data to feed to the Inflater
+	    if (inf.needsDictionary())
+	      throw new ZipException ("Inflater needs Dictionary");
+	  }	      
       }
     catch (DataFormatException dfe)
       {
 	throw new ZipException (dfe.getMessage());
       }
+    return count;
   }
 
   public void close () throws IOException
Index: java/io/ByteArrayInputStream.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/ByteArrayInputStream.java,v
retrieving revision 1.3
diff -u -r1.3 ByteArrayInputStream.java
--- ByteArrayInputStream.java	2000/03/07 19:55:26	1.3
+++ ByteArrayInputStream.java	2000/11/29 09:57:29
@@ -72,9 +72,6 @@
 
   public synchronized int read()
   {
-    if (pos < 0)
-      throw new ArrayIndexOutOfBoundsException(pos);
-
     if (pos < count)
       return ((int) buf[pos++]) & 0xFF;
     return -1;
@@ -82,10 +79,6 @@
 
   public synchronized int read(byte[] b, int off, int len)
   {
-    /* Don't need to check pos value, arraycopy will check it. */
-    if (off < 0 || len < 0 || off + len > b.length)
-      throw new ArrayIndexOutOfBoundsException();
-
     if (pos >= count)
       return -1;
 
Index: java/io/InputStreamReader.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/io/InputStreamReader.java,v
retrieving revision 1.6
diff -u -r1.6 InputStreamReader.java
--- InputStreamReader.java	2000/03/07 19:55:26	1.6
+++ InputStreamReader.java	2000/11/29 09:57:30
@@ -46,7 +46,7 @@
   {
     this.in = in instanceof BufferedInputStream
               ? (BufferedInputStream) in
-              : new BufferedInputStream(in, 250);
+              : new BufferedInputStream(in);
     /* Don't need to call super(in) here as long as the lock gets set. */
     this.lock = in;
     converter = decoder;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]