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:com.github.ipaas.ideploy.agent.handler.BackupCodeHandlerTest.java

/**
 * @throws java.lang.Exception/* ww  w .ja  v a  2 s .  c  om*/
 */
@Before
public void setUp() throws Exception {
    File srcFile = new File(SRC_PATH);
    if (srcFile.exists()) {
        FileUtils.cleanDirectory(srcFile);
    } else {
        srcFile.mkdirs();
    }
    File targetFile = new File(TARGET_PATH);
    if (targetFile.exists()) {
        FileUtils.cleanDirectory(targetFile);
    } else {
        targetFile.mkdirs();
    }

    for (int i = 0; i < 10; i++) {
        FileUtils.writeStringToFile(new File(SRC_PATH + "/" + i), String.valueOf(i));
    }
    for (int i = 10; i < 20; i++) {
        new File(SRC_PATH + "/" + i).mkdir();
    }
}

From source file:com.talis.inject.guice.PropertiesConfiguredModuleFactoryTest.java

@Test
public void readPropertiesFromFileSpecifiedBySystemProperty() throws Exception {

    File tmpFile = File.createTempFile("injector-module", ".properties");
    tmpFile.deleteOnExit();/*from w ww  . j a  v a 2s .  co m*/
    FileUtils.writeStringToFile(tmpFile, String.format("%s=%s",
            PropertiesConfiguredModuleFactory.MODULE_PROPERTY, TestModuleThree.class.getName()));
    System.clearProperty(PropertiesConfiguredModuleFactory.PROPERTIES_LOCATION_PROP);

    try {
        System.setProperty(PropertiesConfiguredModuleFactory.PROPERTIES_LOCATION_PROP,
                tmpFile.getAbsolutePath());
        Module[] modules = new PropertiesConfiguredModuleFactory().getModules();
        assertEquals(1, modules.length);
        assertTrue(TestModuleThree.class.isInstance(modules[0]));
    } finally {
        System.clearProperty(PropertiesConfiguredModuleFactory.PROPERTIES_LOCATION_PROP);
    }
}

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

@Test
public void loadPropertiesFromFile() throws IOException {
    File file = File.createTempFile("test", ".properties");
    FileUtils.writeStringToFile(file, "a=b\nc=d\n");
    Properties properties = PropertiesUtil.loadFromFile(file);
    Assert.assertEquals("b", properties.get("a"));
}

From source file:com.kotcrab.vis.editor.util.vis.CrashReporter.java

public File processReport() throws IOException {
    File crashReportFile = new File(logFile.getParent(),
            "viseditor-crash " + new SimpleDateFormat("yy-MM-dd HH-mm-ss").format(new Date()) + ".txt");
    FileUtils.writeStringToFile(crashReportFile, report);
    Log.info(TAG, "Crash saved to file: " + crashReportFile.getAbsolutePath());
    return crashReportFile;
}

From source file:io.jenkins.blueocean.rest.model.scm.AbstractSampleDVCSRepoRule.java

public final void write(String rel, String text) throws IOException {
    FileUtils.writeStringToFile(new File(sampleRepo, rel), text);
}

From source file:jenkins.model.lazy.FakeMapBuilder.java

public FakeMapBuilder add(int n) throws IOException {
    File build = new File(dir, Integer.toString(n));
    FileUtils.writeStringToFile(new File(build, "n"), Integer.toString(n));
    build.mkdir();//  w  ww.j  a  v  a2  s  .c om
    return this;
}

From source file:com.tyro.oss.pact.spring4.pact.model.Pact.java

public static void writePact(Pact pact, File pactFile, ObjectStringConverter jsonConverter) throws IOException {
    FileUtils.writeStringToFile(pactFile, jsonConverter.fromObject(pact));
}

From source file:cc.kave.episodes.mining.reader.MappingParserTest.java

@Test
public void readMapping() throws IOException {
    Event e1 = new Event();
    Event e2 = new Event();
    e2.setKind(EventKind.INVOCATION);//from   w ww. j a  v a 2  s.  co m

    List<Event> expected = new LinkedList<Event>();
    expected.add(e1);
    expected.add(e2);

    String jsonString = JsonUtils.toJson(expected);
    File file = getFilePath();

    FileUtils.writeStringToFile(file, jsonString);

    List<Event> actuals = sut.parse(NUMBREPOS);

    assertEquals(expected, actuals);
}

From source file:com.amazonaws.util.Md5UtilsTest.java

@Test
public void testFile() throws Exception {
    File f = File.createTempFile("Md5UtilsTest-", "txt");
    f.deleteOnExit();//  w w  w  .  j a  va  2s  . c  o  m
    FileUtils.writeStringToFile(f, "Testing MD5");
    byte[] md5 = Md5Utils.computeMD5Hash(f);
    assertEquals("0b4f503b8eb7714ce12402406895cf68", StringUtils.lowerCase(Base16.encodeAsString(md5)));

    String b64 = Md5Utils.md5AsBase64(f);
    assertEquals("C09QO463cUzhJAJAaJXPaA==", b64);
}

From source file:cc.recommenders.io.ZipFolder.java

private void createMarker() {
    File markerName = new File(_root, MARKER_FILE_NAME);
    if (!markerName.exists()) {
        try {/*from w w w. j  a  va 2  s. co m*/
            FileUtils.writeStringToFile(markerName, _metaData);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}