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.cisco.cta.taxii.adapter.filter.JsonValidationFilterTest.java

private String readFirstLine(String resource) throws IOException {
    try (InputStream istream = getClass().getResourceAsStream(resource)) {
        List<String> lines = IOUtils.readLines(istream);
        return lines.get(0);
    }/*  w  ww  .  j  a v  a 2s .  c o m*/
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtilTest.java

@Test
public void testWriteSoftFile() throws Exception {
    Experiment experiment = helper.makeGoodExperiment();
    String permaLinkUrl = "http://example.com/my-experiment";
    StringWriter sw = new StringWriter();
    PrintWriter out = new PrintWriter(sw);
    GeoSoftFileWriterUtil.writeSoftFile(experiment, permaLinkUrl, out);
    out.close();// w w  w  .  j ava 2s .c o m
    @SuppressWarnings("unchecked")
    List<String> lines = IOUtils.readLines(new StringReader(sw.toString()));

    final String[] expected = { "^SAMPLE=test-hyb", "!Sample_title=test-hyb",
            "!Sample_description=test-sample1, test-sample2", "!Sample_supplementary_file=raw_file.data",
            "!Sample_table=derived_file.data", "!Sample_source_name=test-source",
            "!Sample_organism=test Organizm 1", "!Sample_organism=test Organizm 2",
            "!Sample_treatment_protocol=\"some treatment:treatment desc\"; \"another treatment:another treatment desc\"",
            "!Sample_growth_protocol=\"some growth:growth desc\"",
            "!Sample_extract_protocol=\"some extract:extract desc\"",
            "!Sample_label_protocol=\"some label:labeling desc\"",
            "!Sample_hyb_protocol=\"some hybridization:hybridization desc\"",
            "!Sample_scan_protocol=\"some scan:scan desc\"",
            "!Sample_data_processing=\"data processing:data proc desc\"", "!Sample_label=label",
            "!Sample_biomaterial_provider=Affymetrix", "!Sample_platform_id=test-ga",
            "!Sample_characteristics=test-factor:test-value growth",
            "!Sample_characteristics=OrganismPart:some tissue site",
            "!Sample_characteristics=DiseaseState:some disease state",
            "!Sample_characteristics=ExternalId:test external id",
            "!Sample_characteristics=test-cat:test-val growth",
            "!Sample_characteristics=CellType:some cell type", "!Sample_molecule=other", "^SERIES=test-exp-id",
            "!Series_title=test-title", "!Series_summary=test-title",
            "!Series_overall_design=\"test-design-type1 (MO)\"; \"test-design-type2 (MO)\"",
            "!Series_pubmed_id=test-pub", "!Series_contributor=fff,mmm,lll",
            "!Series_web_link=http://example.com/my-experiment", "!Series_sample_id=test-hyb" };

    for (int i = 0; i < expected.length; i++) {
        String result = lines.get(i);
        assertEquals("line " + (i + 1), expected[i], result);
    }

}

From source file:com.hortonworks.streamline.streams.catalog.service.CatalogService.java

public static Collection<Class<? extends Storable>> getStorableClasses() {
    InputStream resourceAsStream = CatalogService.class.getClassLoader().getResourceAsStream("storables.props");
    HashSet<Class<? extends Storable>> classes = new HashSet<>();
    try {//  www  . j  a va 2s  .co m
        List<String> classNames = IOUtils.readLines(resourceAsStream);
        for (String className : classNames) {
            classes.add((Class<? extends Storable>) Class.forName(className));
        }
    } catch (IOException | ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    return classes;
}

From source file:is.iclt.icenlp.core.formald.tagsets.CustomTagset.java

private CustomTagset(InputStream is) {
    try {/* ww w.  j  a  v  a  2 s .co  m*/
        ArrayList<String> lines = (ArrayList<String>) IOUtils.readLines(is);
        tagMap = new HashMap<String, String>();
        reverseTagMap = new HashMap<String, String>();

        for (String line : lines) {
            String[] tokens = line.split("\\s+");
            if (tokens.length == 2) {
                tagMap.put(tokens[0], tokens[1]);
                reverseTagMap.put(tokens[1], tokens[0]);
            }
        }
        is.close();
    } catch (IOException ex) {
        System.out.println("Could not load tagset data!");
        ex.printStackTrace();
    }
}

From source file:de.rallye.test.helper.HttpClient.java

public static List<String> apiCallAsString(String url, int expectedStatusCode) throws IOException {
    HttpResponse r = apiCall(url, expectedStatusCode);
    return IOUtils.readLines(r.getEntity().getContent());
}

From source file:com.hortonworks.registries.tag.service.CatalogTagService.java

public static Collection<Class<? extends Storable>> getStorableClasses() {
    InputStream resourceAsStream = CatalogTagService.class.getClassLoader()
            .getResourceAsStream("tagstorables.props");
    HashSet<Class<? extends Storable>> classes = new HashSet<>();
    try {//  w ww  .  j  av a 2  s .  c om
        List<String> classNames = IOUtils.readLines(resourceAsStream);
        for (String className : classNames) {
            classes.add((Class<? extends Storable>) Class.forName(className));
        }
    } catch (IOException | ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    return classes;
}

From source file:com.jgui.ttscrape.LookOutFor.java

@PostConstruct
public void init() {

    try {/*from  ww w.  j a v  a2  s  .  c om*/
        titlesToFind = new ArrayList<String>();
        for (String title : IOUtils.readLines(new FileReader(titlesToFindFile))) {
            if ((title.length() != 0) && (title.charAt(0) != '#')) {
                titlesToFind.add(title.trim());
            }
        }
    } catch (Exception ex) {
        logger.error("failed to read titles to ignore list", ex);
    }
}

From source file:com.thoughtworks.go.agent.launcher.ServerCallTest.java

@Test
public void shouldBeAbleToReadTheResponseBody() throws Exception {
    GetMethod getMethod = new GetMethod(
            DownloadableFile.AGENT.url(ServerUrlGeneratorMother.generatorFor("localhost", 9090)));
    ServerCall.ServerResponseWrapper response = ServerCall.invoke(getMethod);
    List list = IOUtils.readLines(response.body);
    assertThat(list.isEmpty(), is(false));
}

From source file:com.streamsets.pipeline.lib.io.TestLiveFileChunk.java

@Test
public void testChunkGetters() throws IOException {
    LiveFile file = Mockito.mock(LiveFile.class);
    LiveFileChunk chunk = new LiveFileChunk("tag", file, StandardCharsets.UTF_8, "Hola\nHello".getBytes(), 1, 9,
            true);//from   w w  w  .j  av  a  2s . co  m
    Assert.assertEquals("tag", chunk.getTag());
    Assert.assertEquals(file, chunk.getFile());
    Assert.assertEquals("Hola", IOUtils.readLines(chunk.getReader()).get(0));
    Assert.assertEquals("Hell", IOUtils.readLines(chunk.getReader()).get(1));
    Assert.assertEquals(1, chunk.getOffset());
    Assert.assertEquals(9, chunk.getLength());
    Assert.assertTrue(chunk.isTruncated());
    Assert.assertEquals(2, chunk.getLines().size());
    Assert.assertEquals("Hola\n", chunk.getLines().get(0).getText());
    Assert.assertEquals(1, chunk.getLines().get(0).getFileOffset());
    Assert.assertEquals(chunk.getBuffer(), chunk.getLines().get(0).getBuffer());
    Assert.assertEquals(0, chunk.getLines().get(0).getOffset());
    Assert.assertEquals(5, chunk.getLines().get(0).getLength());
    Assert.assertEquals("Hell", chunk.getLines().get(1).getText());
    Assert.assertEquals(6, chunk.getLines().get(1).getFileOffset());
    Assert.assertEquals(chunk.getBuffer(), chunk.getLines().get(1).getBuffer());
    Assert.assertEquals(5, chunk.getLines().get(1).getOffset());
    Assert.assertEquals(4, chunk.getLines().get(1).getLength());
}

From source file:com.jgui.ttscrape.IgnoreListFilter.java

@PostConstruct
public void init() {
    try {// ww  w.  j  a  v  a  2s  .c o m
        fileHeader = new ArrayList<String>();
        titlesToIgnore = new ArrayList<String>();
        boolean headerComplete = false;
        for (String title : IOUtils.readLines(new FileReader(ignoreFile))) {
            if ((title.length() != 0) && (title.charAt(0) != '#')) {
                titlesToIgnore.add(title.trim());
                headerComplete = true;
            } else if (!headerComplete) {
                fileHeader.add(title);
            }
        }
    } catch (Exception ex) {
        logger.error("failed to read titles to ignore list", ex);
    }
}