Java Code Examples for org.apache.commons.io.input.Tailer#create()
The following examples show how to use
org.apache.commons.io.input.Tailer#create() .
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: CsvStreamReader.java From Quicksql with MIT License | 6 votes |
/** * 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); } }
Example 2
Source File: CsvStreamReader.java From calcite with Apache License 2.0 | 6 votes |
/** * 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); } }
Example 3
Source File: Subscriber.java From bidder with Apache License 2.0 | 5 votes |
/** * Setup a file tailer. * @param buf String. The Address buffer. * @throws Exception on setup exception. */ void processLogTailer(String buf) throws Exception { // String buf = "file://log.txt&whence=eof&delay=500&reopen=false&bufsize=4096"; buf = buf.substring(7); String parts [] = buf.split("&"); String fileName = parts[0]; for (int i=1;i<parts.length;i++) { String t[] = parts[i].trim().split("="); if (t.length != 2) { throw new Exception("Not a proper parameter (a=b)"); } t[0] = t[0].trim(); t[1] = t[1].trim(); switch(t[0]) { case "whence": if (t[1].equalsIgnoreCase("bof")) end = false; else end = true; break; case "delay": delay = Integer.parseInt(t[1]); break; case "reopen": reopen = Boolean.parseBoolean(t[1]); break; case "bufsize": bufsize = Integer.parseInt(t[1]); break; } } topic = fileName; tailer = Tailer.create(new File(fileName), this, delay, end, reopen, bufsize ); }
Example 4
Source File: FileToStreamOutputWriter.java From amazon-neptune-tools with Apache License 2.0 | 5 votes |
FileToStreamOutputWriter(OutputWriter innerOutputWriter, Path filePath, KinesisConfig kinesisConfig) { this.innerOutputWriter = innerOutputWriter; this.filePath = filePath; this.stream = kinesisConfig.stream(); this.listener = new ExportListener(stream); this.tailer = Tailer.create(filePath.toFile(), listener); }
Example 5
Source File: FileTailingDataProvider.java From storm-solr with Apache License 2.0 | 5 votes |
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); }
Example 6
Source File: LogTailer.java From micro-server with Apache License 2.0 | 5 votes |
public void tail(TailerListener listener) { File file = new File( fileLocation); Tailer tailer = Tailer.create(file, listener, 10); tailer.run(); }
Example 7
Source File: LogTailer.java From micro-server with Apache License 2.0 | 5 votes |
public void tail(TailerListener listener, String alias) { File file = logLookup.map(l -> l.lookup(alias)) .orElse(new File( fileLocation)); Tailer tailer = Tailer.create(file, listener, 10); tailer.run(); }
Example 8
Source File: TestUtils.java From incubator-samoa with Apache License 2.0 | 4 votes |
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); }
Example 9
Source File: OutputFileTailer.java From MesquiteCore with GNU Lesser General Public License v3.0 | 4 votes |
public void start () { OutputFileListener listener = new OutputFileListener(this); tailer = Tailer.create(fileToTail, listener, 500); }
Example 10
Source File: TestUtils.java From samoa with Apache License 2.0 | 4 votes |
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); }