public void run(){
  RandomAccessFile reader=null;
  try {
    long last=0;
    long position=0;
    while (run && reader == null) {
      try {
        reader=new RandomAccessFile(file,RAF_MODE);
      }
 catch (      FileNotFoundException e) {
        listener.fileNotFound();
      }
      if (reader == null) {
        try {
          Thread.sleep(delayMillis);
        }
 catch (        InterruptedException e) {
        }
      }
 else {
        position=end ? file.length() : 0;
        last=System.currentTimeMillis();
        reader.seek(position);
      }
    }
    while (run) {
      boolean newer=FileUtils.isFileNewer(file,last);
      long length=file.length();
      if (length < position) {
        listener.fileRotated();
        try {
          RandomAccessFile save=reader;
          reader=new RandomAccessFile(file,RAF_MODE);
          position=0;
          IOUtils.closeQuietly(save);
        }
 catch (        FileNotFoundException e) {
          listener.fileNotFound();
        }
        continue;
      }
 else {
        if (length > position) {
          position=readLines(reader);
          last=System.currentTimeMillis();
        }
 else         if (newer) {
          position=0;
          reader.seek(position);
          position=readLines(reader);
          last=System.currentTimeMillis();
        }
      }
      if (reOpen) {
        IOUtils.closeQuietly(reader);
      }
      try {
        Thread.sleep(delayMillis);
      }
 catch (      InterruptedException e) {
      }
      if (run && reOpen) {
        reader=new RandomAccessFile(file,RAF_MODE);
        reader.seek(position);
      }
    }
  }
 catch (  Exception e) {
    listener.handle(e);
  }
 finally {
    IOUtils.closeQuietly(reader);
  }
}

public void run ( ) { RandomAccessFile reader = null ; try { long last = 0 ; long position = 0 ; while ( run && reader == null ) { try { reader = new RandomAccessFile ( file , RAF_MODE ) ; } catch ( FileNotFoundException e ) { listener . fileNotFound ( ) ; } if ( reader == null ) { try { Thread . sleep ( delayMillis ) ; } catch ( InterruptedException e ) { } } else { position = end ? file . length ( ) : 0 ; last = System . currentTimeMillis ( ) ; reader . seek ( position ) ; } } while ( run ) { boolean newer = FileUtils . isFileNewer ( file , last ) ; long length = file . length ( ) ; if ( length < position ) { listener . fileRotated ( ) ; try { RandomAccessFile save = reader ; reader = new RandomAccessFile ( file , RAF_MODE ) ; position = 0 ; IOUtils . closeQuietly ( save ) ; } catch ( FileNotFoundException e ) { listener . fileNotFound ( ) ; } continue ; } else { if ( length > position ) { position = readLines ( reader ) ; last = System . currentTimeMillis ( ) ; } else if ( newer ) { position = 0 ; reader . seek ( position ) ; position = readLines ( reader ) ; last = System . currentTimeMillis ( ) ; } } if ( reOpen ) { IOUtils . closeQuietly ( reader ) ; } try { Thread . sleep ( delayMillis ) ; } catch ( InterruptedException e ) { } if ( run && reOpen ) { reader = new RandomAccessFile ( file , RAF_MODE ) ; reader . seek ( position ) ; } } } catch ( Exception e ) { listener . handle ( e ) ; } finally { IOUtils . closeQuietly ( reader ) ; } }
follows changes in the file , calling the tailerlistener ' s handle method for each new line .
