org.apache.commons.io.input.TailerListenerAdapter Java Examples

The following examples show how to use org.apache.commons.io.input.TailerListenerAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogsCommand.java    From konduit-serving with Apache License 2.0 6 votes vote down vote up
private void readAndTail(File logsFile, int fromNumberOfLines) throws IOException {
    new Tailer(logsFile, StandardCharsets.UTF_8, new TailerListenerAdapter() {
        @SneakyThrows
        @Override
        public void init(Tailer tailer) {
            super.init(tailer);
            if(fromNumberOfLines != -1) {
                out.println(LauncherUtils.readLastLines(logsFile, fromNumberOfLines));
            }
        }

        @Override
        public void handle(String line) {
            out.println(line);
        }

        @Override
        public void handle(Exception ex) {
            ex.printStackTrace();
            System.exit(1);
        }
    }, 100, fromNumberOfLines != -1, false, 4096).run();
}
 
Example #2
Source File: TailingVerifier.java    From app-maven-plugin with Apache License 2.0 6 votes vote down vote up
private void startTailingLog() {
  TailerListener listener =
      new TailerListenerAdapter() {
        @Override
        public void handle(String line) {
          System.out.println(testName + ": " + line);
        }
      };

  // Tail the log
  File file = new File(getBasedir() + File.separator + getLogFileName());
  try {
    if (file.exists()) {
      file.delete();
    }
    file.createNewFile();
  } catch (IOException e) {
    e.printStackTrace();
  }
  Tailer tailer = new Tailer(file, listener, TAIL_DELAY_MILLIS);
  Thread thread = new Thread(tailer);
  thread.setDaemon(true);
  thread.start();
}
 
Example #3
Source File: FileTailer.java    From websockets-log-tail with Apache License 2.0 6 votes vote down vote up
private TailerListenerAdapter createListener(final ObservableEmitter<String> emitter) {
    return new TailerListenerAdapter() {

        @Override
        public void fileRotated() {
            // ignore, just keep tailing
        }

        @Override
        public void handle(String line) {
            emitter.onNext(line);
        }

        @Override
        public void fileNotFound() {
            emitter.onError(new FileNotFoundException(file.toString()));
        }

        @Override
        public void handle(Exception ex) {
            emitter.onError(ex);
        }
    };
}
 
Example #4
Source File: PipeTailer.java    From bidder with Apache License 2.0 5 votes vote down vote up
/**
 * Create a named pipe subscriber
 * @param handler TailerListenerAdaptor. The parent, the thing that consumes the message.
 * @param fileName String. The name of the pipe.
 * @throws Exception if the file does not exist or what is named is not a file.
 */
public PipeTailer(TailerListenerAdapter handler, String fileName) throws Exception {
    this.handler = handler;
    this.fileName = fileName;
    File f_pipe = new File(fileName);
    if (!f_pipe.exists())
        throw new Exception("Named pipe: " + fileName + " does not exist");
    if (!f_pipe.isFile()==false)
        throw new Exception(fileName + " is not a pipee");
    me = new Thread(this);
    me.start();

}