BufferedInputStream has the flexibility for its subclass to control buffer 
behavior. So it leaves some fields such as "count" and "pos" accessible by 
its subclass to realize some specific buffer behaviors such as recyclable 
buffer. 
So we should consious about the usage of such fields. For example, a 
buffer will set "pos" to discretional position or set "count" to discretional number 
(for a recyclable buffer, it could set it to 0). 
So it's too weak in current implementation of read that just verify 
"if(pos == count)" to decide whether refill buffer.
A patch should like this:

public synchronized int
read() throws IOException
{
-  if ((pos == count) || !primed)
+   if ((pos >= count) || !primed)

    {
      refillBuffer(1);
      
-      if (pos == count)
+           if (pos >= count)
        return(-1);
    }

  ++pos;

  return((buf[pos - 1] & 0xFF));
}


public synchronized int
read(byte[] buf, int offset, int len) throws IOException
{
    ... ...
  // Read the rest of the bytes
  try
    {
      for(;total_read != len;)
        {
-          if (pos == count)
+          if (pos >= count)
            refillBuffer(len - total_read);

-          if (pos == count)
+          if (pos >= count)
            if (total_read == 0)
              return(-1);
            else
              return(total_read);
    ... ...
}


_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to