private boolean doesFileMatchBytes(final File file,final byte[] bytes) throws IOException {
  final String absolutePath=file.getAbsolutePath();
  boolean keepTrying=true;
  final boolean isDebugEnabled=logger.isDebugEnabled();
  while (file.length() < bytes.length && keepTrying) {
    if (isDebugEnabled) {
      logger.debug("Loop waiting for another to write file: {}",absolutePath);
    }
    long startingFileLength=file.length();
    try {
      Thread.sleep(500);
    }
 catch (    InterruptedException iex) {
    }
    if (startingFileLength == file.length()) {
      if (isDebugEnabled) {
        logger.debug("Done waiting for another to write file: {}",absolutePath);
      }
      keepTrying=false;
    }
  }
  if (file.length() != bytes.length) {
    if (isDebugEnabled) {
      logger.debug("Unmatching file length when waiting for another to write file: {}",absolutePath);
    }
    return false;
  }
  BufferedInputStream inStream=new BufferedInputStream(new FileInputStream(file));
  int index=0;
  try {
    for (; index < bytes.length; index++) {
      if (((byte)inStream.read()) != bytes[index]) {
        if (isDebugEnabled) {
          logger.debug("Did not find a match when waiting for another to write file: {}",absolutePath);
        }
        return false;
      }
    }
  }
  finally {
    inStream.close();
  }
  return true;
}

private boolean doesFileMatchBytes ( final File file , final byte [ ] bytes ) throws IOException { final String absolutePath = file . getAbsolutePath ( ) ; boolean keepTrying = true ; final boolean isDebugEnabled = logger . isDebugEnabled ( ) ; while ( file . length ( ) < bytes . length && keepTrying ) { if ( isDebugEnabled ) { logger . debug ( "Loop waiting for another to write file: {}" , absolutePath ) ; } long startingFileLength = file . length ( ) ; try { Thread . sleep ( 500 ) ; } catch ( InterruptedException iex ) { } if ( startingFileLength == file . length ( ) ) { if ( isDebugEnabled ) { logger . debug ( "Done waiting for another to write file: {}" , absolutePath ) ; } keepTrying = false ; } } if ( file . length ( ) != bytes . length ) { if ( isDebugEnabled ) { logger . debug ( "Unmatching file length when waiting for another to write file: {}" , absolutePath ) ; } return false ; } BufferedInputStream inStream = new BufferedInputStream ( new FileInputStream ( file ) ) ; int index = 0 ; try { for ( ; index < bytes . length ; index ++ ) { if ( ( ( byte ) inStream . read ( ) ) != bytes [ index ] ) { if ( isDebugEnabled ) { logger . debug ( "Did not find a match when waiting for another to write file: {}" , absolutePath ) ; } return false ; } } } finally { inStream . close ( ) ; } return true ; }
determine if the contents of the file referenced is an exact match for the bytes provided . the method first checks to see if the file is actively being written by checking the length over time . if it appears that the file is actively being written , then it loops waiting for that to complete before doing the comparison .
