public long waitAvailable(int requested,int waitMillis) throws IOException, InterruptedException {
  if (available >= requested)   return available;
  long timeoutMillis=System.currentTimeMillis() + waitMillis;
  long nextReportMillis=System.currentTimeMillis() + 1000;
  while (available() < requested && System.currentTimeMillis() < timeoutMillis) {
    if (Thread.interrupted())     throw new InterruptedException();
    Thread.sleep(50);
    if (System.currentTimeMillis() > nextReportMillis) {
      if (logger.isDebugEnabled())       logger.debug("Waited 1000ms for input to appear");
      nextReportMillis=System.currentTimeMillis() + 1000;
    }
  }
  return available;
}

public long waitAvailable ( int requested , int waitMillis ) throws IOException , InterruptedException { if ( available >= requested ) return available ; long timeoutMillis = System . currentTimeMillis ( ) + waitMillis ; long nextReportMillis = System . currentTimeMillis ( ) + 1000 ; while ( available ( ) < requested && System . currentTimeMillis ( ) < timeoutMillis ) { if ( Thread . interrupted ( ) ) throw new InterruptedException ( ) ; Thread . sleep ( 50 ) ; if ( System . currentTimeMillis ( ) > nextReportMillis ) { if ( logger . isDebugEnabled ( ) ) logger . debug ( "Waited 1000ms for input to appear" ) ; nextReportMillis = System . currentTimeMillis ( ) + 1000 ; } } return available ; }
waits for a specified number of bytes to be available for a non - blocking read .
