[Advanced-java] Inheritation of InputStream crashs BufferedReader
Marco Ferretti
marco.ferretti at gmail.com
Thu Apr 27 09:43:47 PDT 2006
On Thursday 27 April 2006 18:05, Peter Rader wrote:
> Hi Folks,
>
> i do not often post to this list, but this time i need your help.
>
> My java decompiler show me the sourcecode of InputStream, so i see
> that i only have to override the method "int read()" and "int available()"
> and his constructor?! Right?
>
For what I may see ... yes
> I do so and convert my inputstream to BufferedReader this way:
>
> BufferedReader myreader = new BufferedReader(new
> InputStreamReader(myInheritOfInputstream));
>
> Everything works fine, until my InputStream got no more data.
>
> "myreader.ready()" is true while my InputStream's methode "available()"
> returns 0.
>
> So what do i have to do, to inform the BufferedReader that there is no
> more data?
Actually, the BufferedReader.ready() method :
return (nextChar < nChars) || in.ready();
in your case you have to check that . If in.ready is called, then the internal
Reader.ready() is called ( in your case InputStreamReader.ready() ) which
returns StreamDecoder.ready() . Now, StramDecoder is
sun.nio.cs.StreamDecoder which means that it does something dependent on the
system. What it looks like is that wither the buffer is somehow
"dirty" ( there's something else to be passed on ) or the StramDecoder sees
more data .
Unfortunately, my knowlegde ends here (it would have been nice 2 have the
sources of the nio classes ....) .
hope it helps .
--
You should go home.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : /lists/advanced-java/attachments/20060427/3cd82441/attachment.bin
More information about the Advanced-java
mailing list