319 * <li> The <code>available</code> method of the underlying stream
320 * returns zero, indicating that further input requests would block.
321 *
322 * </ul> If the first <code>read</code> on the underlying stream returns
323 * <code>-1</code> to indicate end-of-file then this method returns
324 * <code>-1</code>. Otherwise this method returns the number of bytes
325 * actually read.
326 *
327 * <p> Subclasses of this class are encouraged, but not required, to
328 * attempt to read as many bytes as possible in the same fashion.
329 *
330 * @param b destination buffer.
331 * @param off offset at which to start storing bytes.
332 * @param len maximum number of bytes to read.
333 * @return the number of bytes read, or <code>-1</code> if the end of
334 * the stream has been reached.
335 * @exception IOException if this input stream has been closed by
336 * invoking its {@link #close()} method,
337 * or an I/O error occurs.
338 */
339 public synchronized int read(byte b[], int off, int len)
340 throws IOException
341 {
342 getBufIfOpen(); // Check for closed stream
343 if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
344 throw new IndexOutOfBoundsException();
345 } else if (len == 0) {
346 return 0;
347 }
348
349 int n = 0;
350 for (;;) {
351 int nread = read1(b, off + n, len - n);
352 if (nread <= 0)
353 return (n == 0) ? nread : n;
354 n += nread;
355 if (n >= len)
356 return n;
357 // if not closed but no bytes available, return
358 InputStream input = in;
359 if (input != null && input.available() <= 0)
|
319 * <li> The <code>available</code> method of the underlying stream
320 * returns zero, indicating that further input requests would block.
321 *
322 * </ul> If the first <code>read</code> on the underlying stream returns
323 * <code>-1</code> to indicate end-of-file then this method returns
324 * <code>-1</code>. Otherwise this method returns the number of bytes
325 * actually read.
326 *
327 * <p> Subclasses of this class are encouraged, but not required, to
328 * attempt to read as many bytes as possible in the same fashion.
329 *
330 * @param b destination buffer.
331 * @param off offset at which to start storing bytes.
332 * @param len maximum number of bytes to read.
333 * @return the number of bytes read, or <code>-1</code> if the end of
334 * the stream has been reached.
335 * @exception IOException if this input stream has been closed by
336 * invoking its {@link #close()} method,
337 * or an I/O error occurs.
338 */
339 public synchronized int read(byte[] b, int off, int len)
340 throws IOException
341 {
342 getBufIfOpen(); // Check for closed stream
343 if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
344 throw new IndexOutOfBoundsException();
345 } else if (len == 0) {
346 return 0;
347 }
348
349 int n = 0;
350 for (;;) {
351 int nread = read1(b, off + n, len - n);
352 if (nread <= 0)
353 return (n == 0) ? nread : n;
354 n += nread;
355 if (n >= len)
356 return n;
357 // if not closed but no bytes available, return
358 InputStream input = in;
359 if (input != null && input.available() <= 0)
|