Example usage for org.apache.commons.io LineIterator nextLine

List of usage examples for org.apache.commons.io LineIterator nextLine

Introduction

In this page you can find the example usage for org.apache.commons.io LineIterator nextLine.

Prototype

public String nextLine() 

Source Link

Document

Returns the next line in the wrapped Reader.

Usage

From source file:de.fhg.iais.asc.ui.MyCortexStarter.java

public MyCortexStarter(String baseDir) {
    LineIterator it = createLineIterator(baseDir + "/conf/startServers.txt");
    try {//from w  w w . jav a2 s.  c o  m
        while (it.hasNext()) {
            String nextLine = it.nextLine();
            if (!StringUtils.isEmpty(nextLine) && !isComment(nextLine)) {
                this.autoStartNames.add(nextLine);
            }
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
}

From source file:de.fhg.iais.cortex.Starter.java

public Starter(String baseDir) {
    LineIterator it = createLineIterator(baseDir + "/conf/startServers.txt");
    try {/*from   ww w  .j a va2s  . co m*/
        while (it.hasNext()) {
            String nextLine = it.nextLine();
            if (!StringUtils.isEmpty(nextLine) && !isComment(nextLine)) {
                this.autoStartNames.add(nextLine);
            }
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.penntree.PennTreebankCombinedReader.java

private PennTreeNode readTree(LineIterator aLi) {
    StringBuilder tree = new StringBuilder();
    while (aLi.hasNext() || lineBuffer != null) {
        String line = lineBuffer != null ? lineBuffer : aLi.nextLine();
        lineBuffer = null;//  w  w w  .  j a v  a 2 s . c  om
        if (StringUtils.isBlank(line)) {
            if (tree.length() > 0) {
                break;
            } else {
                continue;
            }
        }

        // If the next line starts at the beginning (no indentation) then expect it is a new
        // tree.
        if ((tree.length() > 0) && !Character.isWhitespace(line.charAt(0))) {
            lineBuffer = line;
            break;
        }

        tree.append(line);
        tree.append('\n'); // Actually not needed - just in case we want to debug ;)
    }

    return PennTreeUtils.parsePennTree(tree.toString());
}

From source file:com.norconex.collector.fs.crawler.FilesystemCrawler.java

private void queueStartPaths(ICrawlDataStore crawlDataStore) {
    // Queue regular start urls
    String[] startPaths = getCrawlerConfig().getStartPaths();
    if (startPaths != null) {
        for (int i = 0; i < startPaths.length; i++) {
            String startPath = startPaths[i];
            executeQueuePipeline(new BaseCrawlData(startPath), crawlDataStore);
        }//from w  w  w . j  a  v a  2 s .c  om
    }
    // Queue start urls define in one or more seed files
    String[] pathsFiles = getCrawlerConfig().getPathsFiles();
    if (pathsFiles != null) {
        for (int i = 0; i < pathsFiles.length; i++) {
            String pathsFile = pathsFiles[i];
            LineIterator it = null;
            try {
                it = IOUtils.lineIterator(new FileInputStream(pathsFile), CharEncoding.UTF_8);
                while (it.hasNext()) {
                    String startPath = it.nextLine();
                    executeQueuePipeline(new BaseCrawlData(startPath), crawlDataStore);
                }
            } catch (IOException e) {
                throw new CollectorException("Could not process paths file: " + pathsFile, e);
            } finally {
                LineIterator.closeQuietly(it);
                ;
            }
        }
    }
}

From source file:cn.org.once.cstack.utils.JSONClient.java

public DockerResponse sendGet(URI uri) throws JSONClientException {

    if (logger.isDebugEnabled()) {
        logger.debug("Send a get request to : " + uri);
    }// ww w  .  ja  va 2  s.  co  m
    StringBuilder builder = new StringBuilder();

    HttpGet httpGet = new HttpGet(uri);
    HttpResponse response = null;
    try {
        CloseableHttpClient httpclient = buildSecureHttpClient();
        response = httpclient.execute(httpGet);
        LineIterator iterator = IOUtils.lineIterator(response.getEntity().getContent(), "UTF-8");
        while (iterator.hasNext()) {
            builder.append(iterator.nextLine());
        }
    } catch (IOException e) {
        throw new JSONClientException("Error in sendGet method due to : " + e.getMessage(), e);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Status code : " + response.getStatusLine().getStatusCode());
        logger.debug("Server response : " + builder.toString());
    }

    return new DockerResponse(response.getStatusLine().getStatusCode(), builder.toString());

}

From source file:com.abiquo.vsm.migration.Migrator.java

public void migrateNonPersistedModelFromFile(final File file) throws IOException {
    LineIterator iterator = FileUtils.lineIterator(file);
    RedisDao dao = RedisDaoFactory.getInstance();

    try {/*  w w w .j ava2  s  .c o  m*/
        while (iterator.hasNext()) {
            String line = iterator.nextLine();
            insertMachineFromCSVLine(dao, line);
        }
    } finally {
        LineIterator.closeQuietly(iterator);
    }
}

From source file:com.github.scizeron.jidr.maven.plugin.JidrPackageApp.java

@Override
public void execute() throws MojoExecutionException {
    InputStream input = null;/*from w w  w . j a v  a 2 s .c o m*/
    FileOutputStream output = null;

    if ("pom".equals(this.project.getPackaging())) {
        getLog().info("Skip execute on " + this.project.getPackaging() + " project.");
        return;
    }

    final String outputDirname = this.project.getBuild().getDirectory() + File.separator + "distrib";

    final String libOutputDir = outputDirname + File.separator + "lib";
    final String appOutputDir = outputDirname + File.separator + "app";
    final String confOutputDir = outputDirname + File.separator + "conf";
    final String binOutputDir = outputDirname + File.separator + "bin";

    try {
        new File(libOutputDir).mkdirs();
        new File(appOutputDir).mkdirs();
        new File(binOutputDir).mkdirs();
        new File(confOutputDir).mkdirs();

        File outputFile = new File(binOutputDir + File.separator + APP_SH_FILE);
        output = new FileOutputStream(outputFile);

        input = JidrPackageApp.class.getClassLoader().getResourceAsStream(APP_SH_FILE);
        final LineIterator lineIterator = IOUtils.lineIterator(input, Charsets.UTF_8);
        while (lineIterator.hasNext()) {
            output.write((lineIterator.nextLine() + "\n").getBytes());
        }
        output.close();

        getLog().info(String.format("Create \"%s\" in %s.", APP_SH_FILE, binOutputDir));

        outputFile = new File(confOutputDir + File.separator + APP_CFG_FILE);
        output = new FileOutputStream(outputFile);

        output.write(new String("APP_ARTIFACT=" + project.getArtifactId() + "\n").getBytes());
        output.write(new String("APP_PACKAGING=" + project.getPackaging() + "\n").getBytes());
        output.write(new String("APP_VERSION=" + project.getVersion()).getBytes());

        getLog().info(String.format("Create \"%s\" in %s.", APP_CFG_FILE, confOutputDir));

        // si un repertoire src/main/bin est present dans le projet, le contenu
        // sera copie dans binOutputDir
        addExtraFiles(this.project.getBasedir().getAbsolutePath() + "/src/main/bin", binOutputDir);

        // si un repertoire src/main/conf est present dans le projet, le contenu
        // sera copie dans confOutputDir
        addExtraFiles(this.project.getBasedir().getAbsolutePath() + "/src/main/conf", confOutputDir);

        final String artifactFilename = this.project.getBuild().getFinalName() + "."
                + this.project.getPackaging();

        FileUtils.copyFileToDirectory(
                new File(this.project.getBuild().getDirectory() + File.separator + artifactFilename),
                new File(appOutputDir));

        getLog().info(String.format("Copy \"%s\" to %s.", artifactFilename, appOutputDir));

        String distribFilename = this.project.getArtifactId() + "-" + this.project.getVersion() + "-"
                + classifier + "." + DISTRIB_TYPE;

        ZipFile distrib = new ZipFile(
                this.project.getBuild().getDirectory() + File.separator + distribFilename);
        ZipParameters zipParameters = new ZipParameters();
        distrib.addFolder(new File(binOutputDir), zipParameters);
        distrib.addFolder(new File(appOutputDir), zipParameters);
        distrib.addFolder(new File(confOutputDir), zipParameters);

        getLog().info(
                String.format("Create \"%s\" to %s.", distribFilename, this.project.getBuild().getDirectory()));

        this.mavenProjectHelper.attachArtifact(this.project, DISTRIB_TYPE, classifier, distrib.getFile());
        getLog().info(String.format("Attach \"%s\".", distribFilename));

    } catch (Exception exception) {
        getLog().error(exception);

    } finally {
        try {
            if (output != null) {
                output.close();
            }
            if (input != null) {
                input.close();
            }
        } catch (IOException e) {
            getLog().error(e);
        }
    }
}

From source file:fr.treeptik.cloudunit.docker.JSONClient.java

public JsonResponse sendGet(URI uri) throws IOException {
    StringBuilder builder = new StringBuilder();
    CloseableHttpClient httpclient = build();
    HttpGet httpGet = new HttpGet(uri);
    HttpResponse response = httpclient.execute(httpGet);
    LineIterator iterator = IOUtils.lineIterator(response.getEntity().getContent(), "UTF-8");
    while (iterator.hasNext()) {
        builder.append(iterator.nextLine());
    }/* w  w  w  .  j a  v  a  2  s.  com*/
    JsonResponse jsonResponse = new JsonResponse(response.getStatusLine().getStatusCode(), builder.toString(),
            null);
    return jsonResponse;
}

From source file:it.geosolutions.tools.io.file.MultiPropertyFile.java

/**
 * Process the file.//from  w  w w . ja va2  s.  c o m
 * The return value tells if the processing was successful.
 * Even in a case of a failed parsing, the valid properties will be accessibile. 
 * <br/><br/>
 * At the end of the read procedure the InputStream will be closed.
 * 
 * @return true if the parsing was successful.
 */
public boolean read() {
    properties = new HashMap<String, Object>();
    boolean ret = true;

    LineIterator it = null;
    try {
        in = getIS();
        it = IOUtils.lineIterator(in, "UTF-8");
        while (it.hasNext()) {
            String line = it.nextLine();
            if (line.trim().length() == 0) // empty line
                continue;
            if (line.startsWith("#")) // comment line
                continue;

            int idx = line.indexOf("=");
            if (idx == -1) {
                LOGGER.warn("Missing '=' in line: [" + line + "]" + (file == null ? "" : " in file " + file));
                ret = false;
                continue;
            }

            String key = line.substring(0, idx);
            String value = line.substring(idx + 1);

            putValue(key, value);
        }

        return ret;

    } catch (IOException ex) {
        LOGGER.error(
                "Error processing input" + (file == null ? "" : (" file " + file)) + ": " + ex.getMessage(),
                ex);
        return false;
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.opengamma.bbg.replay.BloombergRefDataCollector.java

private Set<String> loadFields() {
    Set<String> fields = Sets.newHashSet();
    LineIterator it;
    try {//from  w  ww  .  ja  v a2  s  .  c  o m
        it = FileUtils.lineIterator(_fieldsFile);
    } catch (IOException ex) {
        throw new OpenGammaRuntimeException("IOException when reading " + _fieldsFile, ex);
    }
    try {
        while (it.hasNext()) {
            String line = it.nextLine();
            if (StringUtils.isBlank(line) || line.charAt(0) == '#') {
                continue;
            }
            fields.add(line);
        }
    } finally {
        LineIterator.closeQuietly(it);
    }
    return fields;
}