[kaffe] Problem with BufferedInputStream [patch]

Mark Wielaard mark at klomp.org
Thu Jun 5 05:39:02 PDT 2003


Hi,

I tried to get my java bittorrent project (http://www.klomp.org/snark/),
working with kaffe and found a problem with BufferedInputStream. The
code contains the following construct (simplified, the real code uses a
Socket InputStream):

public class ReadLineTest
{
  public static void main(String args[]) throws Exception
  {
    InputStream in = System.in;
    BufferedInputStream bis = new BufferedInputStream(in);
    BufferedReader br = new BufferedReader
      (new InputStreamReader(bis, "US-ASCII"));
    String line = br.readLine();
    System.out.println(line);
  }
}

The expected behaviour is for the program to read a line and print it.
But readLine() will not return with the first line till at least 2048
characters have been input (which can be multiple lines).

The problem is in BufferedInputStream._read(byte b[], int off, int len).
Which tries to fill the given byte[] with len bytes even if it has
buffered less bytes (so it will keep readingfrom the underlying
InputStream).

The attached patch removes the while (len > 0) construct which makes the
above program (and The Hunting of the Snark Project) work correctly.

Mauve and make check results do not show regressions with this change.

Cheers,

Mark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BufferedInputStream.patch
Type: text/x-patch
Size: 2098 bytes
Desc: not available
Url : http://kaffe.org/pipermail/kaffe/attachments/20030605/de447197/attachment-0002.bin 


More information about the kaffe mailing list