Example usage for org.apache.commons.io FileUtils readLines

List of usage examples for org.apache.commons.io FileUtils readLines

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils readLines.

Prototype

public static List readLines(File file) throws IOException 

Source Link

Document

Reads the contents of a file line by line to a List of Strings using the default encoding for the VM.

Usage

From source file:edu.cornell.med.icb.goby.modes.TestReadQualityStatsMode.java

@Test
public void testHasStats() throws IOException {
    final ReadQualityStatsMode readQuality = new ReadQualityStatsMode();
    readQuality.setSampleFraction(1.0d);
    readQuality.addInputFile(new File("test-data/compact-reads/five-with-quality.compact-reads"));
    final File outputFile = new File("test-results/five-with-quality.compact-reads.read-qual-stats.tsv");
    readQuality.setOutputFile(outputFile);
    readQuality.execute();//  w  w  w. ja v a2s  . co  m
    assertEquals("All reads should have been observed", 5, readQuality.getNumberOfObservedReads());
    assertEquals("No reads should have been skipped", 0, readQuality.getNumberOfSkippedReads());
    final List lines = FileUtils.readLines(outputFile);
    assertEquals("Wrong number of stats lines in output file", 39, lines.size());
}

From source file:net.itransformers.idiscover.v2.core.CvsConnectionDetailsFactory.java

@SuppressWarnings("unchecked")
public static Map<String, ConnectionDetails> createConnectionDetail(File file) throws IOException {
    List<String> lines = FileUtils.readLines(file);
    Map<String, ConnectionDetails> result = new LinkedHashMap<String, ConnectionDetails>();
    for (String line : lines) {
        if (line.trim().equals(""))
            continue;
        if (line.startsWith("#"))
            continue;
        int headerSeparatorIndex = line.indexOf(":");
        if (headerSeparatorIndex == -1) {
            throw new RuntimeException(
                    "Can not find header separator ':', for connection details line: " + line);
        }/*from   www. j  a v  a 2  s .  c  o  m*/
        String header = line.substring(0, headerSeparatorIndex);
        String body = line.substring(headerSeparatorIndex + 1);
        Map<String, String> headerAttributes = parse(line, header);
        Map<String, String> attributes = parse(line, body);
        if (!headerAttributes.containsKey("type")) {
            throw new RuntimeException(
                    "Can not find 'type' attribute in header, for connection details line: " + line);
        }
        if (!headerAttributes.containsKey("name")) {
            throw new RuntimeException(
                    "Can not find 'name' attribute in header, for connection details line: " + line);
        }
        ConnectionDetails details = new ConnectionDetails(headerAttributes.get("type"), attributes);
        result.put(headerAttributes.get("name"), details);
    }
    return result;
}

From source file:ch.puzzle.modjprof.instrumentation.InstrumentationIT.java

@Test
public void testExecute() throws IOException, InterruptedException {
    File configFile = new File("target/modjprof.properties");
    String agentArguments = "config=" + configFile.getCanonicalPath();
    assertThat(execute(new String[] {}, agentArguments), is(equalTo(0)));

    long threadId = Thread.currentThread().getId();
    File file = new File(getClass().getClassLoader().getResource(EXPECTED_TRC_FILE).getFile());
    List<String> expectedLines = FileUtils.readLines(file);
    List<String> resultLines = FileUtils.readLines(new File(String.format(TRC_FILE, threadId)), UTF_8);

    assertThat(expectedLines.size(), is(equalTo(resultLines.size())));
    for (int i = 0; i < expectedLines.size(); i++) {
        assertThat(removeTimestamp(resultLines.get(i)), is(removeTimestamp(expectedLines.get(i))));
    }/* www. j av a  2s  .  c om*/
}

From source file:com.pablissimo.sonar.LCOVParserImpl.java

