Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
Hello there, I am posting this unusual behavior I got from combining BufferedReader.ready() and BufferedReader.readLine() when trying to patch an example from SUN's JAVA tutorial. -------------------- ORIGINAL EXAMPLE CODE import java.io.*; public class EchoClient { ------------------- This example works fine except for the fact it expects exactly one line of text as the reply to any single line of command. So I felt compelled to patch the code to alow multiple response lines to a single command, thus having: 1 Now, for my surprise I get in.readLine() to block immediately, I think, well I think, there could be the case when I have data ready for reading, but not \n \r or \r\n terminated (wich is not the case), so I pached on (I'll spare you from the code) and found that if I have in BufferedReader a "foo\n" string waiting, I have .ready() == true; Ok, if I .read() 4 times I get f o o \n respectively and .ready() == false; Ok, but if I .readLine() it, I get "foo\n" but .ready() STILL ON !!! Also weird is the fact of in.ready() == false in line 1, and true in line 3 ! Any info on this is highly appreciated, Pedro Borges @ Portugal
Replies: |
Sponsored Links
|