What's the Importance of the avaliable() method in InputStream? Why
would i use it?
Not very important. You probably wouldn't want to use it. If you don't
understand well exactly what it does (and doesn't) do and when and why
you might want that, then save yourself grief and pretend that the
method doesn't exist. It is rarely used by people who do know and
understand all that.
And what does available()'s method description in inputstream's javadoc
mean?: "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."
It means that the next read on the input stream will retrieve at least
that number of bytes, provided that that number or more are requested.
Furthermore, the read will not block if the number of bytes returned by
available() is greater than zero. Note, however, that by the time the
read is actually performed, there may be more bytes available, so a
return value of zero doesn't necessarily mean that the next read will
block. Note also that available() will, perforce, return zero when the
end of the stream has been detected, and that a read on the stream will
not block in that case, either. A common mistake is to assume that
available() returning zero is a definite signal of end-of-stream; that
assumption is false.
Contrary to ozgwei's comments, available is for more than just
BufferedInputStream, but he is right about how BufferedInputStream
implements the method. Note that java.io.InputStream itself is abstract.