public String tailFile(File file,boolean problemsOnly) throws IOException {
  byte buffer[]=new byte[128000];
  int readSize=buffer.length;
  RandomAccessFile f=new RandomAccessFile(file,"r");
  long length=f.length();
  if (length < readSize) {
    readSize=(int)length;
  }
  long seekOffset=length - readSize;
  f.seek(seekOffset);
  if (readSize != f.read(buffer,0,readSize)) {
    throw new EOFException("Failed to read " + readSize + " bytes from "+ file.getAbsolutePath());
  }
  f.close();
  int msgStart=-1;
  int msgEnd=readSize;
  for (int i=readSize - 1; i >= 0; i--) {
    if (buffer[i] == '[' && (buffer[i + 1] == 's' || buffer[i + 1] == 'e' || buffer[i + 1] == 'w') && i > 0 && (buffer[i - 1] == '\n' || buffer[i - 1] == '\r')) {
      msgStart=i;
      break;
    }
  }
  if (msgStart == -1) {
    if (problemsOnly) {
      return null;
    }
    for (int i=readSize - 3; i >= 0; i--) {
      if (buffer[i] == '\n' || buffer[i] == '\r') {
        msgStart=(buffer[i] == '\n') ? (i + 1) : (i + 2);
        break;
      }
    }
    if (msgStart == -1) {
      msgStart=0;
    }
  }
 else {
    for (int i=msgStart + 1; i < readSize; i++) {
      if (buffer[i] == '[' && (buffer[i - 1] == '\n' || buffer[i - 1] == '\r')) {
        msgEnd=i;
        break;
      }
    }
  }
  for (int i=msgStart; i < msgEnd; i++) {
    if (buffer[i] == '\n' || buffer[i] == '\r') {
      buffer[i]=' ';
    }
  }
  return new String(buffer,msgStart,msgEnd - msgStart);
}

public String tailFile ( File file , boolean problemsOnly ) throws IOException { byte buffer [ ] = new byte [ 128000 ] ; int readSize = buffer . length ; RandomAccessFile f = new RandomAccessFile ( file , "r" ) ; long length = f . length ( ) ; if ( length < readSize ) { readSize = ( int ) length ; } long seekOffset = length - readSize ; f . seek ( seekOffset ) ; if ( readSize != f . read ( buffer , 0 , readSize ) ) { throw new EOFException ( "Failed to read " + readSize + " bytes from " + file . getAbsolutePath ( ) ) ; } f . close ( ) ; int msgStart = - 1 ; int msgEnd = readSize ; for ( int i = readSize - 1 ; i >= 0 ; i -- ) { if ( buffer [ i ] == '[' && ( buffer [ i + 1 ] == 's' || buffer [ i + 1 ] == 'e' || buffer [ i + 1 ] == 'w' ) && i > 0 && ( buffer [ i - 1 ] == '\n' || buffer [ i - 1 ] == '\r' ) ) { msgStart = i ; break ; } } if ( msgStart == - 1 ) { if ( problemsOnly ) { return null ; } for ( int i = readSize - 3 ; i >= 0 ; i -- ) { if ( buffer [ i ] == '\n' || buffer [ i ] == '\r' ) { msgStart = ( buffer [ i ] == '\n' ) ? ( i + 1 ) : ( i + 2 ) ; break ; } } if ( msgStart == - 1 ) { msgStart = 0 ; } } else { for ( int i = msgStart + 1 ; i < readSize ; i ++ ) { if ( buffer [ i ] == '[' && ( buffer [ i - 1 ] == '\n' || buffer [ i - 1 ] == '\r' ) ) { msgEnd = i ; break ; } } } for ( int i = msgStart ; i < msgEnd ; i ++ ) { if ( buffer [ i ] == '\n' || buffer [ i ] == '\r' ) { buffer [ i ] = ' ' ; } } return new String ( buffer , msgStart , msgEnd - msgStart ) ; }
returns the contents located at the end of the file as a string .
