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:functionaltests.dataspaces.TestSubmitJobWithPartiallyUnaccessibleDataSpaces.java

@BeforeClass
public static void before() throws Throwable {
    spaceRoot = tmpFolder.newFolder("space");
    spaceRootUser = new File(spaceRoot, "demo");
    spaceRootUser.mkdirs();/*from   w  w  w . j  a v a 2 s.c om*/

    deployer = new FileSystemServerDeployer(spaceRoot.getAbsolutePath(), false);
    SchedulerTHelper.log("Dataspace started in : " + spaceRoot.getAbsolutePath());
    File inputFile = new File(spaceRootUser, "myfilein1");
    inputFile.createNewFile();
    File propertiesfile = new File(configFile.toURI());
    String propContent = FileUtils.readFileToString(propertiesfile, Charset.defaultCharset().toString());
    String newContent = propContent.replace("$$TOREPLACE$$", deployer.getVFSRootURL());
    FileUtils.writeStringToFile(propertiesfile, newContent);

    schedulerHelper = new SchedulerTHelper(true, propertiesfile.getAbsolutePath());
}

From source file:hoot.services.controllers.ingest.BasemapResourceTest.java

@Test
@Category(UnitTest.class)
public void TestgetBasemapList() throws Exception {
    BasemapResource mapRes = new BasemapResource();
    File f = new File(mapRes._tileServerPath + "/BASEMAP/TestMap");
    FileUtils.forceMkdir(f);/*from w w  w  .j  a v a2  s. c o m*/

    JSONObject cont = new JSONObject();
    cont.put("jobid", "123-456-789");
    cont.put("path", "/projects/hoot/ingest/processed/BASEMAP/TestMap");

    File file = new File(mapRes._ingestStagingPath + "/BASEMAP/TestMap.enabled");
    FileUtils.writeStringToFile(file, cont.toJSONString());

    File f2 = new File(mapRes._tileServerPath + "/BASEMAP/TestMap2");
    FileUtils.forceMkdir(f2);

    File file2 = new File(mapRes._ingestStagingPath + "/BASEMAP/TestMap2.enabled");
    FileUtils.writeStringToFile(file2, cont.toJSONString());

    JSONArray res = mapRes._getBasemapList();
    boolean found = false;
    for (Object oMap : res) {
        JSONObject map = (JSONObject) oMap;
        if (map.get("name").toString().equals("TestMap")) {
            found = true;
            break;
        }
    }
    org.junit.Assert.assertTrue(found);
    FileUtils.forceDelete(f);
    FileUtils.forceDelete(f2);
}

From source file:io.restassured.itest.java.FileUploadingITest.java

@Test
public void can_upload_binary_from_file() throws IOException {
    // Given/*from  ww  w  .ja  va  2 s  .  c om*/
    File file = folder.newFile("my.txt");
    FileUtils.writeStringToFile(file, "Hello World");

    // When
    given().contentType(ContentType.BINARY).body(file).when().post("/reflect").then().statusCode(200)
            .body(equalTo("Hello World"));
}

From source file:ch.sbb.releasetrain.config.ConfigAccessorImpl.java

@Override
public void writeConfig(String name, ReleaseConfig config) {
    File dir = git.getRepo().directory();
    File file = new File(dir, "/" + name + "-type.yml");

    try {//from w ww . ja v a 2 s .  c  o  m
        FileUtils.writeStringToFile(file, accessorRelease.convertEntry(config));
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }

    if (this.readCalendar(name) == null) {
        this.writeCalendar(new ReleaseCalendar(), name);
    }

}

From source file:com.thoughtworks.go.util.validators.LogDirectoryTest.java

@Before
public void setUp() throws Exception {
    configFolder = TestFileUtil.createTempFolder("config-" + System.currentTimeMillis());
    existingLogFolder = TestFileUtil.createTempFolder("log-" + System.currentTimeMillis());
    log4jPropertiesFile = new File(configFolder, "log4j.properties");
    FileUtils.writeStringToFile(log4jPropertiesFile, LOG4J_CONFIG_FILE_CONTENTS);
}

From source file:com.github.swt_release_fetcher.SwtWebsite.java

/**
 * Determines if the website has changed since our last visit. Uses a file
 * called ''pageSource'' to persist the site
 *
 * @param driver/*from w  w w  . j a v  a2 s. co m*/
 * @param websiteUrl URL to SWT's project site
 * @return true if the site has changed, false if not. Also returns true on
 * the first run
 * @throws IOException If the file ''pageSource'' coudln't be read or
 * written
 */
