private static void readDataFromBinlog(ReplicatorRuntime runtime,BinlogReader binlog,byte[] data,int offset,int length,int timeout) throws IOException, ReplicatorException, InterruptedException {
  boolean alreadyLogged=false;
  int spentTime=0;
  int timeoutInMs=timeout * 1000;
  long available;
  while ((available=binlog.available()) < (long)length) {
    if (!alreadyLogged) {
      if (logger.isDebugEnabled()) {
        logger.debug("Trying to read more bytes (" + length + ") than available in the file ("+ available+ " in "+ binlog.getFileName()+ ")... waiting for data to be available");
      }
      alreadyLogged=true;
    }
    try {
      if (spentTime < timeoutInMs) {
        Thread.sleep(1);
        spentTime++;
      }
 else       throw new MySQLExtractException("Timeout while waiting for data : spent more than " + timeout + " seconds while waiting for "+ length+ " bytes to be available");
    }
 catch (    InterruptedException e) {
    }
  }
  binlog.read(data,offset,length);
}

private static void readDataFromBinlog ( ReplicatorRuntime runtime , BinlogReader binlog , byte [ ] data , int offset , int length , int timeout ) throws IOException , ReplicatorException , InterruptedException { boolean alreadyLogged = false ; int spentTime = 0 ; int timeoutInMs = timeout * 1000 ; long available ; while ( ( available = binlog . available ( ) ) < ( long ) length ) { if ( ! alreadyLogged ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Trying to read more bytes (" + length + ") than available in the file (" + available + " in " + binlog . getFileName ( ) + ")... waiting for data to be available" ) ; } alreadyLogged = true ; } try { if ( spentTime < timeoutInMs ) { Thread . sleep ( 1 ) ; spentTime ++ ; } else throw new MySQLExtractException ( "Timeout while waiting for data : spent more than " + timeout + " seconds while waiting for " + length + " bytes to be available" ) ; } catch ( InterruptedException e ) { } } binlog . read ( data , offset , length ) ; }
readdatafrombinlog waits for data to be fully written in the binlog file and then reads it .
