Re: Trouble with custom InputStream being used by Readers
On 06/08/2008 02:04, Tom Anderson allegedly wrote:
On Tue, 5 Aug 2008, Chase Preuninger wrote:
Well how does any other console stop blocking so that a BufferedReader
can stop buffering? Does it just return -1 when it has more data. But
what if it acquires more later on?
I suspect, but am not certain, that Daniele is wrong about
BufferedReader's behaviour.
Might always be the case.
But:
private static class BogusInputStream
extends InputStream
{
private final int size;
private int pos;
public BogusInputStream(int size){
this.size = size;
}
public int read()
throws IOException
{
if( pos < size ){
pos++; return 'a';
}
else{
for(;;);
}
}
}
public static void main(String[] ss)
throws Exception
{
Reader r1 = new InputStreamReader(new BogusInputStream(1<<13));
Reader r2 = new InputStreamReader(new BogusInputStream(1<<12));
r1.read(); // <- works
r2.read(); // <- blocks
}
From which we can infer that on my machine, the sun.nio.cs.StreamDecoder
has an 8k buffer.
Granted, that's not the BufferedReader, but I think it's pretty much a
given that that infinite loop is the root of the problem. That, and not
overriding int read(byte[], int, int) or int read(char[], int, int).
--
DF.