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:com.liferay.cucumber.util.FileUtil.java

public static String read(File file) throws IOException {
    return FileUtils.readFileToString(file);
}

From source file:com.athena.meerkat.controller.web.provisioning.util.ProvisioningUtil.java

public static int getJobNum(File jobBaseDir) throws IOException {
    File jobFile = new File(jobBaseDir.getAbsolutePath() + File.separator + JOB_NUM_FILE_NAME);
    int jobNum = 0;

    if (jobFile.exists()) {
        jobNum = Integer.parseInt(FileUtils.readFileToString(jobFile));
    }/*w ww  .  j  ava2  s.c  om*/

    FileUtils.writeStringToFile(jobFile, String.valueOf(++jobNum));

    return jobNum;
}

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

@Test
public void testToXml1() throws Exception {
    String input = Base64//from  w  w  w.  j  av a 2s.c om
            .encodeBase64String(FileUtils.readFileToByteArray(new File("tests/test-dicom-input-1.dcm")));
    String output = FileUtils.readFileToString(new File("tests/test-dicom-output-1.xml"));
    DICOMSerializer serializer = new DICOMSerializer();
    Assert.assertEquals(output, TestUtil.prettyPrintXml(serializer.toXML(input)));
}

From source file:jp.co.opentone.bsol.linkbinder.CorresponBodyUpdater.java

static void execute(PreparedStatement stmt) throws Exception {
    String dir = "100506-Body???/??Body";

    stmt.setString(1, FileUtils.readFileToString(new File(dir, "ID6564LOG.txt")));
    stmt.setLong(2, 1093);/*from www.j  a  v a2s . c o m*/
    stmt.executeUpdate();

    stmt.setString(1, FileUtils.readFileToString(new File(dir, "ID6565LOG.txt")));
    stmt.setLong(2, 1094);
    stmt.executeUpdate();

    stmt.setString(1, FileUtils.readFileToString(new File(dir, "ID6661LOG.txt")));
    stmt.setLong(2, 1095);
    stmt.executeUpdate();
}

From source file:ca.weblite.xmlvm.VtableHelper.java

/**
 * Tries to find the actual function to use for the given mangled method name in the 
 * given header file./* ww w .ja  va  2 s  .c om*/
 * @param searchPaths  The paths to search for headers.
 * @param headerFile The header file in which to start the search.  Its name is used
 * as the base for the mangled function name.
 * @param mangledMethodName The mangled method name.  This should only be the portion
 * pertaining to the method - not the class portion of a mangled function name.  It will
 * be concatenated to headerFile.getName()+"_" to form the full function name.
 * @return Either a VTable ID (which will have the form XMLVM_VTABLE_IDX_{funcname}) or
 * the actual function name if there is no vtable index constant defined.
 * @throws IOException 
 */
public static String resolveVirtualMethod(Project project, Path searchPaths, File headerFile,
        String mangledMethodName) throws IOException {
    String mangledClassName = headerFile.getName().replaceAll("\\.h$", "");
    String funcName = mangledClassName + "_" + mangledMethodName;
    String headerContents = FileUtils.readFileToString(headerFile);
    Scanner scanner = new Scanner(headerContents);
    int state = 0;
    String superClassHeader = null;
    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        if (state == 0 && line.startsWith("// Super Class:")) {
            state = 1;
        } else if (state == 1 && line.startsWith("#include \"")) {
            superClassHeader = line.substring(line.indexOf("\"") + 1, line.lastIndexOf("\""));
            state = 0;
            break;
        }
    }

    String idxConstant = "XMLVM_VTABLE_IDX_" + funcName;
    String idxConstantSp = idxConstant + " ";
    if (headerContents.indexOf(idxConstantSp) > 0) {
        return idxConstant;
    } else if (headerContents.indexOf(funcName + "(") > 0) {
        return funcName;
    } else if (superClassHeader != null) {
        for (String p : searchPaths.list()) {
            File d = new File(p);
            File h = new File(d, superClassHeader);
            if (h.exists()) {
                return resolveVirtualMethod(project, searchPaths, h, mangledMethodName);
            }
        }
        throw new RuntimeException("Failed to find header file " + superClassHeader);
    } else {
        throw new RuntimeException(
                "Failed to find virtual method " + mangledMethodName + " in header " + headerFile);
    }
}

From source file:ch.sbb.releasetrain.state.StateFileReader.java

public ReleaseState read(String releaseIdentifier) {
    try {/*from  ww  w. j a  v  a 2s.co  m*/
        File file = file(releaseIdentifier);

        if (!file.exists()) {
            log.debug("File %s not existing", file);
            return null;
        }

        return converter.convertEntry(FileUtils.readFileToString(file));
    } catch (IOException e) {
        throw new RuntimeException(String.format("Error reading state from file %s", file(releaseIdentifier)),
                e);
    }
}

From source file:com.mirth.connect.plugins.datatypes.edi.test.EDISerializerTest.java

@Test
public void testToXml() throws Exception {
    String input = FileUtils.readFileToString(new File("tests/test-edi-input.txt"));
    String output = FileUtils.readFileToString(new File("tests/test-edi-output.xml"));
    EDISerializer serializer = new EDISerializer(new EDIDataTypeProperties().getSerializerProperties());
    Assert.assertEquals(output, serializer.toXML(input));
}

From source file:com.lunix.cheata.utils.file.FileManager.java

public static String readFile(String fileName) {
    try {//from  ww  w  .ja  va  2 s.  c o m
        File file = new File(getDir().getAbsolutePath(), fileName);
        String fileContents;
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(new DataInputStream(new FileInputStream(file))));
        fileContents = FileUtils.readFileToString(file);
        reader.close();
        return fileContents;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return "";
}

From source file:com.BuildCraft.utils.Settings.java

public boolean loadSettings() {
    String fileData = "";
    String[] parseData = null;//from  w ww . ja  v  a2s  .  c  o m
    boolean operationCompleted = true;
    boolean lengthMatch = true;

    try {
        fileData = FileUtils.readFileToString(file);
    } catch (IOException ex) {
        ConsoleOut.printMsg("Settings: Warning: Failed to load " + file.getName());
        operationCompleted = false;
    }

    parseData = fileData.split("\n");

    if (parseData.length != aKeys.length) {
        ConsoleOut.printMsg("Settings: Warning: Invalid settings file for defined keys!");
        operationCompleted = false;
        lengthMatch = false;
    }

    if (lengthMatch) {
        for (int i = 0; i < parseData.length; i++) {
            if (aKeys[i] != null) {
                aValues = ArrayUtils.appendToArray(aValues, parseData[i].replace(aKeys[i] + "=", ""));
            }
        }
    }
    return operationCompleted;
}

From source file:SimpleJdomExamples.java

@Test
public void ParseSimpleExample() throws Exception {
    final String jsonText = FileUtils
            .readFileToString(new File(this.getClass().getResource("SimpleExample.json").getFile()));
    String secondSingle = new JdomParser().parse(jsonText).getStringValue("singles", 1);
    assertThat(secondSingle, equalTo("Agadoo"));
}