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.mirth.connect.plugins.datatypes.edi.test.EDISerializerTest.java

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

From source file:com.photon.phresco.framework.commons.XcodeprojParser.java

public PBXProject parseXcodeFile() throws IOException, JSONException {
    String content = FileUtils.readFileToString(xcodprojJsonFile);
    JSONObject object = new JSONObject(content);
    JSONObject objects = object.getJSONObject("objects");

    String[] mainNames = JSONObject.getNames(objects);
    List<PBXNativeTarget> targets = null;
    for (String name : mainNames) {
        JSONObject currentObject = objects.getJSONObject(name);
        if (currentObject.has("isa")) {
            String isa = currentObject.getString("isa");
            if (isa.equalsIgnoreCase("PBXProject")) {
                List<String> targetRefs = getTargetRefs(currentObject);
                targets = getTargetsFromRefs(targetRefs, objects, currentObject);
            }/*from  www.  j  a  v  a2s .c  o m*/
        }
    }
    if (targets != null) {
        PBXProject project = new PBXProject(targets);
        return project;
    }
    return null;
}

From source file:com.aionemu.packetsamurai.parser.valuereader.ClientStringReader.java

public static void load() {
    //PacketSamurai.getUserInterface().log("Loading Client strings... Please wait.");
    Util.drawTitle("Client Strings");
    File stringsFolder = new File("./data/client_strings");
    if (!stringsFolder.exists()) {
        stringsFolder.mkdir();//from  w w w  .  ja v  a  2 s . c o  m
    }
    try {
        File[] files = stringsFolder.listFiles();
        File[] arrayOfFile1;
        int j = (arrayOfFile1 = files).length;
        for (int i = 0; i < j; i++) {
            File sFile = arrayOfFile1[i];
            File xml = new File(sFile.getPath());

            String stringFile = FileUtils.readFileToString(xml);
            String[] strings = StringUtils.substringsBetween(stringFile, "<string>", "</string>");
            if (strings != null) {
                String[] arrayOfString1;
                int m = (arrayOfString1 = strings).length;
                for (int k = 0; k < m; k++) {
                    String string = arrayOfString1[k];
                    int stringId = Integer.parseInt(StringUtils.substringBetween(string, "<id>", "</id>"));
                    String stringBody = StringUtils.substringBetween(string, "<body>", "</body>");
                    stringsById.put(Integer.valueOf(stringId), stringBody);
                }
            }
        }
        PacketSamurai.getUserInterface().log(
                "Strings [Client] - Loaded " + stringsById.size() + " strings from " + files.length + " Files");
    } catch (IOException e) {
        PacketSamurai.getUserInterface().log("ERROR: Failed to load client_strings.xsd: " + e.toString());
        e.printStackTrace();
    }
}

From source file:com.impetus.ankush.agent.utils.XMLUtils.java

/**
 * Method to get an XML Object for the given class type from the provided
 * XML configuration file ./*from  w w  w.j  av a2 s .  co  m*/
 * 
 * @param <S>
 *            The class name for which XML object needs to be returned.
 * @param filePath
 *            File Path of XML file.
 * @param className
 *            Class name of returning object.
 * @return The Object of provided class
 * @throws Exception
 */
public static <S> S getXMLObject(String filePath, Class<S> className) throws Exception {
    // java XML context object.
    JAXBContext jc = JAXBContext.newInstance(className);
    // file.
    File file = new File(filePath);
    if (file.exists()) {
        // if file exists read the file content.
        String fileContent = FileUtils.readFileToString(file);
        // if not empty then unmarshal the object.
        if (!fileContent.isEmpty()) {
            // Creating unmarshaller
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            // Getting component services
            S object = (S) unmarshaller.unmarshal(file);
            // returning object.
            return object;
        }
    }
    return null;
}

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

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

From source file:com.cloudant.mazha.OpenRevisionTest.java