public boolean hasChanged(WebDriver driver, String websiteUrl) throws IOException {

    driver.get(websiteUrl);
    String pageSoruce = driver.getPageSource();
    String persistedPageSource = "";
    File f = new File("pageSource");
    // create a new file to persist page source
    if (!f.exists()) {
        try {
            f.createNewFile();
        } catch (IOException ieo) {
            throw new IOException("Unable to create file " + f.getAbsolutePath(), ieo);
        }
        // if it was already there, this is not the first run of swt-release-fetcher
        // read in the file content
    } else {
        try {
            persistedPageSource = FileUtils.readFileToString(f, "utf-8");
        } catch (IOException ieo) {
            throw new IOException("Unable to read file " + f.getAbsolutePath(), ieo);
        }
    }

    // check if the page has changed
    if (persistedPageSource.equals(pageSoruce)) {
        return false;
        // NOTE: If this is the first run of swt-release-fethcer the file 
        // will be empty and thus filled with content here
    } else {
        try {
            FileUtils.writeStringToFile(f, pageSoruce);
            return true;
        } catch (IOException ieo) {
            throw new IOException("Unable to write to file " + f.getAbsolutePath(), ieo);
        }

    }
}

From source file:com.thoughtworks.go.server.initializers.PluginsZipInitializerTest.java

@Test
public void shouldZipAllPluginsIntoOneZipEveryTime() throws Exception {
    String expectedZipPath = TestFileUtil.createTempFile("go-plugins-all.zip").getAbsolutePath();
    File bundledPluginsDir = TestFileUtil.createTempFolder("plugins-bundled");
    File externalPluginsDir = TestFileUtil.createTempFolder("plugins-external");

    FileUtils.writeStringToFile(new File(bundledPluginsDir, "bundled1.jar"), "Bundled1");
    FileUtils.writeStringToFile(new File(bundledPluginsDir, "bundled2.jar"), "Bundled2");

    FileUtils.writeStringToFile(new File(externalPluginsDir, "external1.jar"), "External1");
    FileUtils.writeStringToFile(new File(externalPluginsDir, "external2.jar"), "External2");

    when(systemEnvironment.get(PLUGIN_GO_PROVIDED_PATH)).thenReturn(bundledPluginsDir.getAbsolutePath());
    when(systemEnvironment.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn(externalPluginsDir.getAbsolutePath());
    when(systemEnvironment.get(ALL_PLUGINS_ZIP_PATH)).thenReturn(expectedZipPath);

    pluginsZipInitializer.initialize();//  w  ww .java2s  .co  m

    assertThat(expectedZipPath + " should exist", new File(expectedZipPath).exists(), is(true));
    assertThat(new ZipFile(expectedZipPath).getEntry("bundled/bundled1.jar"), is(notNullValue()));
    assertThat(new ZipFile(expectedZipPath).getEntry("bundled/bundled2.jar"), is(notNullValue()));
    assertThat(new ZipFile(expectedZipPath).getEntry("external/external1.jar"), is(notNullValue()));
    assertThat(new ZipFile(expectedZipPath).getEntry("external/external2.jar"), is(notNullValue()));
}

From source file:com.cloud.utils.ProcessUtilTest.java

@Test(expected = ConfigurationException.class)
public void pidCheckEmptyPid() throws ConfigurationException, IOException {
    Assume.assumeTrue(SystemUtils.IS_OS_LINUX);
    FileUtils.writeStringToFile(pidFile, "intentionally not number");
    ProcessUtil.pidCheck(pidFile.getParent(), pidFile.getName());
}

From source file:js_test_data.JsTestScenariosBuilder.java

public void build(Injector injector) throws Exception {
    Transaction transaction = graphDb.beginTx();
    JSONObject jsonObject = new JSONObject();
    for (JsTestScenario scenario : scenarios) {
        graphComponentTest.removeWholeGraph();
        injector.injectMembers(scenario);
        jsonObject.put(jsonKeyNameFromTestScenario(scenario), scenario.build());
    }//w ww  . j a va2  s . c  o  m
    FileUtils.writeStringToFile(new File("src/test/java/js_test_data/js-test-data-server-side.json"),
            jsonObject.toString());
    transaction.failure();
    transaction.close();
}

From source file:edu.isistan.carcha.lsa.TextTraceabilityComparator.java

@Override
protected String saveGraph() {
    String filename = buildOutputFilename();
    filename += ".concern";
    File f = new File(filename);
    try {//from  w  ww.  j a v a  2s .  c o m
        FileUtils.writeStringToFile(f, sb.toString());
        return filename;
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
    return null;
}