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:aurelienribon.texturepackergui.Project.java

public static Project fromFile(File file) throws IOException {
    Project prj = load(FileUtils.readFileToString(file));
    if (!prj.input.equals(""))
        prj.input = new File(file.getParent(), prj.input).getCanonicalPath();
    if (!prj.output.equals(""))
        prj.output = new File(file.getParent(), prj.output).getCanonicalPath();
    return prj;// w  w  w  .  ja  v a  2 s . co  m
}

From source file:hu.bme.mit.trainbenchmark.benchmark.sqlite.driver.SQLiteDriver.java

@Override
public void read(final String modelPath) throws IOException, InterruptedException, SQLException {
    final File modelFile = new File(modelPath);
    if (!modelFile.exists()) {
        throw new IOException("Model does not exist: " + modelPath);
    }//from  ww  w  .  j  a v  a  2s.  com

    connection = DriverManager.getConnection("jdbc:sqlite::memory:");
    final Statement statement = connection.createStatement();
    statement.setQueryTimeout(3600);

    final String sql = FileUtils.readFileToString(new File(modelPath));
    statement.executeUpdate(sql);

    // create temporary table (used by the transformations)
    final PreparedStatement createStatement = connection
            .prepareStatement("CREATE TEMP TABLE IF NOT EXISTS Variables (Name TEXT PRIMARY KEY, Value LONG);");
    createStatement.execute();
}

From source file:io.proleap.vb6.runner.impl.VbParseTestRunnerImpl.java

protected void doCompareParseTree(final File treeFile, final StartRuleContext startRule,
        final VisualBasic6Parser parser) throws IOException {

    final String treeFileData = FileUtils.readFileToString(treeFile);

    if (!Strings.isBlank(treeFileData)) {
        LOG.info("Comparing parse tree with file {}.", treeFile.getName());

        final String inputFileTree = Trees.toStringTree(startRule, parser);
        final String cleanedInputFileTree = io.proleap.vb6.util.StringUtils.cleanFileTree(inputFileTree);
        final String cleanedTreeFileData = io.proleap.vb6.util.StringUtils.cleanFileTree(treeFileData);

        assertEquals(cleanedTreeFileData, cleanedInputFileTree);
    } else {/* ww w.j a  v  a 2s.  c o  m*/
        LOG.info("Ignoring empty parse tree file {}.", treeFile.getName());
    }
}

From source file:com.sangupta.codefix.FixCopyright.java

@Override
protected void beforeProcessing() {
    try {//  w  w  w . ja  v a 2  s .c  o m
        this.copyrightNotice = FileUtils.readFileToString(new File(this.copyrightFile));
    } catch (IOException e) {
        System.out.println("Unable to read copyright notice from file: " + this.copyrightFile);
        return;
    }
}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.core.wrapper.BaselineExtractorTest.java

@Ignore
@Test/*  www . j  av a2 s  .  c  om*/
public void baselineTest() throws Exception {

    String testDoc = FileUtils.readFileToString(new File("src/test/resources/keyphrase/extractor/test.txt"));

    Candidate nounTokens = new Candidate(CandidateType.Token, PosType.N);

    KeyphraseExtractor_ImplBase positionBaselineExtractor = new PositionBaselineExtractor();
    positionBaselineExtractor.setCandidate(nounTokens);

    String actualKeyphrases = StringUtils.join(
            keyphraseList2StringList(getTopRankedKeyphrases(positionBaselineExtractor.extract(testDoc), 5)),
            ",");

    assertEquals("MPEG,video,rate allocation,rates,bit allocation", actualKeyphrases);
}

From source file:gov.nih.nci.cacis.mirth.XSLForMirthFormatterTest.java

/**
 * Tests the xsl formatter/*from   ww  w.  j  a va  2s. c  om*/
 * @throws IOException io error thrown, if any
 * @throws URISyntaxException error thrown, if any
 */
@Test
public void checkFormatter() throws IOException, URISyntaxException {
    final String origXslFile = getClass().getClassLoader().getResource("sample.xsl").getFile();
    final File xslFile = new File(origXslFile);
    final String xslFileNm = xslFile.getName();
    final String outputDir = xslFile.getParent() + "/formatted/";
    final String[] args = { outputDir, origXslFile };
    XSLForMirthFormatter.main(args);

    final File actualFrmtdXsl = new File(outputDir + xslFileNm);
    assertTrue(actualFrmtdXsl.exists());

    final String actualFrmtdXslContent = FileUtils.readFileToString(actualFrmtdXsl);
    assertNotNull(actualFrmtdXslContent);

    final String expectedFrmtdXsl = getClass().getClassLoader().getResource("sample.formatted").getFile();
    final String expectedFrmtdXslContent = FileUtils.readFileToString(new File(expectedFrmtdXsl));
    assertNotNull(expectedFrmtdXslContent);

    assertEquals(expectedFrmtdXslContent, actualFrmtdXslContent);

}

From source file:de.tudarmstadt.ukp.dkpro.core.flextag.model.InstallAsMavenArtifact.java

private static String prepareBuildScript(String modelLocation, String groupId, String artifactId,
        String version, String tool, String language, String variant, String targetName,
        String workingDirectory, String modelencoding, String postagset) throws IOException {

    String buildFile = FileUtils.readFileToString(new File("src/main/resources/build.xml"));
    buildFile = buildFile.replaceAll("#TARGETNAME#", targetName);
    buildFile = buildFile.replaceAll("#MODELLOCATION#", modelLocation);
    buildFile = buildFile.replaceAll("#GROUPID#", groupId);
    buildFile = buildFile.replaceAll("#ARTIFACTID#", artifactId);
    buildFile = buildFile.replaceAll("#DATE#", version);
    buildFile = buildFile.replaceAll("#VERSION#", "1");
    buildFile = buildFile.replaceAll("#TOOL#", tool);
    buildFile = buildFile.replaceAll("#LANGUAGE#", language);
    buildFile = buildFile.replaceAll("#VARIANT#", variant);
    buildFile = buildFile.replaceAll("#ENCODING#", modelencoding);
    buildFile = buildFile.replaceAll("#POSTAGSET#", postagset);
    return buildFile;
}

From source file:me.ryandowling.NowPlayingConverter.java

private void updateFiles() {
    try {//from  ww w . j a v  a2  s .c o  m
        String nowPlaying = FileUtils.readFileToString(Utils.getNowPlayingRawPath().toFile());
        String[] parts = nowPlaying.split("\\|\\|\\|");

        if (parts.length == 2) {
            FileUtils.write(Utils.getNowPlayingPath().toFile(), parts[0]);
            FileUtils.write(Utils.getNowPlayingFilePath().toFile(), parts[1]);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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

@Test
public void test51RequestFromXml() throws Exception {
    String input = FileUtils.readFileToString(new File("tests/test-ncpdp-51-request-output.xml"));
    String output = FileUtils.readFileToString(new File("tests/test-ncpdp-51-request-input.txt"));
    NCPDPSerializer serializer = new NCPDPSerializer(defaultProperties);
    Assert.assertEquals(output, serializer.fromXML(input));
}

From source file:hu.bme.mit.trainbenchmark.benchmark.neo4j.queries.cypher.Neo4jCypherQuery.java

public Neo4jCypherQuery(final Neo4jDriver driver, final String workspaceDir, final RailwayQuery query)
        throws IOException {
    super(query, driver);

    this.query = query;
    this.queryDefinition = FileUtils.readFileToString(new File(workspaceDir + Neo4jConstants.CYPHER_DIR
            + "queries/" + query + "." + Neo4jConstants.QUERY_EXTENSION));
}