@Test
public void deserialization_ok() throws IOException {
    String s = FileUtils.readFileToString(new File("fixture/open_revisions_ok.json"));
    List<OpenRevision> openRevisionList = jsonHelper.fromJson(new StringReader(s),
            new TypeReference<List<OpenRevision>>() {
            });//from  w w  w .j  av  a 2 s  .  co m
    Assert.assertThat(openRevisionList, hasSize(1));
    Assert.assertTrue(openRevisionList.get(0) instanceof OkOpenRevision);
    DocumentRevs documentRevs = ((OkOpenRevision) openRevisionList.get(0)).getDocumentRevs();
    Assert.assertEquals("a", documentRevs.getId());
    Assert.assertEquals("1-a", documentRevs.getRev());
}

From source file:github.srlee309.lessWrongBookCreator.bookGeneration.SummaryHtmlCreatorTest.java

@Test
public void createSummaryPage_BookSummarySection_OutputHtmlAsExpected() throws Exception {
    String expectedHtmlString = FileUtils
            .readFileToString(new File(this.getClass().getResource("/summaryTOC.html").toURI()));
    SummaryHtmlCreator summaryHtmlCreator = new SummaryHtmlCreator();
    ArrayList<PostSummarySection> expectedPostSections = new ArrayList<PostSummarySection>();
    expectedPostSections.add(new PostSummarySection("What Do We Mean By \"Rationality\"?",
            "http://lesswrong.com/lw/31/what_do_we_mean_by_rationality/",
            "When we talk about rationality, we're generally talking about either epistemic rationality (systematic methods of finding out the truth) or instrumental rationality (systematic methods of making the world more like we would like it to be). We can discuss these in the forms of probability theory and decision theory, but this doesn't fully cover the difficulty of being rational as a human. There is a lot more to rationality than just the formal theories."));
    expectedPostSections.add(new PostSummarySection("Feeling Rational",
            "http://lesswrong.com/lw/hp/feeling_rational/",
            "Strong emotions can be rational.  A rational belief that something good happened leads to rational happiness.  But your emotions ought not to change your beliefs about events that do not depend causally on your emotions."));
    ArrayList<SequenceSummarySection> expectedSequenceSections = new ArrayList<SequenceSummarySection>();
    expectedSequenceSections.add(new SequenceSummarySection("Predictably Wrong", "Sequence on cognitive bias",
            expectedPostSections));//from w ww.  j  a  va 2  s .  c  o m
    ArrayList<BookSummarySection> bookSections = new ArrayList<BookSummarySection>();
    String bookSectionSummary = "<ul>\n" + "   <li>'What is rationality?</li>\n"
            + "   <li>'What does it really mean to be rational?'</li>\n"
            + "   <li>'Why is is valuable to care about the truth?'</li>\n" + "</ul>";
    bookSections.add(new BookSummarySection("Map and Territory", bookSectionSummary, expectedSequenceSections));
    summaryHtmlCreator.createSummaryPage(bookSections);
    String resultHtmlString = FileUtils.readFileToString(new File("htmlOutput/summaryTOC.html"));
    assertTrue(resultHtmlString.equals(expectedHtmlString));
}

From source file:com.cloudant.mazha.DocumentRevsTest.java

@Test(expected = RuntimeException.class)
public void deserialization_unknownSpecialField() throws IOException {
    String s = FileUtils.readFileToString(new File("fixture/document_revs_with_unknown_special_field.json"));
    jsonHelper.fromJson(new StringReader(s), DocumentRevs.class);
}

From source file:io.kahu.hawaii.sso.util.FileJsonWebKeySetRepository.java

public FileJsonWebKeySetRepository(File file) throws IOException, ParseException {
    String jwks = FileUtils.readFileToString(file);
    this.jsonWebKeySet = JWKSet.parse(jwks);
}

From source file:com.mirth.connect.plugins.datatypes.ncpdp.test.NCPDPSerializerTest.java

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