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

Print this page




 269         return ret;
 270     }
 271 
 272     /**
 273      * Reads up to <code>len</code> characters of data from this piped
 274      * stream into an array of characters. Less than <code>len</code> characters
 275      * will be read if the end of the data stream is reached or if
 276      * <code>len</code> exceeds the pipe's buffer size. This method
 277      * blocks until at least one character of input is available.
 278      *
 279      * @param      cbuf     the buffer into which the data is read.
 280      * @param      off   the start offset of the data.
 281      * @param      len   the maximum number of characters read.
 282      * @return     the total number of characters read into the buffer, or
 283      *             <code>-1</code> if there is no more data because the end of
 284      *             the stream has been reached.
 285      * @exception  IOException  if the pipe is
 286      *                  <a href=PipedInputStream.html#BROKEN> <code>broken</code></a>,
 287      *                  {@link #connect(java.io.PipedWriter) unconnected}, closed,
 288      *                  or an I/O error occurs.

 289      */
 290     public synchronized int read(char cbuf[], int off, int len)  throws IOException {
 291         if (!connected) {
 292             throw new IOException("Pipe not connected");
 293         } else if (closedByReader) {
 294             throw new IOException("Pipe closed");
 295         } else if (writeSide != null && !writeSide.isAlive()
 296                    && !closedByWriter && (in < 0)) {
 297             throw new IOException("Write end dead");
 298         }
 299 
 300         if ((off < 0) || (off > cbuf.length) || (len < 0) ||
 301             ((off + len) > cbuf.length) || ((off + len) < 0)) {
 302             throw new IndexOutOfBoundsException();
 303         } else if (len == 0) {
 304             return 0;
 305         }
 306 
 307         /* possibly wait on the first character */
 308         int c = read();




 269         return ret;
 270     }
 271 
 272     /**
 273      * Reads up to <code>len</code> characters of data from this piped
 274      * stream into an array of characters. Less than <code>len</code> characters
 275      * will be read if the end of the data stream is reached or if
 276      * <code>len</code> exceeds the pipe's buffer size. This method
 277      * blocks until at least one character of input is available.
 278      *
 279      * @param      cbuf     the buffer into which the data is read.
 280      * @param      off   the start offset of the data.
 281      * @param      len   the maximum number of characters read.
 282      * @return     the total number of characters read into the buffer, or
 283      *             <code>-1</code> if there is no more data because the end of
 284      *             the stream has been reached.
 285      * @exception  IOException  if the pipe is
 286      *                  <a href=PipedInputStream.html#BROKEN> <code>broken</code></a>,
 287      *                  {@link #connect(java.io.PipedWriter) unconnected}, closed,
 288      *                  or an I/O error occurs.
 289      * @exception  IndexOutOfBoundsException {@inheritDoc}
 290      */
 291     public synchronized int read(char cbuf[], int off, int len)  throws IOException {
 292         if (!connected) {
 293             throw new IOException("Pipe not connected");
 294         } else if (closedByReader) {
 295             throw new IOException("Pipe closed");
 296         } else if (writeSide != null && !writeSide.isAlive()
 297                    && !closedByWriter && (in < 0)) {
 298             throw new IOException("Write end dead");
 299         }
 300 
 301         if ((off < 0) || (off > cbuf.length) || (len < 0) ||
 302             ((off + len) > cbuf.length) || ((off + len) < 0)) {
 303             throw new IndexOutOfBoundsException();
 304         } else if (len == 0) {
 305             return 0;
 306         }
 307 
 308         /* possibly wait on the first character */
 309         int c = read();