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.cloud.utils.PropertiesUtilsTest.java

@Test
public void processConfigFile() throws IOException {
    File tempFile = File.createTempFile("temp", ".properties");
    FileUtils.writeStringToFile(tempFile, "a=b\nc=d\n");
    Map<String, String> config = PropertiesUtil.processConfigFile(new String[] { tempFile.getAbsolutePath() });
    Assert.assertEquals("b", config.get("a"));
    Assert.assertEquals("d", config.get("c"));
    tempFile.delete();/*  w ww .java  2s .  co m*/
}

From source file:com.streamsets.pipeline.stage.destination.SimpleTestInputFormat.java

@Override
public List<InputSplit> getSplits(JobContext jobContext) throws IOException, InterruptedException {
    Configuration conf = jobContext.getConfiguration();

    if (conf.getBoolean(THROW_EXCEPTION, false)) {
        throw new IOException("Throwing exception as instructed, failure in bootstraping MR job.");
    }/*w ww  .ja  va 2 s .com*/

    String fileLocation = conf.get(FILE_LOCATION);
    if (fileLocation != null) {
        FileUtils.writeStringToFile(new File(fileLocation), conf.get(FILE_VALUE));
    }

    return Collections.emptyList();
}

From source file:aurelienribon.texturepackergui.Project.java

public void save(File projectFile) throws IOException {
    String str = "input=\"" + FilenameHelper.getRelativePath(input, projectFile.getParent()) + "\"\n"
            + "output=\"" + FilenameHelper.getRelativePath(output, projectFile.getParent()) + "\"\n"
            + "packName=\"" + packName + "\"\n\n" + saveSettings(settings);

    FileUtils.writeStringToFile(projectFile, str);
}

From source file:com.BuildCraft.utils.Settings.java

public boolean saveSettings() {
    boolean operationCompleted = true;
    String fileData = "";

    for (int i = 0; i < aKeys.length; i++) {
        if (i == 0) {
            fileData += aKeys[i] + "=" + aValues[i];
        } else {//from   w  w w . jav a2 s.  c  o  m
            fileData += "\n" + aKeys[i] + "=" + aValues[i];
        }
    }

    try {
        FileUtils.writeStringToFile(file, fileData);
    } catch (IOException ex) {
        ConsoleOut.printMsg("Settings: Warning: Failed to save " + file.getName());
        operationCompleted = false;
    }
    return operationCompleted;
}

From source file:de.tudarmstadt.ukp.dkpro.tc.core.io.DumpDataWriter.java

@Override
public void write(File outputDirectory, FeatureStore featureStore, boolean useDenseInstances,
        String learningMode, boolean applyWeighting) throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append(featureStore.getNumberOfInstances());
    sb.append("\n");
    sb.append(StringUtils.join(featureStore.getUniqueOutcomes(), ", "));
    sb.append("\n");
    for (Instance instance : featureStore.getInstances()) {
        sb.append(instance.toString());/*from   www . jav a  2  s.co  m*/
    }
    System.out.println(sb.toString());
    FileUtils.writeStringToFile(new File(outputDirectory, DUMP_FILE_NAME), sb.toString());
}

From source file:com.microsoft.alm.plugin.external.commands.DownloadCommand.java

/**
 * Returns the destination of the file or throws an error if one occurred
 *//*w  w  w.  j av  a2 s . c  o  m*/
@Override
public String parseOutput(final String stdout, final String stderr) {
    super.throwIfError(stderr);
    // Write the contents of stdout to the destination file
    File file = new File(destination);
    if (file.exists()) {
        file.delete();
    }
    try {
        FileUtils.writeStringToFile(file, stdout);
    } catch (IOException e) {
        // throw any errors that occur
        throw new ToolParseFailureException(e);
    }

    // Return the path to the file
    return destination;
}

From source file:com.beaconhill.yqd.Processor.java

public void download(String dataDir, String s) {
    try {/*from w w w  .  j  a  v  a2  s .  c  o  m*/
        String fileName = dataDir + "/" + s + ".csv";
        String data = downloader.getSymbolData(s);
        if (data.startsWith("<!doctype html")) {
            System.err.println("ERROR: the symbol '" + s + "' was not found ");
        } else {
            FileUtils.writeStringToFile(new File(fileName), data);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

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

/**
 * Method to log screenshot to log file.
 * // w  ww .ja v a2  s .c o m
 * @param webDriver
 *            (web driver object)
 * @param linkText
 *            (text to log)
 */
public void logScreenShot(final WebDriver webDriver, final String linkText) {
    if (screenShotsDirectory != null) {
        File screenShotFile = new File(screenShotsDirectory, getUniqueString() + ".html");
        try {
            FileUtils.writeStringToFile(screenShotFile, webDriver.getPageSource());
            Reporter.log(
                    "<a href=\"" + screenShotFile.getName() + "\" target=\"_blank\">" + linkText + "</a><br>");
        } catch (IOException e) {
            Reporter.log("Unable to log screenshot");
        }
    } else {
        Reporter.log("Screenshots directory not set. Not logging screenshot");
    }
}

From source file:com.hp.autonomy.idolutils.GenerateIndexableXmlDocumentTest.java

@Test
public void generateFile() throws IOException {
    final Collection<String> numericFields = new ArrayList<>(1000);
    final Random random = new Random();
    for (int i = 0; i < 1000; i++) {
        numericFields.add(String.valueOf(1451610061 + random.nextInt(1000)));
    }/*from   w  w w .j  a  v a 2  s.  co  m*/

    final Collection<SampleDoc> sampleDocs = new ArrayList<>(numericFields.size());
    int i = 0;
    for (final String numericField : numericFields) {
        sampleDocs.add(new SampleDoc(UUID.randomUUID().toString(), "Sample Date Title " + i++,
                "Sample Date Content", numericField));
    }

    @SuppressWarnings("TypeMayBeWeakened")
    final IdolXmlMarshaller marshaller = new IdolXmlMarshallerImpl();
    final File outputFile = new File(TEST_DIR, "sampleFile.xml");
    FileUtils.writeStringToFile(outputFile,
            marshaller.generateXmlDocument(sampleDocs, SampleDoc.class, StandardCharsets.UTF_8));
    assertTrue(outputFile.exists());
}

From source file:com.gs.obevo.util.FileUtilsCobra.java

public static void writeStringToFile(File file, String data) {
    try {/* w ww  . ja va  2s .c o m*/
        FileUtils.writeStringToFile(file, data);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
}