]> gcc.gnu.org Git - gcc.git/commitdiff
re PR libgcj/18840 (java.io.BufferedInputStream.read(byte[],..) methods don't attempt...
authorTom Tromey <tromey@redhat.com>
Tue, 11 Jan 2005 20:04:33 +0000 (20:04 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Tue, 11 Jan 2005 20:04:33 +0000 (20:04 +0000)
PR libgcj/18840:
* java/io/BufferedInputStream.java (read): Repeatedly read to
fill buffer.
(refill): Change test to see if buffer must be grown.

From-SVN: r93192

libjava/ChangeLog
libjava/java/io/BufferedInputStream.java

index 14bc8281ddb8be87a63d3dcb75798a98a3426b91..1276a680cde18cff62c54de2b5dc396212de2e42 100644 (file)
@@ -1,3 +1,10 @@
+2005-01-11  Tom Tromey  <tromey@redhat.com>
+
+       PR libgcj/18840:
+       * java/io/BufferedInputStream.java (read): Repeatedly read to
+       fill buffer.
+       (refill): Change test to see if buffer must be grown.
+
 2005-01-10  Tom Tromey  <tromey@redhat.com>
 
        * mauve-libgcj: Exclude some swing tests.
index 27fc4b7b49dfe0a526ce128e1ae16d611c3852b6..5343f0762b619eeb461edee53a898c2ecb3b3e45 100644 (file)
@@ -1,5 +1,5 @@
 /* BufferedInputStream.java -- An input stream that implements buffering
-   Copyright (C) 1998, 1999, 2001, 2004  Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2001, 2004, 2005  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -198,7 +198,7 @@ public class BufferedInputStream extends FilterInputStream
   {
     marktarget = marklimit = readlimit;
     if (marklimit > CHUNKSIZE)
-       marklimit = CHUNKSIZE;
+      marklimit = CHUNKSIZE;
     markpos = pos;
   }
 
@@ -241,7 +241,10 @@ public class BufferedInputStream extends FilterInputStream
    * This method reads bytes from a stream and stores them into a caller
    * supplied buffer.  It starts storing the data at index <code>off</code>
    * into the buffer and attempts to read <code>len</code> bytes.  This method
-   * can return before reading the number of bytes requested.
+   * can return before reading the number of bytes requested, but it will try
+   * to read the requested number of bytes by repeatedly calling the underlying
+   * stream as long as available() for this stream continues to return a
+   * non-zero value (or until the requested number of bytes have been read).
    * The actual number of bytes read is returned as an int.  A -1 is returned
    * to indicate the end of the stream.
    * <p>
@@ -263,16 +266,34 @@ public class BufferedInputStream extends FilterInputStream
     if (off < 0 || len < 0 || b.length - off < len)
       throw new IndexOutOfBoundsException();
 
+    if (len == 0)
+      return 0;
+
     if (pos >= count && !refill())
       return -1;               // No bytes were read before EOF.
 
     int totalBytesRead = Math.min(count - pos, len);
     System.arraycopy(buf, pos, b, off, totalBytesRead);
     pos += totalBytesRead;
+    off += totalBytesRead;
+    len -= totalBytesRead;
 
     if (markpos >= 0 && pos - markpos > marktarget)
       markpos = -1;
 
+    while (len > 0 && super.available() > 0 && refill())
+      {
+       int remain = Math.min(count - pos, len);
+       System.arraycopy(buf, pos, b, off, remain);
+       pos += remain;
+       off += remain;
+       len -= remain;
+       totalBytesRead += remain;
+
+       if (markpos >= 0 && pos - markpos > marktarget)
+         markpos = -1;
+      }
+
     return totalBytesRead;
   }
 
@@ -311,7 +332,7 @@ public class BufferedInputStream extends FilterInputStream
   public synchronized long skip(long n) throws IOException
   {
     if (buf == null)
-       throw new IOException("Stream closed.");
+      throw new IOException("Stream closed.");
 
     final long origN = n;
 
@@ -343,7 +364,7 @@ public class BufferedInputStream extends FilterInputStream
   boolean refill() throws IOException
   {
     if (buf == null)
-       throw new IOException("Stream closed.");
+      throw new IOException("Stream closed.");
 
     if (markpos < 0)
       count = pos = 0;
@@ -357,7 +378,7 @@ public class BufferedInputStream extends FilterInputStream
        pos -= markpos;
        markpos = 0;
       }
-    else if (marktarget >= buf.length && marklimit < marktarget)       // BTW, markpos == 0
+    else if (count >= buf.length && count < marktarget)        // BTW, markpos == 0
       {
        // Need to grow the buffer now to have room for marklimit bytes.
        // Note that the new buffer is one greater than marklimit.
@@ -378,6 +399,6 @@ public class BufferedInputStream extends FilterInputStream
       return false;
 
     count += numread;
-    return true;
+    return numread > 0;
   }
 }
This page took 0.076646 seconds and 5 git commands to generate.