Hello Gael, > Are you completely sure of that ?
I've sent you the link to the JavaDocs. Are they in any way unclear? It's official Sun JavaDoc, not something I've made up on my home page. > I just tried this available() thing while > debugging after figuring out that no text seemed to be read. What I am > actually doing is feeding the input stream to an > InputFileReader/BufferedReader and parsing it in a while(reader.ready()) > loop. Is there something wrong with that then ? For heaven's sake, don't you read JavaDocs? http://java.sun.com/j2se/1.4.2/docs/api/java/io/Reader.html#ready() ready() tells you whether there is data available _without_blocking_! It does NOT tell you whether you're at the end of the stream. Specifications and JavaDocs are the reference for API behavior, not trial-and-error results with one or two sites and a debugger. > Note that available() does > return the size of the page when I am using Wikipedia's server. Well, than that page happens to be very small (<4k) and the Wikipedia server does not flush the output stream after the HTTP header and before the HTTP body. If the body happens to be transferred in the same IP packet as the end of the header, it is buffered locally on the client and will be detected by available() and ready(). If the body is transferred in a separate IP packet, or does not fit into a single packet, available() will NOT return how much data there is in the page, but only how much of that happens to be buffered on the client. Which might be 0. If you're reading from either an InputStream or a Reader, you read _blocking_ until the read(...) method you're using returns a negative value. THEN you're at the end of the stream. cheers, Roland > > Thank you for your help, > Gaƫl > > On 2/17/07, Roland Weber <[EMAIL PROTECTED]> wrote: >> >> Hello Gael, >> >> > The stream seems to be empty, >> > mystream.available() returns 0, but getResponseBodyAsString() does >> return >> > the content of the page. >> >> InputStream.available does NOT tell you how much bytes are in the stream. >> It tells you how much you can read _without_blocking_. If you call the >> read() method while available returns 0, it will simply block until some >> bytes become available or EOF is detected. >> >> >> http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStream.html#available() >> >> >> cheers, >> Roland >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
