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:github.srlee309.lessWrongBookCreator.scraper.WikiPostSectionExtractorTest.java

@Test
public void getPostSectionString_ReadStoredHtml_OutputAsExpected() throws Exception {
    PostExtractionDetails postExtractionDetails = new PostExtractionDetails.Builder().build();
    String htmlString = FileUtils.readFileToString(
            new File(this.getClass().getResource("/Feeling Moral - Lesswrongwiki.html").toURI()));
    Document doc = Jsoup.parse(htmlString);
    WikiPostSectionExtractor instance = new WikiPostSectionExtractor();
    String result = instance.getPostSectionString(postExtractionDetails, doc);
    String expResult = FileUtils.readFileToString(
            new File(this.getClass().getResource("/Feeling Moral - Lesswrongwiki.txt").toURI()));

    assertTrue(expResult.trim().equals(result.trim()));
}

From source file:com.gorsini.searcher.CanalplaySearcher.java

public void check() throws HTMLChangeException, IOException {
    String url = makeURL("intouchables");
    Document doc = Jsoup.connect(url).referrer("http://vod.canalplay.com/").get();
    Elements movies = doc.select("div.list_movie");
    String html = movies.html();/*from  w w w .java2 s.  c o  m*/
    String previousHTML = null;
    LOG.finest(html);
    File file = new File(CHECK_FILENAME);
    if (file.exists()) {
        previousHTML = FileUtils.readFileToString(new File(CHECK_FILENAME));
    } else {
        LOG.log(Level.INFO, "sauvegarde check");
        FileUtils.writeStringToFile(file, html);
    }
    if (previousHTML != null && !html.equals(previousHTML)) {
        // sauvegarde la nouvelle version pour pouvoir la comparer.
        FileUtils.writeStringToFile(new File(CHECK_FILENAME + ".new"), html);
        throw new HTMLChangeException();
    } else {
        LOG.log(Level.INFO, "no change detected into HTML response");
    }
}

From source file:github.srlee309.lessWrongBookCreator.scraper.YudowskyPostSectionExtractorTest.java

@Test
public void getPostSectionString_ReadStoredHtml_OutputAsExpected() throws Exception {
    PostExtractionDetails postExtractionDetails = new PostExtractionDetails.Builder().build();
    String htmlString = FileUtils.readFileToString(
            new File(this.getClass().getResource("/Yudkowsky - The Simple Truth.html").toURI()));
    Document doc = Jsoup.parse(htmlString);
    YudowskyPostSectionExtractor instance = new YudowskyPostSectionExtractor();
    String result = instance.getPostSectionString(postExtractionDetails, doc);
    String expResult = FileUtils.readFileToString(
            new File(this.getClass().getResource("/Yudkowsky - The Simple Truth Post Section.txt").toURI()));

    assertTrue(expResult.trim().equals(result.trim()));
}

From source file:com.mirth.connect.model.converters.tests.HL7SerializerTest.java

@Test
public void testToXmlDefault() throws Exception {
    String input = FileUtils.readFileToString(new File("tests/test-hl7-input.txt"));
    String output = FileUtils.readFileToString(new File("tests/test-hl7-output.xml"));
    ER7Serializer serializer = new ER7Serializer(defaultProperties);
    Assert.assertEquals(output, TestUtil.prettyPrintXml(serializer.toXML(input)));
}

From source file:fr.fastconnect.tibco.businessworks.fcunit.AssertXMLEqualTest.java

private String getExpected() throws IOException {
    return FileUtils.readFileToString(new File("src/test/resources/expected.xml"));

}

From source file:com.alta189.bukkit.script.ScriptLoader.java

public Script loadScript(Context context, Scriptable scope, File file) throws Exception {
    String contents = FileUtils.readFileToString(file);
    String name = FilenameUtils.getBaseName(file.getName());

    context.evaluateString(scope, "importPackage(org.bukkit);", name, 1, null);

    if (Bukkit.getPluginManager().getPlugin("Spout") != null) {
        context.evaluateString(scope, "importPackage(org.getspout.spoutapi);", name, 1, null);
    }//from   w w w  . j  a v a 2 s  .com

    context.evaluateString(scope, "var info = {};", name, 1, null);
    context.evaluateString(scope, contents, name, 1, null);

    Scriptable infoObject = CastUtil.safeCast(ScriptableObject.getProperty(scope, "info"));
    ScriptInfo info = new ScriptInfo(infoObject);
    if (info.getName() != null) {
        info.setName(name);
    }

    return new Script(file, info);
}

From source file:com.tunyk.jsonbatchtranslate.api.JsonBatchTranslateTest.java

@BeforeClass
public static void setUp() throws IOException {
    Properties properties = new Properties();
    URL url = ClassLoader.getSystemResource("config.properties");
    properties.load(url.openStream());//from  w w w .ja  v  a  2s .  c o m
    googleTranslateApiKey = properties.getProperty("google.translate.api.key");
    microsoftTranslatorApiKey = properties.getProperty("microsoft.translator.api.key");
    yandexApiKey = null;
    in = FileUtils.readFileToString(new File(ClassLoader.getSystemResource("input.json").getPath()));
}

From source file:github.srlee309.lessWrongBookCreator.scraper.OvercomingBiasPostSectionExtractorTest.java

@Test
public void getPostSectionString_ReadStoredHtmlNoComments_OutputAsExpected() throws Exception {
    PostExtractionDetails postExtractionDetails = new PostExtractionDetails.Builder().build();
    String htmlString = FileUtils.readFileToString(
            new File(this.getClass().getResource("/Overcoming Bias  Does Decadence Cause Decay.html").toURI()));
    Document doc = Jsoup.parse(htmlString);
    OvercomingBiasPostSectionExtractor instance = new OvercomingBiasPostSectionExtractor();
    String result = instance.getPostSectionString(postExtractionDetails, doc);
    String expResult = FileUtils.readFileToString(new File(this.getClass()
            .getResource("/Overcoming Bias  Does Decadence Cause Decay No Comments.txt").toURI()), "UTF-8");

    assertTrue(expResult.trim().equals(result.trim()));
}

From source file:com.aionemu.gameserver.configs.schedule.CrazySchedule.java

public static CrazySchedule load() {
    CrazySchedule ss;// w ww .  j a  v a 2 s  . c  om
    try {
        String xml = FileUtils.readFileToString(new File("./config/schedule/crazy_daeva_schedule.xml"));
        ss = (CrazySchedule) JAXBUtil.deserialize(xml, CrazySchedule.class);
    } catch (Exception e) {
        throw new RuntimeException("Failed to initialize Crazy Daeva Schedule...", e);
    }
    return ss;
}

From source file:com.jdom.word.playdough.model.BaseGamePackResolver.java

public String getGamePackContents(String gamePackFileName) {
    try {/* w  w w  .  j a v a2  s  . co  m*/
        return FileUtils.readFileToString(new File(gamePacksDirectory, gamePackFileName));
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}