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.seleniumtests.ut.util.squashta.TestTaFolderStructureGenerator.java

/**
 * folder structure generation with ta file present in source. We check that it's taken
 * @throws IOException// ww  w. j  a  v  a2  s.c om
 */
@Test(groups = { "squash" })
public void testGenerateStructureWithExistingTa() throws IOException {
    File tmpFolder = Paths.get(SeleniumTestsContextManager.getDataPath(), "tmp").toFile();
    File taFile = Paths.get(tmpFolder.getPath(), "src", "squashTA", "tests", "core_generic.ta").toFile();
    FileUtils.writeStringToFile(taFile, "exists");

    TaFolderStructureGenerator structGen = new TaFolderStructureGenerator("core", tmpFolder.getAbsolutePath(),
            tmpFolder.getAbsolutePath());
    try {
        structGen.generateDefaultStructure();
        Assert.assertTrue(taFile.exists());
        Assert.assertEquals(FileUtils.readFileToString(taFile), "exists");
    } finally {
        FileUtils.cleanDirectory(tmpFolder);
        tmpFolder.delete();
    }
}

From source file:fr.xebia.workshop.git.UpdatePomFileAndCommitTest.java

@After
public void restoreTargetPomContent() throws Exception {
    FileUtils.writeStringToFile(pomFile, pomContent);
}

From source file:jenkins.plugins.shiningpanda.scm.ToxSCM.java

public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath remoteDir,
        BuildListener listener, File changeLogFile) throws IOException, InterruptedException {
    FilePath toxIniFp = build.getWorkspace().child(toxIni);
    FilePath setupPyFp = toxIniFp.getParent().child("setup.py");
    FileUtils.writeStringToFile(new File(toxIniFp.getRemote()), content);
    FileUtils.writeStringToFile(new File(setupPyFp.getRemote()), "from setuptools import setup; setup();");
    return createEmptyChangeLog(changeLogFile, listener, "log");
}

From source file:com.sketchy.hardware.impl.RaspberryPIServoController.java

public synchronized void penUp() {
    if (properties.getPenUpPosition() != lastPosition) {
        try {/*from w  ww.  j a va  2 s. c o m*/
            int penUpValue = (int) ((SERVO_MAX_VALUE - SERVO_MIN_VALUE) / 100.0 * properties.getPenUpPosition()
                    + SERVO_MIN_VALUE);
            String servoPenUpCommand = buildServoCommand(properties.getPenPinNumber(), penUpValue);
            FileUtils.writeStringToFile(servoPipeFile, servoPenUpCommand);
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
        Gpio.delayMicroseconds(properties.getPenUpPeriodInMilliseconds() * 1000);
        lastPosition = properties.getPenUpPosition();
    }
}

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

private static void writeGraph(File file, IGraph graph) throws IOException {

    String header = "source,target,category,linkDescription,sourceGroup,targetGroup,sourceGroupDescription,targetGroupDescription"
            + System.lineSeparator();
    FileUtils.writeStringToFile(file, header);
    TpaWebPersistor graphweb = new TpaWebPersistor(file);
    graph.writeLines(graphweb);//from w w  w . j a va  2  s  . co m
}

From source file:com.github.neio.filesystem.paths.TestFilePath.java

@Test
public void testSha1Hash() throws IOException {
    FileUtils.writeStringToFile(new File(testDir, "testFile"), "Hello World");

    Assert.assertEquals("a4d55a8d778e5022fab701977c5d840bbc486d0",
            new FilePath("./testTempDir/testFile").sha1Hash().toString(16));
}

From source file:com.datatorrent.lib.io.fs.FSInputModuleAppTest.java

@Before
public void setup() throws Exception {
    inputDir = testMeta.baseDirectory + File.separator + "input";
    outputDir = testMeta.baseDirectory + File.separator + "output";

    FileUtils.writeStringToFile(new File(inputDir + File.separator + FILE_1), FILE_1_DATA);
    FileUtils.writeStringToFile(new File(inputDir + File.separator + FILE_2), FILE_2_DATA);
    FileUtils.forceMkdir(new File(inputDir + File.separator + "dir"));
    FileUtils.writeStringToFile(new File(inputDir + File.separator + "dir/inner.txt"), FILE_1_DATA);
}

From source file:com.citrix.g2w.webdriver.TestLogger.java

/**
 * Method to log message along with screenshot.
 * /*  ww  w.j av a 2 s. c om*/
 * @param message
 *            (message to log)
 * @param webDriver
 *            (web driver object)
 */
public void logWithScreenShot(final String message, final WebDriver webDriver) {
    StringBuilder logText = new StringBuilder(message);
    if (screenShotsDirectory != null) {
        File screenShotFile = new File(screenShotsDirectory, getUniqueString() + ".html");
        try {
            FileUtils.writeStringToFile(screenShotFile, webDriver.getPageSource());
            logText.append(
                    " <a href=\"" + screenShotFile.getName() + "\" target=\"_blank\">Resulting Page</a>");
        } catch (IOException e) {
            logText.append(" Unable to log screenshot");
        }
    } else {
        logText.append(" <i>Screenshots directory not set. Not logging screenshot<i>");
    }

    logText.append("<br>");
    Reporter.log(logText.toString());
}

From source file:edu.umn.msi.tropix.common.io.IOContextsTest.java

@Test(groups = "unit")
public void inputForFile() throws IOException {
    final File file1 = File.createTempFile("tpx", "tst"), file2 = File.createTempFile("tpx", "tst");
    try {//from   ww w. j  a  va 2 s. co  m
        FileUtils.writeStringToFile(file1, "Moo Cow");

        final InputContext inputContext = InputContexts.forFile(file1);
        inputContext.get(file2);
        assert FileUtils.readFileToString(file2).equals("Moo Cow");
    } finally {
        FileUtils.deleteQuietly(file1);
        FileUtils.deleteQuietly(file2);
    }
}

From source file:com.thoughtworks.go.server.web.ArtifactFolderTest.java

@Test
public void shouldRenderDirectoryIfItExists() throws IOException {
    File file = new File(new File(folder, "dir1"), "foo.txt");
    file.getParentFile().mkdirs();/*from   w w  w.  j  a  va 2  s . c om*/
    FileUtils.writeStringToFile(file, "FOO");
    assertThat(artifactFolder.renderArtifactFiles("http://uri"), containsString(">\nfoo.txt\n</a>"));
    assertThat(artifactFolder.renderArtifactFiles("http://uri"),
            containsString("<a href=\"http://uri/files/pipeline-name/label-111/"
                    + "stage-name/1/job-name/pathRelativeToBaseURL/dir1/foo.txt\">"));
}