public Map<String, CoverageMeasuresBuilder> parseFile(File file) {
    final List<String> lines;
    try {/*from w  w w  .  j a  v a 2 s  .c o  m*/
        lines = FileUtils.readLines(file);
    } catch (IOException e) {
        throw new SonarException("Could not read content from file: " + file, e);
    }
    return parse(lines);
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.helpers.FinalTableExtractor.java

public static void createCrossEvaluationTables(File mainFolder, final String prefix) throws IOException {
    Map<String, Table<String, String, Double>> domainResults = new TreeMap<>();

    File[] crossDomainFolders = mainFolder.listFiles(new FileFilter() {
        @Override//w ww . ja v a 2  s .  c  o  m
        public boolean accept(File pathname) {
            return pathname.isDirectory() && pathname.getName().startsWith(prefix);
        }
    });

    System.out.println(Arrays.toString(crossDomainFolders));

    for (File crossDomainFolder : crossDomainFolders) {
        // get the target domain
        String[] folderNameSplit = crossDomainFolder.getName().split("_");
        String domain = folderNameSplit[1];
        String featureSet = folderNameSplit[2];

        File resultSummaryFile = new File(crossDomainFolder, "resultSummary.txt");
        for (String line : FileUtils.readLines(resultSummaryFile)) {
            // parse the line with evaluation
            String[] split = line.split("\\s+");
            String argumentComponent = split[0];
            Double value = Double.valueOf(split[1]);

            // create a new table if needed
            if (!domainResults.containsKey(domain)) {
                domainResults.put(domain, TreeBasedTable.<String, String, Double>create());
            }

            // fill the table
            Table<String, String, Double> table = domainResults.get(domain);

            if (includeColumn(argumentComponent)) {
                table.put(featureSet, argumentComponent, value);
            }
        }
    }

    System.out.println(domainResults.keySet());

    for (Map.Entry<String, Table<String, String, Double>> entry : domainResults.entrySet()) {

        System.out.println(entry.getKey());
        System.out.println(tableToCsv(entry.getValue()));
    }
}

From source file:eu.delving.sip.TestCoordinateConversion.java

@Before
public void prep() throws IOException {
    URL input = getClass().getResource("/geo/TestCoordinateConversion.txt");
    inputLines = FileUtils.readLines(new File(input.getFile()));
    URL func = getClass().getResource("/geo/TestCoordinateConversion.xml");
    MappingFunction mappingFunction = (MappingFunction) getStream().fromXML(new File(func.getFile()));
    Map<String, String> facts = new TreeMap<String, String>();
    functionScript = groovyCodeResource.createFunctionScript(mappingFunction, facts, null);
}

From source file:de.tudarmstadt.ukp.dkpro.wsd.si.dictionary.util.GoogleDictionary.java

public GoogleDictionary(String path, String neededMentionsPath) throws FileNotFoundException, IOException {

    HashSet<String> neededMentions = new HashSet<String>(FileUtils.readLines(new File(neededMentionsPath)));

    mentionMap = new HashMap<String, List<String[]>>();
    targetMap = new HashMap<String, Integer>();

    BufferedReader reader = new BufferedReader(
            new InputStreamReader(new BZip2CompressorInputStream(new FileInputStream(path))));
    String line;// w w w .ja va2  s.com
    String[] lineArray;
    String anchor;
    String target;
    String score;
    boolean inKB;
    boolean isTranslation;
    //      Timer timer = new Timer(297073139);
    while ((line = reader.readLine()) != null) {
        lineArray = line.split("\t");

        anchor = lineArray[0];
        if (neededMentions.contains(anchor)) {
            anchor = anchor.replaceAll("\"", "").trim().replaceAll(" ", "_").toLowerCase();
            score = lineArray[1].split(" ")[0].trim();
            target = lineArray[1].split(" ")[1].trim();

            inKB = false;
            isTranslation = false;
            for (String flag : lineArray[1].substring(lineArray[1].indexOf(target) + target.length())
                    .split(" ")) {
                if (flag.equals("KB")) {
                    inKB = true;
                }
                if (flag.equals("x")) {
                    isTranslation = true;
                }
            }
            //            if(inKB && !isTranslation)
            if (!isTranslation) {
                //add target to targetMap
                if (targetMap.containsKey(target)) {
                    targetMap.put(target, targetMap.get(target) + 1);
                } else {
                    targetMap.put(target, 1);
                }

                //add targets to mentionMap
                if (!mentionMap.containsKey(anchor)) {
                    mentionMap.put(anchor, new LinkedList<String[]>());
                }
                mentionMap.get(anchor).add(new String[] { target, score });
            }

        }
    }

    reader.close();
}

From source file:com.roquahacks.semafor4j.FrameNetService.java

public void writeOptionsToConfig() {
    try {/*w w w  .  j av  a 2  s .  c  o  m*/
        this.configFile = FileUtils.readLines(new File(FrameNetOptions.ABS_PATH_FILE_CONFIG));
        BufferedWriter bw = new BufferedWriter(new FileWriter(new File(FrameNetOptions.ABS_PATH_FILE_CONFIG)));
        for (String s : configFile) {
            if (s.startsWith(SEMAFOR_HOME)) {
                s = SEMAFOR_HOME + FrameNetOptions.ABS_PATH_SEMAFOR;
            } else if (s.startsWith(MST_MODE)) {
                if (this.fnOpt.isServerModeOn()) {
                    s = MST_MODE + "server";
                } else {
                    s = MST_MODE + "noserver";
                }
            } else if (s.startsWith(JAVA_HOME)) {
                s = JAVA_HOME + this.fnOpt.getJavaHomePath();
            } else if (s.startsWith(GOLD_TARGET_FILE)) {
                s = GOLD_TARGET_FILE + this.fnOpt.getGoldTargetsPath();
            } else if (s.startsWith(AUTO_TARGET_ID_MODE)) {
                if (this.fnOpt.isAutoTargetIDStrictModeOn()) {
                    s = AUTO_TARGET_ID_MODE + "strict";
                } else {
                    s = AUTO_TARGET_ID_MODE + "relaxed";
                }
            } else if (s.startsWith(USE_GRAPH_FILES)) {
                if (this.fnOpt.isGraphFilesOn()) {
                    s = USE_GRAPH_FILES + "yes";
                } else {
                    s = USE_GRAPH_FILES + "no";
                }
            } else if (s.startsWith(DECODING_TYPE)) {
                s = DECODING_TYPE + this.fnOpt.getDecodingType();
            }
            bw.write(s);
            bw.newLine();
        }
        bw.flush();
        bw.close();
        this.configFile.clear();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:br.ufac.sion.util.retorno.caixa.ArquivoRetornoCaixa.java

private void carregarLinhas(File arquivo) {
    List<String> linhas;
    try {//w ww  .j a  va  2 s .c  om
        linhas = FileUtils.readLines(arquivo);
    } catch (IOException e) {
        throw new RuntimeException("Erro lendo linhas do arquivo de retorno", e);
    }
    this.arquivoTexto.read(linhas);
}

From source file:de.codecentric.batch.test.FlatFileJobTest.java

@Test
public void runJavaConfigJob() throws Exception {
    File file = new File("target/out-javaconfig.txt");
    file.delete();/*from  w ww . ja v a2 s.c  o m*/
    jobOperator.start("flatFileJob", "");
    while (jobRepository.getLastJobExecution("flatFileJob", new JobParameters()).getStatus().isRunning()) {
        Thread.sleep(100);
    }
    assertEquals(BatchStatus.COMPLETED,
            jobRepository.getLastJobExecution("flatFileJob", new JobParameters()).getStatus());
    assertEquals(3, FileUtils.readLines(file).size());
}