8182684: Further clarify InputStream#available()

Reviewed-by: alanb, rriggs
This commit is contained in:
Brian Burkhalter 2018-03-13 12:24:39 -07:00
parent ae966db198
commit 516fa74ca5

View file

@ -539,29 +539,29 @@ public abstract class InputStream implements Closeable {
} }
/** /**
* Returns an estimate of the number of bytes that can be read (or * Returns an estimate of the number of bytes that can be read (or skipped
* skipped over) from this input stream without blocking by the next * over) from this input stream without blocking, which may be 0, or 0 when
* invocation of a method for this input stream. The next invocation * end of stream is detected. The read might be on the same thread or
* might be the same thread or another thread. A single read or skip of this * another thread. A single read or skip of this many bytes will not block,
* many bytes will not block, but may read or skip fewer bytes. * but may read or skip fewer bytes.
* *
* <p> Note that while some implementations of {@code InputStream} will return * <p> Note that while some implementations of {@code InputStream} will
* the total number of bytes in the stream, many will not. It is * 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 * never correct to use the return value of this method to allocate
* a buffer intended to hold all data in this stream. * a buffer intended to hold all data in this stream.
* *
* <p> A subclass' implementation of this method may choose to throw an * <p> A subclass's implementation of this method may choose to throw an
* {@link IOException} if this input stream has been closed by * {@link IOException} if this input stream has been closed by invoking the
* invoking the {@link #close()} method. * {@link #close()} method.
* *
* <p> The {@code available} method for class {@code InputStream} always * <p> The {@code available} method of {@code InputStream} always returns
* returns {@code 0}. * {@code 0}.
* *
* <p> This method should be overridden by subclasses. * <p> This method should be overridden by subclasses.
* *
* @return an estimate of the number of bytes that can be read (or skipped * @return an estimate of the number of bytes that can be read (or
* over) from this input stream without blocking or {@code 0} when * skipped over) from this input stream without blocking or
* it reaches the end of the input stream. * {@code 0} when it reaches the end of the input stream.
* @exception IOException if an I/O error occurs. * @exception IOException if an I/O error occurs.
*/ */
public int available() throws IOException { public int available() throws IOException {