< prev index next >

src/java.base/share/classes/java/io/SequenceInputStream.java

Print this page




 168      * blocks until at least 1 byte of input is available; otherwise, no
 169      * bytes are read and <code>0</code> is returned.
 170      * <p>
 171      * The <code>read</code> method of <code>SequenceInputStream</code>
 172      * tries to read the data from the current substream. If it fails to
 173      * read any characters because the substream has reached the end of
 174      * the stream, it calls the <code>close</code> method of the current
 175      * substream and begins reading from the next substream.
 176      *
 177      * @param      b     the buffer into which the data is read.
 178      * @param      off   the start offset in array <code>b</code>
 179      *                   at which the data is written.
 180      * @param      len   the maximum number of bytes read.
 181      * @return     int   the number of bytes read.
 182      * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 183      * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 184      * <code>len</code> is negative, or <code>len</code> is greater than
 185      * <code>b.length - off</code>
 186      * @exception  IOException  if an I/O error occurs.
 187      */
 188     public int read(byte b[], int off, int len) throws IOException {
 189         if (in == null) {
 190             return -1;
 191         } else if (b == null) {
 192             throw new NullPointerException();
 193         } else if (off < 0 || len < 0 || len > b.length - off) {
 194             throw new IndexOutOfBoundsException();
 195         } else if (len == 0) {
 196             return 0;
 197         }
 198         do {
 199             int n = in.read(b, off, len);
 200             if (n > 0) {
 201                 return n;
 202             }
 203             nextStream();
 204         } while (in != null);
 205         return -1;
 206     }
 207 
 208     /**


 168      * blocks until at least 1 byte of input is available; otherwise, no
 169      * bytes are read and <code>0</code> is returned.
 170      * <p>
 171      * The <code>read</code> method of <code>SequenceInputStream</code>
 172      * tries to read the data from the current substream. If it fails to
 173      * read any characters because the substream has reached the end of
 174      * the stream, it calls the <code>close</code> method of the current
 175      * substream and begins reading from the next substream.
 176      *
 177      * @param      b     the buffer into which the data is read.
 178      * @param      off   the start offset in array <code>b</code>
 179      *                   at which the data is written.
 180      * @param      len   the maximum number of bytes read.
 181      * @return     int   the number of bytes read.
 182      * @exception  NullPointerException If <code>b</code> is <code>null</code>.
 183      * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
 184      * <code>len</code> is negative, or <code>len</code> is greater than
 185      * <code>b.length - off</code>
 186      * @exception  IOException  if an I/O error occurs.
 187      */
 188     public int read(byte[] b, int off, int len) throws IOException {
 189         if (in == null) {
 190             return -1;
 191         } else if (b == null) {
 192             throw new NullPointerException();
 193         } else if (off < 0 || len < 0 || len > b.length - off) {
 194             throw new IndexOutOfBoundsException();
 195         } else if (len == 0) {
 196             return 0;
 197         }
 198         do {
 199             int n = in.read(b, off, len);
 200             if (n > 0) {
 201                 return n;
 202             }
 203             nextStream();
 204         } while (in != null);
 205         return -1;
 206     }
 207 
 208     /**
< prev index next >