code: public synchronized int read(char cbuf[], int off, int len)  throws IOException {
          if (!connected) {
              throw new IOException("Pipe not connected");
          } else if (closedByReader) {
              throw new IOException("Pipe closed");
          } else if (writeSide != null && !writeSide.isAlive()
                     && !closedByWriter && (in < 0)) {
              throw new IOException("Write end dead");
          }
  
          if ((off < 0) || (off > cbuf.length) || (len < 0) ||
              ((off + len) > cbuf.length) || ((off + len) < 0)) {
              throw new IndexOutOfBoundsException();
          } else if (len == 0) {
              return 0;
          }
  
          /* possibly wait on the first character */
          int c = read();
          if (c < 0) {
              return -1;
          }
          cbuf[off] =  (char)c;
          int rlen = 1;
          while ((in >= 0) && (--len > 0)) {
              cbuf[off + rlen] = buffer[out++];
              rlen++;
              if (out >= buffer.length) {
                  out = 0;
              }
              if (in == out) {
                  /* now empty */
                  in = -1;
              }
          }
          return rlen;
      }
docs: Reads up to <code>len</code> characters of data from this piped
  stream into an array of characters. Less than <code>len</code> characters
  will be read if the end of the data stream is reached or if
  <code>len</code> exceeds the pipe's buffer size. This method
  blocks until at least one character of input is available.
  
  @param      cbuf     the buffer into which the data is read.
  @param      off   the start offset of the data.
  @param      len   the maximum number of characters read.
  @return     the total number of characters read into the buffer, or
  <code>-1</code> if there is no more data because the end of
  the stream has been reached.
  @exception  IOException  if the pipe is
  <a href=PipedInputStream.html#BROKEN> <code>broken</code></a>,
  {@link #connect(java.io.PipedWriter) unconnected}, closed,
  or an I/O error occurs.