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

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

Introduction

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

Prototype

public static String readFileToString(File file) throws IOException 

Source Link

Document

Reads the contents of a file into a String using the default encoding for the VM.

Usage

From source file:eu.planets_project.services.datatypes.ContentTests.java

@Before
public void init() throws IOException {
    file = new File(LOCATION);
    url = file.toURI().toURL();//from ww  w  .  jav  a  2  s. co m
    stream = url.openStream();
    byteArray = IOUtils.toByteArray(new FileInputStream(file));
    content = FileUtils.readFileToString(file);
}

From source file:com.galenframework.tests.parser.IndentationStructureParserTest.java

@Test
public void shouldRead_structuresFromFile() throws IOException {
    IndentationStructureParser parser = new IndentationStructureParser();

    String content = FileUtils.readFileToString(
            new File(getClass().getResource("/indentation-structure-parser/struct1.txt").getFile()));
    String contentWithTabs = content.replace("\\t", "\t");
    List<StructNode> nodes = parser.parse(contentWithTabs);

    assertThat(//from ww  w .j a  va  2 s. c o m
            nodes, is(
                    asList(node("Node A 0", 6, UNKNOWN_SOURCE),
                            node("Node A 1", 8, UNKNOWN_SOURCE, asList(
                                    node("Node A 1 1", 9, UNKNOWN_SOURCE,
                                            asList(node("Node A 1 1 1", 10, UNKNOWN_SOURCE),
                                                    node("Node A 1 1 2", 11, UNKNOWN_SOURCE))),
                                    node("Node A 1 2", 12, UNKNOWN_SOURCE,
                                            asList(node("Node A 1 2 1", 13, UNKNOWN_SOURCE))))),
                            node("Node B 1", 18, UNKNOWN_SOURCE,
                                    asList(node("Node B 1 1", 19, UNKNOWN_SOURCE,
                                            asList(node("Node B 1 1 1", 20, UNKNOWN_SOURCE))),
                                            node("Node B 1 2", 21, UNKNOWN_SOURCE),
                                            node("Node B 1 3", 22, UNKNOWN_SOURCE))))));
}

From source file:com.gagein.crawler.Extractor.java

