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) 

Source Link

Document

Creates and starts a Tailer for the given file, starting at the beginning of the file with the default delay of 1.0s

Usage

From source file:fr.logfiletoes.config.Unit.java

/**
 * Initialise ElasticSearch Index ans taile file
 * @throws IOException /*from w  ww  . java 2  s.  c o  m*/
 */
public void start() throws IOException {
    httpclient = HttpClients.createDefault();
    context = HttpClientContext.create();
    HttpGet httpGet = new HttpGet(getElasticSearch().getUrl());
    if (getElasticSearch().getLogin() != null && getElasticSearch().getPassword() != null) {
        UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(getElasticSearch().getLogin(),
                getElasticSearch().getPassword());
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, credentials);
        context.setCredentialsProvider(credentialsProvider);
    }
    CloseableHttpResponse elasticSearchCheck = httpclient.execute(httpGet, context);
    LOG.log(Level.INFO, "Check index : \"{0}\"", elasticSearchCheck.getStatusLine().getStatusCode());
    LOG.log(Level.INFO, inputSteamToString(elasticSearchCheck.getEntity().getContent()));
    int statusCodeCheck = elasticSearchCheck.getStatusLine().getStatusCode();
    EntityUtils.consume(elasticSearchCheck.getEntity());
    elasticSearchCheck.close();

    if (statusCodeCheck == 404) {
        // Cration de l'index
        HttpPut httpPut = new HttpPut(getElasticSearch().getUrl());
        CloseableHttpResponse executeCreateIndex = httpclient.execute(httpPut, context);
        LOG.log(Level.INFO, "Create index : \"{0}\"", executeCreateIndex.getStatusLine().getStatusCode());
        LOG.log(Level.INFO, inputSteamToString(executeCreateIndex.getEntity().getContent()));
        EntityUtils.consume(executeCreateIndex.getEntity());
        executeCreateIndex.close();

        CloseableHttpResponse elasticSearchCheckCreate = httpclient.execute(httpGet, context);
        LOG.log(Level.INFO, "Check create index : \"{0}\"",
                elasticSearchCheckCreate.getStatusLine().getStatusCode());
        LOG.log(Level.INFO, inputSteamToString(elasticSearchCheckCreate.getEntity().getContent()));
        int statusCodeCheckCreate = elasticSearchCheckCreate.getStatusLine().getStatusCode();
        EntityUtils.consume(elasticSearchCheckCreate.getEntity());
        elasticSearchCheckCreate.close();

        if (statusCodeCheckCreate != 200) {
            LOG.log(Level.SEVERE, "unable to create index \"{0}\"", getElasticSearch().getUrl());
            throw new IOException("unable to create index \"" + getElasticSearch().getUrl() + "\"");
        }
    } else if (elasticSearchCheck.getStatusLine().getStatusCode() != 200) {
        LOG.severe("unkown error elasticsearch");
        throw new IOException("unkown error elasticsearch");
    }
    LOG.log(Level.INFO, "Initialisation ElasticSearch r\u00e9ussi pour {0}", getElasticSearch().getUrl());

    tailer = Tailer.create(getLogFile(), new TailerListenerUnit(this, httpclient, context));
}

From source file:com.hellblazer.process.impl.AbstractManagedProcess.java

@Override
public Tailer tailStdErr(TailerListener listener) {
    return Tailer.create(getStdErrFile(), listener);
}

From source file:com.hellblazer.process.impl.AbstractManagedProcess.java

@Override
public Tailer tailStdOut(TailerListener listener) {
    return Tailer.create(getStdOutFile(), listener);
}

From source file:org.dodjsoft.tail.TailFilePanel.java

void setFile(File file) {
    this.file = file;

    // stop currently running tail
    if (this.tailer != null) {
        this.tailer.stop();
    }// w ww  . j a v  a2  s  .co  m
    // set title
    this.setName(file.getAbsolutePath());
    // set content
    Tailer.create(file, this);
}