Example usage for org.apache.commons.io FileUtils writeStringToFile

List of usage examples for org.apache.commons.io FileUtils writeStringToFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils writeStringToFile.

Prototype

public static void writeStringToFile(File file, String data) throws IOException 

Source Link

Document

Writes a String to a file creating the file if it does not exist using the default encoding for the VM.

Usage

From source file:edu.lternet.pasta.portal.search.BrowseGroup.java

public static void main(String[] args) {
    String browseDir = "/home/pasta/local/browse";
    BrowseGroup controlledVocabulary = null;
    String xmlString = null;/* w ww.j  a va2s. co  m*/
    String htmlString = null;
    File browseCacheFile = null;

    controlledVocabulary = generateKeywordCache();

    if (controlledVocabulary != null) {
        xmlString = controlledVocabulary.toXML();
        htmlString = controlledVocabulary.toHTML();
        browseCacheFile = new File(String.format("%s/browseKeyword.xml", browseDir));
        try {
            FileUtils.writeStringToFile(browseCacheFile, xmlString);
        } catch (Exception e) {
            e.printStackTrace();
        }
        browseCacheFile = new File(String.format("%s/browseKeyword.html", browseDir));
        try {
            FileUtils.writeStringToFile(browseCacheFile, htmlString);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.err.println("Generation of keyword browse cache and HTML completed.");
    } else {
        System.err.println("Generation of keyword browse cache failed.");
    }
}

From source file:launcher.License.java

public static void cache(String license) {
    if (!isCached()) {
        try {/*from  w w  w  .ja va2 s . co  m*/
            FileUtils.writeStringToFile(Cache, license);
        } catch (IOException e) {
            LaunchLogger.error("There was a problem caching your license.");
            LaunchLogger.exception(e);
        }
    }
}

From source file:ch.oakmountain.tpa.web.TpaPersistorUtils.java

public static void copyFromResourceToDir(String fileName, String outputDir) throws IOException {
    String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream(File.separator + fileName));
    FileUtils.writeStringToFile(new File(outputDir + File.separator + fileName), content);
}

From source file:com.thoughtworks.go.config.GuidService.java

public static void storeGuid(String guid) {
    try {/*from   ww w .j av  a2 s  .c  o m*/
        AGENT_GUID_FILE.delete();
        FileUtils.writeStringToFile(AGENT_GUID_FILE, guid);
    } catch (IOException ioe) {
        throw bomb("Couldn't save GUID to filesystem", ioe);
    }
}

From source file:cc.kave.episodes.export.EventStreamIo.java

public static void write(EventStream stream, String fileStream, String fileMapping) {
    try {//from   w w  w . j  a  va  2  s  . c o  m
        FileUtils.writeStringToFile(new File(fileStream), stream.getStream());
        JsonUtils.toJson(stream.getMapping().keySet(), new File(fileMapping));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:ch.oakmountain.tpa.web.TpaPersistorUtils.java

public static void copyFromResourceToDir(String fileName, String outputDir, String prefix) throws IOException {
    String content = IOUtils.toString(
            TpaWebPersistor.class.getResourceAsStream(File.separator + prefix + File.separator + fileName));
    FileUtils.writeStringToFile(new File(outputDir + File.separator + prefix + File.separator + fileName),
            content);/*from  w  ww  .j a v a  2s  . c o  m*/
}

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

public void write(final ReleaseState releaseState) {
    try {//from  www  . jav  a  2s. com
        FileUtils.writeStringToFile(file(releaseState.retreiveIdentifier()),
                converter.convertEntry(releaseState));
    } catch (IOException e) {
        throw new RuntimeException(
                String.format("Error writing state to file %s", file(releaseState.retreiveIdentifier())), e);
    }
}

From source file:com.buildautomation.jgit.api.CreateListApplyAndDropStash.java

public static void createListApplyAndDropStash() throws IOException, GitAPIException {
    // prepare a new test-repository
    try (Repository repository = CookbookHelper.createNewRepository()) {
        try (Git git = new Git(repository)) {
            // create a file
            File file1 = new File(repository.getDirectory().getParent(), "testfile");
            FileUtils.writeStringToFile(file1, "some text");
            File file2 = new File(repository.getDirectory().getParent(), "testfile2");
            FileUtils.writeStringToFile(file2, "some text");

            // add and commit the file
            git.add().addFilepattern("testfile").call();
            git.add().addFilepattern("testfile2").call();
            git.commit().setMessage("Added testfiles").call();

            // then modify the file
            FileUtils.writeStringToFile(file1, "some more text", true);

            // push the changes to a new stash
            RevCommit stash = git.stashCreate().call();

            System.out.println("Created stash " + stash);

            // then modify the 2nd file
            FileUtils.writeStringToFile(file2, "some more text", true);

            // push the changes to a new stash
            stash = git.stashCreate().call();

            System.out.println("Created stash " + stash);

            // list the stashes
            Collection<RevCommit> stashes = git.stashList().call();
            for (RevCommit rev : stashes) {
                System.out.println("Found stash: " + rev + ": " + rev.getFullMessage());
            }/*from   ww w.j  a  v a2  s .c o  m*/

            // drop the 1st stash without applying it
            ObjectId call = git.stashDrop().setStashRef(0).call();
            System.out.println("StashDrop returned: " + call);

            ObjectId applied = git.stashApply().setStashRef(stash.getName()).call();
            System.out.println("Applied 2nd stash as: " + applied);
        }
    }
}

From source file:fr.cntcnc.migration.html4joomla1to3.CNTparser.java

public static void imprimeurArticles(String listeArticles, String nomFichier) {
    try {//from   w  w w  . j  a  v a2 s  . com
        //        entre : String[] listeArticles ...   String articleComplet = "";
        //        concatnation des sous article
        //        for (String listeArticle : listeArticles) {
        //            articleComplet+=listeArticle;
        //        }
        FileUtils.writeStringToFile(new File(nomFichier + ".txt"), listeArticles);
        System.out.println("---- Impression de l'article ---" + nomFichier + ".txt");
    } catch (IOException ex) {
        Logger.getLogger(CNTparser.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.dianping.phoenix.dev.core.tools.generator.stable.GitRepositoryListGenerator.java

private static void persist(List<ProjectRepositoryPair> pairs, File file) throws Exception {
    StringBuilder content = new StringBuilder();
    for (ProjectRepositoryPair pair : pairs) {
        content.append(pair.name).append("=").append(pair.repoUrl).append("\n");
    }//from w  ww  . j ava2  s.  c  om
    FileUtils.writeStringToFile(file, content.toString());
}