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

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

Introduction

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

Prototype

public static List readLines(Reader input) throws IOException 

Source Link

Document

Get the contents of a Reader as a list of Strings, one entry per line.

Usage

From source file:com.opengamma.elsql.ElSqlBundle.java

private static List<String> loadResource(Resource resource) {
    InputStream in = null;/* ww  w .  ja  v a2s .  com*/
    try {
        in = resource.getInputStream();
        return IOUtils.readLines(in);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:eu.annocultor.tests.ReporterPersistenceTest.java

@Test
@SuppressWarnings("unchecked")
public void testRW() throws Exception {
    final String[] lines = { "line 1", "line 13", "l34ine 144", "4line ,d 1", "line 1'", "'line 1", "" };

    File dir = new File(task.getEnvironment().getTmpDir(), "reportPersistence");
    dir.mkdir();/* w w  w  .  ja v a 2s  . com*/

    // init & persist
    {
        ReportCounter<String> c = new ReportCounter<String>(dir, TEST + "." + AbstractReporter.FILE_LOOKUPS,
                1000);
        int i = 0;
        for (String line : lines) {
            c.inc(line, i);
            i++;
        }
        c.flush();
    }
    // load from file
    {
        ReportCounter<String> c = new ReportCounter<String>(dir, TEST + "." + AbstractReporter.FILE_LOOKUPS,
                1000);
        c.load();
        int i = 0;
        for (ObjectCountPair<String> entry : c.asList()) {
            // difficult to test            Assert.assertEquals("On line " + i, lines[i], entry.getObject());
            i++;
        }

        Assert.assertEquals(lines.length, i);
    }
    // generate html report
    Reporter reporter = new ReporterImpl(TEST, task.getEnvironment());
    for (String line : lines) {
        reporter.log(line);
    }
    reporter.report();

    ReportPresenter presenter = new ReportPresenter(task.getEnvironment().getDocDir(), TEST);
    presenter.makeHtmlReport();
    FileInputStream is = new FileInputStream(
            new File(task.getEnvironment().getDocDir(), TEST + "/ReportData.js"));
    List<String> js = IOUtils.readLines(is);
    String joined = StringUtils.join(js, ",");
    {
        for (String line : lines) {
            Assert.assertTrue("On line: " + line, joined.contains(line));
        }
    }
    is.close();

}

From source file:bboss.org.artofsolving.jodconverter.process.LinuxProcessManager.java

private List<String> execute(String... args) throws IOException {
    String[] command;/*w  w w . j  av  a 2s .  c o  m*/
    if (runAsArgs != null) {
        command = new String[runAsArgs.length + args.length];
        System.arraycopy(runAsArgs, 0, command, 0, runAsArgs.length);
        System.arraycopy(args, 0, command, runAsArgs.length, args.length);
    } else {
        command = args;
    }
    Process process = new ProcessBuilder(command).start();
    @SuppressWarnings("unchecked")
    List<String> lines = IOUtils.readLines(process.getInputStream());
    return lines;
}

From source file:com.hortonworks.registries.util.HdfsFileStorageTest.java

@Test
public void testUploadJarWithDir() throws Exception {
    Map<String, String> config = new HashMap<>();
    config.put(HdfsFileStorage.CONFIG_FSURL, "file:///");
    config.put(HdfsFileStorage.CONFIG_DIRECTORY, HDFS_DIR);
    fileStorage.init(config);/*from   www  .  j a va 2 s. c  om*/

    File file = File.createTempFile("test", ".tmp");
    file.deleteOnExit();

    List<String> lines = Arrays.asList("test-line-1", "test-line-2");
    Files.write(file.toPath(), lines, Charset.forName("UTF-8"));
    String jarFileName = "test.jar";

    fileStorage.deleteFile(jarFileName);

    fileStorage.uploadFile(new FileInputStream(file), jarFileName);

    InputStream inputStream = fileStorage.downloadFile(jarFileName);
    List<String> actual = IOUtils.readLines(inputStream);
    Assert.assertEquals(lines, actual);
}

From source file:com.splunk.shuttl.archiver.importexport.ShellExecutor.java

/**
 * @return//from w  w w.  java  2s .c om
 */
public List<String> getStdOut() {
    try {
        return IOUtils.readLines(process.getInputStream());
    } catch (IOException e) {
        return Collections.emptyList();
    }
}

From source file:com.nuevebit.miroculus.mrna.cli.DatabasePopulator.java

private void parseMortalityRates(InputStream mortalityRates) throws IOException {

    List<String> lines = IOUtils.readLines(mortalityRates);

    for (String line : lines) {
        String[] parts = line.split("=");
        String diseaseName = parts[0];
        double rate = Double.valueOf(parts[1]);

        Disease disease = diseaseRepository.findByName(diseaseName);
        disease.setMortalityRate(rate);/* www.j a v a  2s .  c o m*/

        //diseaseRepository.save(disease);
    }
}

From source file:cz.pichlik.goodsentiment.server.handler.EventAggregatorTest.java

@Test
public void timestampIsDate() throws Exception {
    File resultFile = aggregateSingle();
    try (FileReader fr = new FileReader(resultFile)) {
        List<String> result = IOUtils.readLines(fr);
        assertThat(result, hasItems(StringEndsWith.endsWith("2015-12-10T17:55:25")));
    }/* ww w .jav  a  2s.  c  o  m*/
}

From source file:net.rptools.lib.FileUtil.java

@SuppressWarnings("unchecked")
public static List<String> getLines(File file) throws IOException {
    List<String> list;
    FileReader fr = new FileReader(file);
    try {/*from  ww w . j  a v  a 2  s . c o  m*/
        list = IOUtils.readLines(fr);
    } finally {
        fr.close();
    }
    return list;
}

From source file:com.btoddb.chronicle.FileTestUtils.java

public Matcher<File> hasEventsInOrder(final Event[] targetEvents) {
    return new TypeSafeMatcher<File>() {
        String errorDesc;/*from   w  w  w.  ja  v a  2 s  . c o m*/
        String expected;
        String got;

        @Override
        protected boolean matchesSafely(final File f) {
            FileReader fr = null;
            try {
                fr = new FileReader(f);
                List<String> lines = IOUtils.readLines(fr);
                if (targetEvents.length != lines.size()) {
                    errorDesc = "number of events: ";
                    expected = "" + targetEvents.length;
                    got = "" + lines.size();
                    return false;
                }

                for (int i = 0; i < targetEvents.length; i++) {
                    Event event = config.getEventSerializer().deserialize(lines.get(i));
                    if (!targetEvents[i].equals(event)) {
                        errorDesc = "event: ";
                        expected = new String(config.getEventSerializer().serialize(targetEvents[i]));
                        got = lines.get(i);
                        return false;
                    }
                }
                return true;
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return false;
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            } finally {
                if (null != fr) {
                    try {
                        fr.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

        }

        @Override
        public void describeTo(final Description description) {
            description.appendText(errorDesc).appendValue(expected);
        }

        @Override
        protected void describeMismatchSafely(final File item, final Description mismatchDescription) {
            mismatchDescription.appendText("  was: ").appendValue(got);
        }
    };
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.comments.pipeline.VocabularyCollector.java

@Override
public void initialize(UimaContext context) throws ResourceInitializationException {
    super.initialize(context);

    if (minimalOccurrence < 0) {
        throw new ResourceInitializationException(
                new IllegalArgumentException("Minimal occurrence must be positive integer"));
    }//ww w.  j  a  v  a 2s .  c o  m

    try {
        if (ignoreStopwords) {
            URL url = ResourceUtils.resolveLocation(stopwordsList);
            stopwords.addAll(IOUtils.readLines(url.openStream()));
        }
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
}