Example usage for org.apache.commons.io.input Tailer create

List of usage examples for org.apache.commons.io.input Tailer create

Introduction

In this page you can find the example usage for org.apache.commons.io.input Tailer create.

Prototype

public static Tailer create(File file, TailerListener listener, long delay, boolean end) 

Source Link

Document

Creates and starts a Tailer for the given file.

Usage

From source file:org.ngrinder.operation.cotroller.LogMonitorController.java

/**
 * Initialize the {@link Tailer}./* w  ww .  j  a  v a2 s. c o m*/
 */
private synchronized void initTailer() {
    File logFile = getLogFile();
    if (tailer != null) {
        tailer.stop();
    }
    tailer = Tailer.create(logFile, new TailerListenerAdapter() {
        /**
         * Handles a line from a Tailer.
         *
         * @param line
         *            the line.
         */
        public void handle(String line) {
            synchronized (this) {
                if (stringBuffer.length() + line.length() > 5000) {
                    count++;
                    modification = 0;
                    stringBuffer = new StringBuffer();
                }
                modification++;
                if (stringBuffer.length() > 0) {
                    stringBuffer.append("<br>");
                }
                stringBuffer.append(line.replace("\n", "<br>"));
            }
        }
    }, 1000, true);
}