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.beyondee.faces.diff.XmlDiffTest.java

public List<String> diff(int testNr) {
    try {//from   ww  w . j a v a  2 s . c om
        String oldHTMLString = FileUtils
                .readFileToString(new File("target/test-classes/test" + testNr + "-old.xml"));
        String newHTMLString = FileUtils
                .readFileToString(new File("target/test-classes/test" + testNr + "-new.xml"));
        HTMLTag oldHTMLTag = new HTMLTag(oldHTMLString);
        HTMLTag newHTMLTag = new HTMLTag(newHTMLString);

        List<String> deletions = new ArrayList<>();
        List<String> changes = new ArrayList<>();
        List<String> insertions = new ArrayList<>();

        List<HTMLTag> updates = new ArrayList<>();
        XmlDiff.tagsAreEqualOrCanBeChangedLocally(oldHTMLTag, newHTMLTag, updates, deletions, changes,
                insertions);
        List<String> result = new ArrayList<>();
        result.addAll(deletions);
        result.addAll(changes);
        result.addAll(insertions);
        for (HTMLTag u : updates) {
            result.add(u.toCompactString());
        }
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:de.lgohlke.sonar.maven.XmlReader.java

private String readXmlFromFile(File projectDirectory, String pathToXmlReport) {
    final File xmlReport = new File(projectDirectory, pathToXmlReport);
    try {/*from  w w  w  . j a  va2s. co  m*/
        return FileUtils.readFileToString(xmlReport);
    } catch (IOException e) {
        XmlReader.log.error(e.getMessage(), e);
        throw new IllegalStateException(e);
    }
}

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

public static void runXmlvm(Project project, String[] args, File xmlvmJar) {
    try {/*from   ww  w . j a va2 s .  com*/
        //System.out.println(getProject().getProperties());
        //System.out.println(this.getClassPath());
        //System.out.println(System.getProperties());
        Java j = (Java) project.createTask("java");
        j.setMaxmemory("2G");
        j.setJar(xmlvmJar);
        //j.setFailonerror(true);
        File log = File.createTempFile("foo", "bar");
        j.setOutput(log);
        j.setFork(true);
        for (String arg : args) {
            Commandline.Argument a = j.createArg();
            a.setValue(arg);

        }
        System.out.println("About to execute XMLVM...");
        for (int i = 0; i < args.length; i++) {
            System.out.println("ARG: " + args[i]);
        }
        j.execute();
        System.out.println(FileUtils.readFileToString(log));
        System.out.println("Finished execution of XMLVM");
    } catch (IOException ex) {
        Logger.getLogger(XMLVM.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:de.felixschulze.maven.plugins.xcode.xcodeprojparser.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);
            }/* w w  w . j  a  v  a2  s. c om*/
        }
    }
    if (targets != null) {
        return new PBXProject(targets);
    }
    return null;
}

From source file:ezbake.security.client.EzbakeMockSecurityClientTest.java

@BeforeClass
public static void setUp() throws Exception {
    properties = new Properties();
    properties.setProperty(EzBakeSecurityClientConfigurationHelper.USE_MOCK_KEY, String.valueOf(true));
    properties.setProperty(EzBakeSecurityClientConfigurationHelper.MOCK_USER_KEY, DN);
    properties.setProperty(TokenProvider.CLIENT_MODE, TokenProvider.ClientMode.Dev.getValue());
    serverPrivateKey = FileUtils.readFileToString(new File(serverPrivatePath));
}

From source file:com.github.lucene.store.CreateJavaTestIndex.java

private static Document getDocument(final String rootDir, final File file) throws IOException, ParseException {
    final String fileName = file.getName();
    final String filePath = file.getAbsolutePath();
    final String content = FileUtils.readFileToString(file);

    System.out.println(fileName + ":" + filePath + "\n---------");

    final Document doc = new Document();
    doc.add(new StringField("fileName", fileName, Field.Store.YES));
    doc.add(new StringField("filePath", filePath, Field.Store.YES));
    doc.add(new TextField("content", content, Field.Store.NO));
    return doc;/* w  w  w .  jav a 2 s . c om*/
}

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

@Test
public void getPostSectionString_NoComments_StringCorrect() throws Exception {
    PostExtractionDetails postExtractionDetails = new PostExtractionDetails.Builder().build();
    String htmlString = FileUtils.readFileToString(
            new File(this.getClass().getResource("/Sorting Out Sticky Brains - Less Wrong.html").toURI()));
    Document doc = Jsoup.parse(htmlString);
    LessWrongPostSectionExtractor instance = new LessWrongPostSectionExtractor();
    String expResult = FileUtils.readFileToString(new File(
            this.getClass().getResource("/Sorting Out Sticky Brains - Less Wrong No Comments.txt").toURI()));
    String result = instance.getPostSectionString(postExtractionDetails, doc);

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

From source file:Business.TexFiedSet.java

@Override
public void actionPerformed(ActionEvent ae) {

    try {//from  www  .  jav a  2s. co  m

        String content = FileUtils.readFileToString(file);
        //            String content1 = content.replaceAll("[\\\t|\\\n|\\\r]", " ");
        txtArea.setText(content);
        MainJFrame.highlight(txtArea);
    } catch (IOException ex) {
        Logger.getLogger(TexFiedSet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:gov.nih.nci.cacis.ip.xds.DefaultXdsMetadataSupplierTest.java

/**
 * //from  w  w w  . j  ava  2s .  com
 * @throws IOException exception
 * @throws URISyntaxException exception
 * @throws JAXBException 
 */
@Test
public void createMetadata() throws IOException, JAXBException, URISyntaxException {

    final File file = new File(
            getClass().getClassLoader().getResource("caCISRequest_With_RoutingInstructions.xml").toURI());

    final String docEntryMetadata = defaultXdsMetadataSupplier.createDocEntry(FileUtils.readFileToString(file));

    assertTrue(docEntryMetadata.contains("HLv2 OBX Message"));
    assertTrue(docEntryMetadata.contains("DM123456"));

    assertNotNull(docEntryMetadata);

    final String submissionSetMetadata = defaultXdsMetadataSupplier
            .createSubmissionSet(FileUtils.readFileToString(file));
    assertNotNull(submissionSetMetadata);
    assertTrue(docEntryMetadata.contains("DM123456"));

    assertNotNull(defaultXdsMetadataSupplier.createDocOID());
    assertNotNull(defaultXdsMetadataSupplier.createDocSourceOID());
}

From source file:com.door43.translationstudio.core.TargetTranslationMigrator.java

/**
 * Performs a migration on a manifest object.
 * We just throw it into a temporary directory and run the normal migration on it.
 * @param manifestJson/*from ww w.  j a v  a2  s .com*/
 * @return
 */
public static JSONObject migrateManifest(JSONObject manifestJson) {
    File tempDir = new File(AppContext.context().getCacheDir(), System.currentTimeMillis() + "");
    // TRICKY: the migration can change the name of the translation dir so we nest it to avoid conflicts.
    File fakeTranslationDir = new File(tempDir, "translation");
    fakeTranslationDir.mkdirs();
    JSONObject migratedManifest = null;
    try {
        FileUtils.writeStringToFile(new File(fakeTranslationDir, "manifest.json"), manifestJson.toString());
        fakeTranslationDir = migrate(fakeTranslationDir);
        if (fakeTranslationDir != null) {
            migratedManifest = new JSONObject(
                    FileUtils.readFileToString(new File(fakeTranslationDir, "manifest.json")));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // clean up
        FileUtils.deleteQuietly(tempDir);
    }
    return migratedManifest;
}