-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sebastiaan,
Sebastiaan van Erk wrote: > I'm having a problem reading data in my Comet servlet. > > In the BEGIN event I have the following loop: > > while (request.getInputStream().available() > 0) { > // log that in read loop, log available() > // read some data > } > // log that read loop is done, log available() > return; Are you sure this is what you want to do? This loop is not guaranteed to read all of the incoming data. Check the javadoc for InputStream.available: http://java.sun.com/j2se/1.5.0/docs/api/java/io/InputStream.html#available(): "Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream." If there will be 100 bytes eventually, but only 50 are available now, you'll get 50 as the return value. If you read those bytes, but the rest are unavailable, then your second loop condition evaluation will return 0, and the loop will exit (with 50 bytes still on the way). > Does anybody know what the proper way to read ALL the data is, and not > cause this exception to happen? If you want to read /all/ data and not worry about blocking, you should be doing this: byte[] buffer = new byte[BUFFER_SIZE]; int read; while(0 < (read = request.getInputStream().read(buffer)) { // do something with 'read' bytes of data from the buffer } - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGgSMJ9CaO5/Lv0PARAss5AKC6FGl6VWseNj2cqJA4hE/R2HZSZQCfW/x1 1AzxGVpySeNpLNZalukYZx8= =jxPX -----END PGP SIGNATURE----- --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]