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:de.beyondjava.jsf.ajax.differentialContextWriter.differenceEngine.DifferenceEngineTest.java

/**
 * Tests the change of a single attribute.
 *
 * @throws IOException/*w  w w. j  a  v  a 2s.  c o  m*/
 */
// @Test
public void testDetermineNecessaryChanges1() throws IOException {
    final DifferenceEngine diffenceEngine = new DifferenceEngine();
    File dir = new File("src/test/resources/DifferenceEngine");

    final File partialChange = new File(dir, "partialChange1.xml");
    if (partialChange.exists()) {
        String newHTML = FileUtils.readFileToString(partialChange);
        String lastKnownHTML = FileUtils.readFileToString(new File(dir, "html1.xml"));
        HTMLTag lastKnownCorrespondingNode = new HTMLTag(lastKnownHTML);
        List<String> deletions = new ArrayList<String>();
        List<String> attributeChanges = new ArrayList<String>();
        List<String> insertions = new ArrayList<String>();
        List<HTMLTag> updates = new ArrayList<HTMLTag>();
        diffenceEngine.determineNecessaryChanges(new HTMLTag(newHTML), lastKnownCorrespondingNode, updates,
                deletions, attributeChanges, insertions);
        assertNotNull(updates);
        assertEquals(0, updates.size());
        assertEquals(0, deletions.size());
        assertEquals(1, attributeChanges.size());
        String diff1 = attributeChanges.get(0);
        assertEquals(
                "<attributes id=\"formID:cityID\"><attribute name=\"value\" value=\"Jugenheim\"/></attributes>",
                diff1);
    }
}

From source file:com.predic8.membrane.examples.tests.LoggingJDBCTest.java

@Test
public void test() throws IOException, InterruptedException, InstantiationException, IllegalAccessException,
        ClassNotFoundException, SQLException {
    copyDerbyJarToMembraneLib();//from  w w w  .  j a  va2s .c om

    File baseDir = getExampleDir("logging-jdbc");
    File beansConfig = new File(baseDir, "proxies.xml");
    FileUtils.writeStringToFile(beansConfig, FileUtils.readFileToString(beansConfig)
            .replace("org.apache.derby.jdbc.ClientDriver", "org.apache.derby.jdbc.EmbeddedDriver")
            .replace("jdbc:derby://localhost:1527/membranedb;create=true", "jdbc:derby:derbyDB;create=true"));

    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        getAndAssert200("http://localhost:2000/");
    } finally {
        sl.killScript();
    }

    assertLogToDerbySucceeded(baseDir);
}

From source file:com.github.jknack.handlebars.InheritanceTest.java

@Test
public void inheritance() throws IOException {
    try {/*from   www.j  a va  2  s  . c o m*/
        Template template = handlebars.compile(name);
        CharSequence result = template.apply(new Object());
        String expected = FileUtils
                .readFileToString(new File("src/test/resources/inheritance/" + name + ".expected"));
        assertEquals(expected, result);
    } catch (HandlebarsException ex) {
        Handlebars.error(ex.getMessage());
        throw ex;
    }
}

From source file:com.aionemu.commons.scripting.impl.javacompiler.JavaSourceFromFile.java

/**
 * Returns class source represented as string.
 *
 * @param ignoreEncodingErrors not used//from  w w w  . j av  a  2 s  .co  m
 * @return class source
 * @throws IOException if something goes wrong
 */
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
    return FileUtils.readFileToString(new File(this.toUri()));
}

From source file:hudson.init.InitScriptsExecutor.java

private static void execute(File initScript) throws IOException {
    logger.info("Executing " + initScript);
    String script = FileUtils.readFileToString(initScript);
    logger.info(new Script(script).execute());
}

From source file:com.cloud.utils.ProcessUtilTest.java

@Test
public void pidCheck() throws ConfigurationException, IOException {
    Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
    FileUtils.writeStringToFile(pidFile, "123456\n");
    ProcessUtil.pidCheck(pidFile.getParent(), pidFile.getName());
    String pidStr = FileUtils.readFileToString(pidFile);
    Assert.assertFalse("pid can not be blank", pidStr.isEmpty());
    int pid = Integer.parseInt(pidStr.trim());
    int maxPid = Integer.parseInt(FileUtils.readFileToString(new File("/proc/sys/kernel/pid_max")).trim());
    Assert.assertTrue(pid <= maxPid);
}

From source file:architecture.ee.web.struts2.action.admin.ajax.SqlFinderAction.java

