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:de.tudarmstadt.ukp.argumentation.data.roomfordebate.DataFetcher.java

/**
 * Crawls all URLs from the given list and stores them in the output folder; files that
 * already exist in the output folder are skipped
 *
 * @param urls      list of urls for Room for debate
 * @param outputDir output/*www .  jav  a  2 s  .  co m*/
 * @throws IOException ex
 */
public static void crawlPages(List<String> urls, File outputDir) throws IOException {
    for (String url : urls) {
        // file name
        File outFile = new File(outputDir, URLEncoder.encode(url, "utf-8") + ".html");

        if (!outFile.exists()) {
            NYTimesCommentsScraper nyTimesCommentsScraper = new NYTimesCommentsScraper();

            String html;
            try {
                html = nyTimesCommentsScraper.readHTML(url);
            } catch (InterruptedException e) {
                throw new IOException(e);
            }

            FileUtils.writeStringToFile(outFile, html);
        }
    }
}

From source file:com.liferay.cucumber.util.FileUtil.java

public static void write(File file, String string) throws IOException {
    FileUtils.writeStringToFile(file, string);
}

From source file:net.sasasin.sreader.batch.publish.HtmlPublisher.java

@Override
public void finalize() {
    s.append("</body><html>");
    try {//from   w w w  . j  av  a  2 s  .  c  om
        FileUtils.writeStringToFile(
                new File(System.getProperty("user.home") + File.separatorChar + "sreader.html"), s.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Comitter.java

public void processPhrase(String phrase) {

    char[][] fonts = Fonts.getFonts();
    char character;
    int i;//from  w w w  . ja v a 2 s  . c o m

    for (i = 0; i < phrase.length(); i++) {
        character = phrase.charAt(i);
        output += processCharacter(fonts[character], i);
        System.out.println();
    }
    output += "git remote add origin https://github.com/testcomitter/qqq.git\n" + "git push -u origin master\n";

    File file = new File("/home/gabriel/Code/sh/asd.sh");
    try {
        FileUtils.writeStringToFile(file, output);
    } catch (IOException ex) {
        Logger.getLogger(Comitter.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println(output);
}

From source file:ezbake.security.persistence.model.TestCAPersistenceModel.java

@Before
public void setUpFileSystem() throws IOException {
    String root = folder.getRoot().toString();

    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "", "ca", "certificate", "", "data")),
            "my certificate");
    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "", "ca", "private_key", "", "data")),
            "my private key");
    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "", "ca", "serial", "", "data")), "100");
    ezPersist = new FilePersist(root);
}

From source file:ezbake.persist.TestFilePersist.java

@Before
public void setUpFileSystem() throws IOException {
    String root = folder.getRoot().toString();
    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "", "test", "", "", "data")), "1");
    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "", "test", "colf", "", "data")), "2");
    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "", "test", "colf", "colq", "data")), "3");

    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "", "test2", "", "", "data")), "1");
    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "", "test2", "colf", "", "data")), "2");
    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "", "test2", "colf", "colq", "data")), "3");

    FileUtils.writeStringToFile(new File(FilePersist.joinPath(root, "lookup", "table", "colf", "colq", "data")),
            "3");

    persist = new FilePersist(root);
}

From source file:ch.sbb.releasetrain.config.model.releaseconfig.ReleaseConfigSerializerTest.java

@Test
public void testSerializeReleaseConfig() throws Exception {

    ReleaseConfig release = new ReleaseConfig();
    release.setTyp("devType");
    ActionConfig action = new EmailActionConfig();
    action.getProperties().put("state", "SUCCESS");
    release.getActions().add(action);/*from w  w w.  ja  v a 2s.  c om*/

    ActionConfig action2 = new EmailActionConfig();
    action2.getProperties().put("state", "SUCCESS");
    release.getActions().add(action2);

    File file = new File(testFolder.getRoot(), "devType3.yml");
    FileUtils.writeStringToFile(file, configSerializer.convertEntry(release));

    ReleaseConfig release2 = configSerializer.convertEntry(FileUtils.readFileToString(file));
    Assert.assertNotNull(release2);
    Assert.assertEquals(release, release2);

}

From source file:com.gorsini.searcher.CanalplaySearcher.java

public void check() throws HTMLChangeException, IOException {
    String url = makeURL("intouchables");
    Document doc = Jsoup.connect(url).referrer("http://vod.canalplay.com/").get();
    Elements movies = doc.select("div.list_movie");
    String html = movies.html();//from ww w .  j  ava 2s .co m
    String previousHTML = null;
    LOG.finest(html);
    File file = new File(CHECK_FILENAME);
    if (file.exists()) {
        previousHTML = FileUtils.readFileToString(new File(CHECK_FILENAME));
    } else {
        LOG.log(Level.INFO, "sauvegarde check");
        FileUtils.writeStringToFile(file, html);
    }
    if (previousHTML != null && !html.equals(previousHTML)) {
        // sauvegarde la nouvelle version pour pouvoir la comparer.
        FileUtils.writeStringToFile(new File(CHECK_FILENAME + ".new"), html);
        throw new HTMLChangeException();
    } else {
        LOG.log(Level.INFO, "no change detected into HTML response");
    }
}

From source file:com.davis.crs.CreateCannedDataSet.java

/**
 * Write data objects to json file./*w ww  . j  a  va 2 s  . co m*/
 *
 * @param dataHolders the data holders
 * @param fileName    the file name
 * @throws IOException the io exception
 */
public static void writeDataObjectsToJsonFile(ArrayList<CRSEndpointResponse> dataHolders, String fileName)
        throws IOException {
    System.out.println("Size of the CRSEndpointResponse Array = " + dataHolders.size());
    File file = new File(outputDir);

    if (!file.exists()) {
        file.mkdirs();
    }

    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String json = gson.toJson(dataHolders);
    File file1 = new File(outputDir + "/" + fileName);

    FileUtils.writeStringToFile(file1, json);
}

From source file:hudson.gridmaven.settings.SettingsProviderUtils.java

/**
 * @return a temp file which must be deleted after use
 *///ww  w . ja  v a  2s . c o m
public static File copyConfigContentToFile(SettingConfig config) throws IOException {
    File tmpContentFile = File.createTempFile("config", "tmp");
    FileUtils.writeStringToFile(tmpContentFile, config.content);
    return tmpContentFile;
}