本文整理汇总了Java中org.apache.commons.io.input.TailerListener类的典型用法代码示例。如果您正苦于以下问题:Java TailerListener类的具体用法?Java TailerListener怎么用?Java TailerListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TailerListener类属于org.apache.commons.io.input包,在下文中一共展示了TailerListener类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startTailingLog
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
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();
}
示例2: createListener
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
private TailerListener createListener() {
return new TailerListenerAdapter() {
@Override
public void fileRotated() {
// ignore, just keep tailing
}
@Override
public void handle(String line) {
session.getAsyncRemote().sendText(line);
}
@Override
public void fileNotFound() {
session.getAsyncRemote().sendText(new FileNotFoundException(logFile.toString()).toString());
}
@Override
public void handle(Exception ex) {
session.getAsyncRemote().sendText(ex.toString());
}
};
}
示例3: CsvStreamReader
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
/**
* Creates a CsvStreamReader with supplied separator and quote char.
*
* @param source The file to an underlying CSV source
* @param separator The delimiter to use for separating entries
* @param quoteChar The character to use for quoted elements
* @param escape The character to use for escaping a separator or quote
* @param line The line number to skip for start reading
* @param strictQuotes Sets if characters outside the quotes are ignored
* @param ignoreLeadingWhiteSpace If true, parser should ignore
* white space before a quote in a field
*/
private CsvStreamReader(Source source, char separator, char quoteChar,
char escape, int line, boolean strictQuotes,
boolean ignoreLeadingWhiteSpace) {
super(new StringReader("")); // dummy call to base constructor
contentQueue = new ArrayDeque<>();
TailerListener listener = new CsvContentListener(contentQueue);
tailer = Tailer.create(source.file(), listener, DEFAULT_MONITOR_DELAY,
false, true, 4096);
this.parser = new CSVParser(separator, quoteChar, escape, strictQuotes,
ignoreLeadingWhiteSpace);
this.skipLines = line;
try {
// wait for tailer to capture data
Thread.sleep(DEFAULT_MONITOR_DELAY);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
示例4: tail
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
public void tail(TailerListener listener) {
File file = new File(
fileLocation);
Tailer tailer = Tailer.create(file, listener, 10);
tailer.run();
}
示例5: initNetlogTailer
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
private void initNetlogTailer() {
if (netLogTailerThread != null) {
netLogTailerThread.interrupt();
netLogTailerThread = null;
}
if (activeNetLogFile != null) {
TailerListener listener = new NetLogTailerListener();
Tailer tailer = new Tailer(activeNetLogFile, listener, 2000);
this.netLogTailerThread = new Thread(tailer);
netLogTailerThread.setDaemon(true);
netLogTailerThread.start();
}
}
示例6: getStream
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
public Observable<String> getStream(final long pollIntervalMs) {
return Observable.create(new OnSubscribeFunc<String>() {
@Override
public Subscription onSubscribe(
final Observer<? super String> observer) {
TailerListener listener = createListener(observer);
final Tailer tailer = new Tailer(file, listener, pollIntervalMs);
Thread t = new Thread(createRunnable(observer, tailer));
t.start();
return createSubscription(tailer);
}
});
}
示例7: GzipTailer
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
/**
* Creates a Tailer for the given file, with a specified buffer size.
*
* @param file the file to follow.
* @param listener the TailerListener to use.
* @param delayMillis the delay between checks of the file for new content in milliseconds.
* @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
* @param bufSize Buffer size
*/
public GzipTailer(File file, TailerListener listener, long delayMillis, boolean end, int bufSize)
{
super(file, listener, delayMillis, end, bufSize);
this.file = file;
this.delayMillis = delayMillis;
this.end = end;
this.inbuf = new byte[bufSize];
// Save and prepare the listener
this.listener = listener;
listener.init(this);
}
示例8: start
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
public void start()
{
for (Log log : logs)
{
TailerListener listener = new MyTailerListener(log);
executor.execute(new Tailer(log.getFile(), listener, DELAY, false, false));
}
}
示例9: LogTailer
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
@Autowired
public LogTailer(File file, TailerListener listener, long delayMillis) {
super(file, listener, delayMillis, TAIL_FROM_END_OF_FILE);
}
示例10: setupTailer
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
private void setupTailer() {
TailerListener listener = new LogTailer();
File tailFile = new File(DebugLogger.LOGGING_FILENAME);
tailer = Tailer.create(tailFile, new LogTailer(), 500, true);
}
示例11: create
import org.apache.commons.io.input.TailerListener; //导入依赖的package包/类
/**
* Creates and starts a Tailer for the given file.
*
* @param file the file to follow.
* @param listener the TailerListener to use.
* @param delayMillis the delay between checks of the file for new content in milliseconds.
* @param end Set to true to tail from the end of the file, false to tail from the beginning of the file.
* @param bufSize buffer size.
* @return The new tailer
*/
public static GzipTailer create(File file, TailerListener listener, long delayMillis, boolean end, int bufSize)
{
GzipTailer tailer = new GzipTailer(file, listener, delayMillis, end, bufSize);
Thread thread = new Thread(tailer);
thread.setDaemon(true);
thread.start();
return tailer;
}