public void extact(String dirPath) {
    logger.debug("============????");
    getFilesPath(dirPath);//from  w ww.  ja  v  a  2  s.  co  m
    System.out.println(pathSet);
    ArticleStripper as = new ArticleStripper();
    as.setExtractAuthor(false);
    as.setExtractContent(true);
    as.setExtractDate(false);
    as.setExtractImg(false);
    as.setKeepContentLink(false);

    for (String url : pathSet) {
        System.out.println(url);
        File file = new File(url);
        try {
            logger.debug("==============?" + url + "?");
            String page = FileUtils.readFileToString(file);

            IArticleStrip bbs = new BoilerpipeStripper();
            String content = bbs.stripToCommonTextArticle(null, null, page);
            System.out.println("url##################" + url);
            System.out.println("Content##################" + content);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:de.tudarmstadt.ukp.dkpro.tc.features.readability.TypeTokenRatioExtractorTest.java

@Test
public void testTypeTokenRatioExtractor() throws Exception {
    String text = FileUtils.readFileToString(new File("src/test/resources/test_document_en.txt"));

    AnalysisEngineDescription desc = createEngineDescription(createEngineDescription(OpenNlpSegmenter.class),
            createEngineDescription(OpenNlpPosTagger.class), createEngineDescription(ClearNlpLemmatizer.class));
    AnalysisEngine engine = createEngine(desc);
    JCas jcas = engine.newJCas();/*from   www .  ja  va  2  s.  c  o  m*/
    jcas.setDocumentLanguage("en");
    jcas.setDocumentText(text);
    engine.process(jcas);

    TypeTokenRatioExtractor extractor = new TypeTokenRatioExtractor();

    List<Feature> features = extractor.extract(jcas);

    Assert.assertEquals(1, features.size());
    Assert.assertEquals((double) features.get(0).getValue(), 0.6, 0.1);

}

From source file:net.itransformers.idiscover.core.DiscoveryResourceManager.java

public DiscoveryResourceManager(File projectDir, String label, String PathToXML) {
    String xml = null;/*from  www . ja  va2 s .  co m*/
    try {
        xml = FileUtils.readFileToString(new File(projectDir, PathToXML));
    } catch (IOException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    ResourcesType deviceGroupsType = null;
    try {
        deviceGroupsType = JaxbMarshalar.unmarshal(ResourcesType.class, is);
    } catch (JAXBException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
    this.resourceManager = new ResourceManager(deviceGroupsType);
}

From source file:com.sangupta.imgur.api.TestModels.java

private String readJson(String fileName) {
    try {/* w w w . j av a 2s.c  o m*/
        String path = this.getClass().getClassLoader().getResource(fileName).getPath();
        return FileUtils.readFileToString(new File(path));
    } catch (IOException e) {

    }

    return null;
}

From source file:gov.va.vinci.leo.tools.AsciiFilterTest.java

@Before
public void setTestString() throws IOException {
    String path = new File(".").getCanonicalPath();
    if (!path.endsWith("core")) {
        rootDirectory = "core/";
    }// www .  j  a v a 2s .c  o  m
    TEST_FILE = rootDirectory + "src/test/resources/filterTest/utf8.txt";

    try {
        TEST_STRING = FileUtils
                .readFileToString(new File(rootDirectory + "src/test/resources/results/utf8toascii.txt"));
    } catch (Exception e) {
        TEST_STRING = "bad";
        LOG.warn("Unable to slurp up the utf8toascii.txt file for Conversion results:\n"
                + ExceptionUtils.getFullStackTrace(e));
    }
    LOG.info("TEST_STRING: " + TEST_STRING);

}

From source file:de.tudarmstadt.ukp.dkpro.tc.features.readability.PhrasePatternExtractorTest.java

@Ignore
public void testPhrasePatternExtractor() throws Exception {
    String text = FileUtils.readFileToString(new File("src/test/resources/test_document_en.txt"));

    AnalysisEngineDescription desc = createEngineDescription(createEngineDescription(OpenNlpSegmenter.class),
            createEngineDescription(OpenNlpPosTagger.class), createEngineDescription(OpenNlpChunker.class));
    AnalysisEngine engine = createEngine(desc);
    JCas jcas = engine.newJCas();//from  w  w  w.  j ava  2  s.c  om
    jcas.setDocumentLanguage("en");
    jcas.setDocumentText(text);
    engine.process(jcas);

    PhrasePatternExtractor extractor = new PhrasePatternExtractor();
    List<Feature> features = extractor.extract(jcas);

    Assert.assertEquals(6, features.size());
    // System.out.println(features);
    Assert.assertEquals((double) features.get(0).getValue(), 4.2, 0.1);
    Assert.assertEquals((double) features.get(1).getValue(), 1.6, 0.1);
    Assert.assertEquals((double) features.get(2).getValue(), 0.9, 0.1);
    Assert.assertEquals((double) features.get(3).getValue(), 3.7, 0.1);
    Assert.assertEquals((double) features.get(4).getValue(), 0.4, 0.1);
    Assert.assertEquals((double) features.get(5).getValue(), 0.4, 0.1);

}

From source file:com.mirth.connect.plugins.datatypes.dicom.test.DICOMSerializerTest.java

@Test
public void testToXml3() throws Exception {
    String input = Base64/*from  w  ww .  jav a2s  . c  om*/
            .encodeBase64String(FileUtils.readFileToByteArray(new File("tests/test-dicom-input-3.dcm")));
    String output = FileUtils.readFileToString(new File("tests/test-dicom-output-3.xml"));
    DICOMSerializer serializer = new DICOMSerializer();
    Assert.assertEquals(output, TestUtil.prettyPrintXml(serializer.toXML(input)));
}

From source file:com.carrotgarden.maven.aws.grv.TestCarrotGroovyRunner.java

@Test
public void testString() throws Exception {

    final Properties properties = new Properties();
    properties.put("prop-key", "prop-value-1");

    assertEquals(properties.get("prop-key"), "prop-value-1");

    final MavenProject project = mock(MavenProject.class);

    when(project.getProperties()).thenReturn(properties);

    final CarrotGroovyRunner runner = new CarrotGroovyRunner(project);

    final File file = new File("./src/test/resources/script.groovy");

    final String script = FileUtils.readFileToString(file);

    final Object result = runner.execute(script);

    assertEquals(result, "result");

    assertEquals(properties.get("prop-key"), "prop-value-2");

}