synchronized void receive(char[] chars,int offset,int count) throws IOException {
  Arrays.checkOffsetAndCount(chars.length,offset,count);
  if (buffer == null) {
    throw new IOException("Pipe is closed");
  }
  if (lastReader != null && !lastReader.isAlive()) {
    throw new IOException("Pipe broken");
  }
  lastWriter=Thread.currentThread();
  while (count > 0) {
    try {
      while (buffer != null && out == in) {
        notifyAll();
        wait(1000);
        if (lastReader != null && !lastReader.isAlive()) {
          throw new IOException("Pipe broken");
        }
      }
    }
 catch (    InterruptedException e) {
      IoUtils.throwInterruptedIoException();
    }
    if (buffer == null) {
      throw new IOException("Pipe is closed");
    }
    if (in == -1) {
      in=0;
    }
    if (in >= out) {
      int length=buffer.length - in;
      if (count < length) {
        length=count;
      }
      System.arraycopy(chars,offset,buffer,in,length);
      offset+=length;
      count-=length;
      in+=length;
      if (in == buffer.length) {
        in=0;
      }
    }
    if (count > 0 && in != out) {
      int length=out - in;
      if (count < length) {
        length=count;
      }
      System.arraycopy(chars,offset,buffer,in,length);
      offset+=length;
      count-=length;
      in+=length;
    }
  }
}

synchronized void receive ( char [ ] chars , int offset , int count ) throws IOException { Arrays . checkOffsetAndCount ( chars . length , offset , count ) ; if ( buffer == null ) { throw new IOException ( "Pipe is closed" ) ; } if ( lastReader != null && ! lastReader . isAlive ( ) ) { throw new IOException ( "Pipe broken" ) ; } lastWriter = Thread . currentThread ( ) ; while ( count > 0 ) { try { while ( buffer != null && out == in ) { notifyAll ( ) ; wait ( 1000 ) ; if ( lastReader != null && ! lastReader . isAlive ( ) ) { throw new IOException ( "Pipe broken" ) ; } } } catch ( InterruptedException e ) { IoUtils . throwInterruptedIoException ( ) ; } if ( buffer == null ) { throw new IOException ( "Pipe is closed" ) ; } if ( in == - 1 ) { in = 0 ; } if ( in >= out ) { int length = buffer . length - in ; if ( count < length ) { length = count ; } System . arraycopy ( chars , offset , buffer , in , length ) ; offset += length ; count -= length ; in += length ; if ( in == buffer . length ) { in = 0 ; } } if ( count > 0 && in != out ) { int length = out - in ; if ( count < length ) { length = count ; } System . arraycopy ( chars , offset , buffer , in , length ) ; offset += length ; count -= length ; in += length ; } } }
receives a char array and stores it into the pipedreader . this called by pipedwriter . write ( ) when writes occur . < p > if the buffer is full and the thread sending # receive is interrupted , the interruptedioexception will be thrown .
