@Override public int read(byte[] buffer,int offset,int length) throws IOException {
  long start=System.currentTimeMillis();
  int read;
  while (true) {
    logger.log(Level.FINER,"Read Recv");
    try {
      read=pseudoTcp.recv(buffer,offset,length);
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"Read Recv read count: " + read);
      }
      if (read > 0) {
        return read;
      }
      logger.log(Level.FINER,"Read wait for data available");
      if (readTimeout > 0) {
        long elapsed=System.currentTimeMillis() - start;
        long left=readTimeout - elapsed;
        if (left <= 0) {
          IOException exc=new IOException("Read operation timeout");
          pseudoTcp.closedown(exc);
          throw exc;
        }
synchronized (read_notify) {
          if (pseudoTcp.getAvailable() == 0) {
            read_notify.wait(left);
          }
        }
      }
 else {
synchronized (read_notify) {
          if (pseudoTcp.getAvailable() == 0) {
            read_notify.wait();
          }
        }
      }
      if (logger.isLoggable(Level.FINER)) {
        logger.log(Level.FINER,"Read notified: " + pseudoTcp.getAvailable());
      }
      if (exception != null) {
        throw exception;
      }
    }
 catch (    InterruptedException ex) {
      if (exception != null) {
        throw new IOException("Read aborted",exception);
      }
 else {
        throw new IOException("Read aborted");
      }
    }
  }
}

@ Override public int read ( byte [ ] buffer , int offset , int length ) throws IOException { long start = System . currentTimeMillis ( ) ; int read ; while ( true ) { logger . log ( Level . FINER , "Read Recv" ) ; try { read = pseudoTcp . recv ( buffer , offset , length ) ; if ( logger . isLoggable ( Level . FINER ) ) { logger . log ( Level . FINER , "Read Recv read count: " + read ) ; } if ( read > 0 ) { return read ; } logger . log ( Level . FINER , "Read wait for data available" ) ; if ( readTimeout > 0 ) { long elapsed = System . currentTimeMillis ( ) - start ; long left = readTimeout - elapsed ; if ( left <= 0 ) { IOException exc = new IOException ( "Read operation timeout" ) ; pseudoTcp . closedown ( exc ) ; throw exc ; } synchronized ( read_notify ) { if ( pseudoTcp . getAvailable ( ) == 0 ) { read_notify . wait ( left ) ; } } } else { synchronized ( read_notify ) { if ( pseudoTcp . getAvailable ( ) == 0 ) { read_notify . wait ( ) ; } } } if ( logger . isLoggable ( Level . FINER ) ) { logger . log ( Level . FINER , "Read notified: " + pseudoTcp . getAvailable ( ) ) ; } if ( exception != null ) { throw exception ; } } catch ( InterruptedException ex ) { if ( exception != null ) { throw new IOException ( "Read aborted" , exception ) ; } else { throw new IOException ( "Read aborted" ) ; } } } }
this method blocks until any data is available
