Is available()
reliable for use in socket programming in Java?
I just care that it tells me when there are bytes available for reading so that when I call read methods they don't block.
BufferedInputStream.available()
relies on InputStream.available()
.
The documentation for InputStream.available() says this:
Note that while some implementations of InputStream will return the total number of bytes in the stream, many will not. It is never correct to use the return value of this method to allocate a buffer intended to hold all data in this stream. http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#available()
I don't care if it gives the correct number of bytes or not, just that it doesn't give me 0 when there are bytes available for reading. I want to know if BufferedInputStream.available() always works for this purpose on Windows and Linux.
Also, I'm not sure what the documentation means by "implementations". What does that refer to? To subclasses of InputStream? To Java on different operating systems? To different JVMs?
Has anybody used available() on Windows or Linux or other system and it didn't work?