本文整理汇总了Java中org.apache.commons.io.input.Tailer.create方法的典型用法代码示例。如果您正苦于以下问题:Java Tailer.create方法的具体用法?Java Tailer.create怎么用?Java Tailer.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.input.Tailer
的用法示例。
在下文中一共展示了Tailer.create方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startTailingFile
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
/**
* Starts tailing the given file, thus updating the log lines in the table.
*
* @param file
* the file to tail
*
* @throws FileNotFoundException
* if the file was not found
*/
public void startTailingFile(File file) throws FileNotFoundException {
if (!file.exists()) {
throw new FileNotFoundException(file.getAbsolutePath());
}
closeCurrentFile();
config.getState().addToRecentFiles(file.getAbsolutePath());
logTailListener = new BufferedLogTailListener(columnizer.getValue(), columnizedLogs,
config.getPreferences().getLogBufferSize());
logTailListener.skipEmptyLogsProperty().bind(config.getPreferences().skipEmptyLogsProperty());
logTailListener.limitNumberOfLogsProperty().bind(config.getPreferences().limitNumberOfLogsProperty());
logTailListener.maxNumberOfLogsProperty().bind(config.getPreferences().maxNumberOfLogsProperty());
tailer = Tailer.create(file, logTailListener, config.getPreferences().getTailingDelayInMillis());
tailingFile.set(true);
tailedFileName.set(file.getAbsolutePath());
}
示例2: CsvStreamReader
import org.apache.commons.io.input.Tailer; //导入方法依赖的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);
}
}
示例3: testShouldBeCallListenerHandleByLogging
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
@Test
public void testShouldBeCallListenerHandleByLogging() throws Exception {
Tailer.create(TestFileLoader.load("data/tailer/test.log"), listener, 100, true);
ConcurrentTestFileWriter.writeTestData("data/tailer/test.log", "logging", 3);
Thread.sleep(300);
verify(mockCollector, times(3)).collect(anyString());
}
示例4: open
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
public void open(Map stormConf) {
fileToParseName = fileToParse.getAbsolutePath();
parsedLineQueue = new LinkedBlockingQueue<Map>(maxQueueSize);
currentLine = 0;
if (lineParser == null)
lineParser = new NoOpLogLineParser();
tailer = Tailer.create(fileToParse, this, tailerDelayMs);
log.info("Started tailing "+fileToParseName);
}
示例5: tail
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
public void tail(TailerListener listener) {
File file = new File(
fileLocation);
Tailer tailer = Tailer.create(file, listener, 10);
tailer.run();
}
示例6: setLogFile
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
public void setLogFile(String pathname) {
logFile = new File(pathname);
tailerListener = new TailerListener();
tailer = Tailer.create(logFile, tailerListener, 450, false);
Thread thread = new Thread(tailer);
thread.setDaemon(true);
thread.start();
if (logFile.exists() == false){
logger.warn("Coud not open log file: " + pathname);
}
}
示例7: setupTailer
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
private void setupTailer() {
TailerListener listener = new LogTailer();
File tailFile = new File(DebugLogger.LOGGING_FILENAME);
tailer = Tailer.create(tailFile, new LogTailer(), 500, true);
}
示例8: start
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
public void start() {
if (tailer == null) {
tailer = Tailer.create(getLogsFile(), this, 500L, true);
LOG.info("Logs watcher started. File {} will be tracked for changes.", configurationMediator.getLogFileName());
}
}
示例9: test
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
public static void test(final TestParams testParams) throws IOException, ClassNotFoundException,
NoSuchMethodException, InvocationTargetException, IllegalAccessException, InterruptedException {
final File tempFile = File.createTempFile("test", "test");
final File labelFile = File.createTempFile("result", "result");
LOG.info("Starting test, output file is {}, test config is \n{}", tempFile.getAbsolutePath(), testParams.toString());
Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
Class.forName(testParams.getTaskClassName())
.getMethod("main", String[].class)
.invoke(null, (Object) String.format(
testParams.getCliStringTemplate(),
tempFile.getAbsolutePath(),
testParams.getInputInstances(),
testParams.getSamplingSize(),
testParams.getInputDelayMicroSec(),
labelFile.getAbsolutePath(),
testParams.getLabelSamplingSize()
).split("[ ]"));
} catch (Exception e) {
LOG.error("Cannot execute test {} {}", e.getMessage(), e.getCause().getMessage());
}
return null;
}
});
Thread.sleep(TimeUnit.SECONDS.toMillis(testParams.getPrePollWaitSeconds()));
CountDownLatch signalComplete = new CountDownLatch(1);
final Tailer tailer = Tailer.create(tempFile, new TestResultsTailerAdapter(signalComplete), 1000);
new Thread(new Runnable() {
@Override
public void run() {
tailer.run();
}
}).start();
signalComplete.await();
tailer.stop();
assertResults(tempFile, testParams);
if (testParams.getLabelFileCreated())
assertLabels(labelFile, testParams);
}
示例10: start
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
public void start () {
OutputFileListener listener = new OutputFileListener(this);
tailer = Tailer.create(fileToTail, listener, 500);
}
示例11: test
import org.apache.commons.io.input.Tailer; //导入方法依赖的package包/类
public static void test(final TestParams testParams) throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InterruptedException {
final File tempFile = File.createTempFile("test", "test");
LOG.info("Starting test, output file is {}, test config is \n{}", tempFile.getAbsolutePath(), testParams.toString());
Executors.newSingleThreadExecutor().submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
Class.forName(testParams.getTaskClassName())
.getMethod("main", String[].class)
.invoke(null, (Object) String.format(
testParams.getCliStringTemplate(),
tempFile.getAbsolutePath(),
testParams.getInputInstances(),
testParams.getSamplingSize(),
testParams.getInputDelayMicroSec()
).split("[ ]"));
} catch (Exception e) {
LOG.error("Cannot execute test {} {}", e.getMessage(), e.getCause().getMessage());
}
return null;
}
});
Thread.sleep(TimeUnit.SECONDS.toMillis(testParams.getPrePollWaitSeconds()));
CountDownLatch signalComplete = new CountDownLatch(1);
final Tailer tailer = Tailer.create(tempFile, new TestResultsTailerAdapter(signalComplete), 1000);
new Thread(new Runnable() {
@Override
public void run() {
tailer.run();
}
}).start();
signalComplete.await();
tailer.stop();
assertResults(tempFile, testParams);
}