jdk/src/share/classes/java/io/SequenceInputStream.java
changeset 23344 70f819173479
parent 14342 8435a30053c1
child 24865 09b1d992ca72
equal deleted inserted replaced
23343:bc82981ff581 23344:70f819173479
   133      * @exception  IOException  if an I/O error occurs.
   133      * @exception  IOException  if an I/O error occurs.
   134      *
   134      *
   135      * @since   JDK1.1
   135      * @since   JDK1.1
   136      */
   136      */
   137     public int available() throws IOException {
   137     public int available() throws IOException {
   138         if(in == null) {
   138         if (in == null) {
   139             return 0; // no way to signal EOF from available()
   139             return 0; // no way to signal EOF from available()
   140         }
   140         }
   141         return in.available();
   141         return in.available();
   142     }
   142     }
   143 
   143 
   158      * @return     the next byte of data, or <code>-1</code> if the end of the
   158      * @return     the next byte of data, or <code>-1</code> if the end of the
   159      *             stream is reached.
   159      *             stream is reached.
   160      * @exception  IOException  if an I/O error occurs.
   160      * @exception  IOException  if an I/O error occurs.
   161      */
   161      */
   162     public int read() throws IOException {
   162     public int read() throws IOException {
   163         if (in == null) {
   163         while (in != null) {
   164             return -1;
   164             int c = in.read();
   165         }
   165             if (c != -1) {
   166         int c = in.read();
   166                 return c;
   167         if (c == -1) {
   167             }
   168             nextStream();
   168             nextStream();
   169             return read();
   169         }
   170         }
   170         return -1;
   171         return c;
       
   172     }
   171     }
   173 
   172 
   174     /**
   173     /**
   175      * Reads up to <code>len</code> bytes of data from this input stream
   174      * Reads up to <code>len</code> bytes of data from this input stream
   176      * into an array of bytes.  If <code>len</code> is not zero, the method
   175      * into an array of bytes.  If <code>len</code> is not zero, the method
   202         } else if (off < 0 || len < 0 || len > b.length - off) {
   201         } else if (off < 0 || len < 0 || len > b.length - off) {
   203             throw new IndexOutOfBoundsException();
   202             throw new IndexOutOfBoundsException();
   204         } else if (len == 0) {
   203         } else if (len == 0) {
   205             return 0;
   204             return 0;
   206         }
   205         }
   207 
   206         do {
   208         int n = in.read(b, off, len);
   207             int n = in.read(b, off, len);
   209         if (n <= 0) {
   208             if (n > 0) {
   210             nextStream();
   209                 return n;
   211             return read(b, off, len);
   210             }
   212         }
   211             nextStream();
   213         return n;
   212         } while (in != null);
       
   213         return -1;
   214     }
   214     }
   215 
   215 
   216     /**
   216     /**
   217      * Closes this input stream and releases any system resources
   217      * Closes this input stream and releases any system resources
   218      * associated with the stream.
   218      * associated with the stream.