Hi,
Just got some strange 'invalid mark' IOExceptions from BufferedReader
(latest CVS version).
It claims, that there is no mark set, though there actually _is_ a mark.

Problem is that in mark() it isn't taken care, that we've at leaset
readAheadLimit chars in the buffer. In case the size is less than
readAheadLimit, we've to fill the rest of the buffer.

This is done in the patch attached.

ciao,
  -hen
PS: keep up the good woork!
---
Henner Zeller                                 [EMAIL PROTECTED]
 PGP pub key [77F75B39]: finger [EMAIL PROTECTED] 

 If Microsoft is the answer, it must have been a VERY silly question.
Index: BufferedReader.java
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/javalib/java/io/BufferedReader.java,v
retrieving revision 1.5
diff -u -r1.5 BufferedReader.java
--- BufferedReader.java 1999/03/23 21:27:17     1.5
+++ BufferedReader.java 1999/06/18 11:29:09
@@ -50,6 +50,8 @@
                // Shift data to the beginning of the buffer
                System.arraycopy(oldbuf, pos, inbuf, 0, size - pos);
                size -= pos;
+               if (size < readAheadLimit)
+                   refillBuffer (pos);
                pos = 0;
                markset = true;
        }
@@ -159,19 +161,23 @@
 }
 
 private int refillBuffer () throws IOException {
+    // Precondition: ASSERT (!markset)
+    return refillBuffer (0);
+}
+
+private int refillBuffer (int atPos) throws IOException {
        synchronized ( lock ) {
                int n;
 
-               n = rd.read( inbuf, 0, inbuf.length);
-               pos = 0;
-               markset = false;
+               n = rd.read( inbuf, atPos, inbuf.length - atPos);
+               pos = atPos;
                        
                if (n > 0) {
-                       size = n;
+                       size = n + atPos;
                        return (n);
                }
                else {
-                       size = 0;
+                       size = atPos;
                        return (-1);
                }
        }

Reply via email to