src/share/classes/java/io/InputStream.java

Print this page




  73      *
  74      * <p> If the length of <code>b</code> is zero, then no bytes are read and
  75      * <code>0</code> is returned; otherwise, there is an attempt to read at
  76      * least one byte. If no byte is available because the stream is at the
  77      * end of the file, the value <code>-1</code> is returned; otherwise, at
  78      * least one byte is read and stored into <code>b</code>.
  79      *
  80      * <p> The first byte read is stored into element <code>b[0]</code>, the
  81      * next one into <code>b[1]</code>, and so on. The number of bytes read is,
  82      * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
  83      * number of bytes actually read; these bytes will be stored in elements
  84      * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
  85      * leaving elements <code>b[</code><i>k</i><code>]</code> through
  86      * <code>b[b.length-1]</code> unaffected.
  87      *
  88      * <p> The <code>read(b)</code> method for class <code>InputStream</code>
  89      * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
  90      *
  91      * @param      b   the buffer into which the data is read.
  92      * @return     the total number of bytes read into the buffer, or
  93      *             <code>-1</code> is there is no more data because the end of
  94      *             the stream has been reached.
  95      * @exception  IOException  If the first byte cannot be read for any reason
  96      * other than the end of the file, if the input stream has been closed, or
  97      * if some other I/O error occurs.
  98      * @exception  NullPointerException  if <code>b</code> is <code>null</code>.
  99      * @see        java.io.InputStream#read(byte[], int, int)
 100      */
 101     public int read(byte b[]) throws IOException {
 102         return read(b, 0, b.length);
 103     }
 104 
 105     /**
 106      * Reads up to <code>len</code> bytes of data from the input stream into
 107      * an array of bytes.  An attempt is made to read as many as
 108      * <code>len</code> bytes, but a smaller number may be read.
 109      * The number of bytes actually read is returned as an integer.
 110      *
 111      * <p> This method blocks until input data is available, end of file is
 112      * detected, or an exception is thrown.
 113      *




  73      *
  74      * <p> If the length of <code>b</code> is zero, then no bytes are read and
  75      * <code>0</code> is returned; otherwise, there is an attempt to read at
  76      * least one byte. If no byte is available because the stream is at the
  77      * end of the file, the value <code>-1</code> is returned; otherwise, at
  78      * least one byte is read and stored into <code>b</code>.
  79      *
  80      * <p> The first byte read is stored into element <code>b[0]</code>, the
  81      * next one into <code>b[1]</code>, and so on. The number of bytes read is,
  82      * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
  83      * number of bytes actually read; these bytes will be stored in elements
  84      * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
  85      * leaving elements <code>b[</code><i>k</i><code>]</code> through
  86      * <code>b[b.length-1]</code> unaffected.
  87      *
  88      * <p> The <code>read(b)</code> method for class <code>InputStream</code>
  89      * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
  90      *
  91      * @param      b   the buffer into which the data is read.
  92      * @return     the total number of bytes read into the buffer, or
  93      *             <code>-1</code> if there is no more data because the end of
  94      *             the stream has been reached.
  95      * @exception  IOException  If the first byte cannot be read for any reason
  96      * other than the end of the file, if the input stream has been closed, or
  97      * if some other I/O error occurs.
  98      * @exception  NullPointerException  if <code>b</code> is <code>null</code>.
  99      * @see        java.io.InputStream#read(byte[], int, int)
 100      */
 101     public int read(byte b[]) throws IOException {
 102         return read(b, 0, b.length);
 103     }
 104 
 105     /**
 106      * Reads up to <code>len</code> bytes of data from the input stream into
 107      * an array of bytes.  An attempt is made to read as many as
 108      * <code>len</code> bytes, but a smaller number may be read.
 109      * The number of bytes actually read is returned as an integer.
 110      *
 111      * <p> This method blocks until input data is available, end of file is
 112      * detected, or an exception is thrown.
 113      *