public String getTargetFileContent() {
    try {// w  w w  . j  a  v  a 2  s.co  m
        File targetFile = getTargetResource().getFile();
        if (!targetFile.isDirectory()) {
            return FileUtils.readFileToString(targetFile);
        }
    } catch (IOException e) {
        log.error(e);
    }
    return "";
}

From source file:com.ms.commons.test.datareader.impl.YamlReader.java

@Override
@SuppressWarnings("unchecked")
protected MemoryDatabase internalRead(String resourceName) {
    MemoryDatabase result = new MemoryDatabase();
    result.setTableList(new ArrayList<MemoryTable>());
    String absPath = BaseReaderUtil.getAbsolutedPath(resourceName);
    try {//ww  w. java  2s  . c  o  m
        String yamlString = FileUtils.readFileToString(new File(absPath));
        YamlStream<?> ystream = Yaml.loadStream(yamlString);

        for (Object y : ystream) {
            if (!(y instanceof Map<?, ?>)) {
                throw new RuntimeException("Yaml format error: " + absPath);
            }
            Map<String, Object> ym = (Map<String, Object>) y;
            String tableName = (String) TypeConvertUtil.convert(String.class, ym.get("name"));
            if (tableName == null) {
                throw new RuntimeException("Table name is null.");
            }
            MemoryTable mt = new MemoryTable(tableName);
            mt.setRowList(new ArrayList<MemoryRow>());
            Object vss = ym.get("data");
            if (!(vss instanceof Object[][])) {
                throw new RuntimeException("Data is not Object[][], but is:" + vss);
            }
            Object[][] oss = (Object[][]) vss;

            Object[] title = oss[0];

            List<String> titleList = new ArrayList<String>();
            for (int i = 0; i < title.length; i++) {
                titleList.add((String) TypeConvertUtil.convert(String.class, title[i]));
            }

            for (int i = 1; i < oss.length; i++) {
                Object[] row = oss[i];
                if (title.length != row.length) {
                    throw new RuntimeException(
                            "Row " + i + " size is not same to tile, in table: " + tableName);
                }
                List<MemoryField> mfl = new ArrayList<MemoryField>();
                for (int x = 0; x < row.length; x++) {
                    mfl.add(new MemoryField(titleList.get(x), MemoryFieldType.Unknow, row[x]));
                }
                MemoryRow mr = new MemoryRow(mfl);
                mt.getRowList().add(mr);
            }

            result.getTableList().add(mt);
        }
    } catch (FileNotFoundException e) {
        throw new ResourceNotFoundException("Yaml file '" + absPath + "' not found.", e);
    } catch (Exception e) {
        throw new RuntimeException("Error occured while read data from yaml file: " + absPath, e);
    }
    return result;
}

From source file:io.netty.verify.osgi.DependencyIT.java

@Test
public void verifyKarafFeatureHasNoWrapProtocol() throws Exception {
    String text = FileUtils.readFileToString(new File(FEATURE));

    // Ignore wrap:mvn:io.netty - it occurs when Maven didn't give the Netty modules to karaf-maven-plugin
    // as class directories.
    Matcher matcher = WRAPPED_MODULE_PATTERN.matcher(text);
    if (matcher.find()) {
        text = matcher.replaceAll("mvn:io.netty/");
        logger.info("Ignored wrap:mvn:io.netty");
    }/*from  ww  w . j  a  va 2s  . com*/

    if (text.contains("wrap:")) {
        fail("feature.xml generated by karaf-maven-plugin contains 'wrap:' protocol; "
                + "some transitive dependencies are not OSGi bundles: " + StringUtil.NEWLINE + text);
    } else {
        logger.info("All transitive dependencies are OSGi bundles.");
    }
}

From source file:com.switchfly.compress.cli.CompressCLITest.java

@Before
public void setUp() throws Exception {

    _inputLocation = new File(getClass().getResource("asset_packages.yml").getFile()).getParentFile();

    _outputLocation = File.createTempFile("output_", "_TEST");
    if (_outputLocation.exists()) {
        _outputLocation.delete();/*from  w w  w.jav a 2  s.co  m*/
    }
    _outputLocation.mkdir();

    _outputFile = File.createTempFile("output_", "_compressed");
    FileUtils.deleteQuietly(_outputFile);

    _configuration = FileUtils
            .readFileToString(new File(getClass().getResource("asset_packages.yml").getFile()));
}