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, String encoding) throws IOException 

Source Link

Document

Writes a String to a file creating the file if it does not exist.

Usage

From source file:io.wcm.devops.conga.generator.plugins.postprocessor.DummyPostProcessor.java

@Override
public List<FileContext> apply(FileContext file, PostProcessorContext context) {
    FileHeaderContext fileHeader = extractFileHeader(file, context);

    File newFile = new File("target/generation-test/postProcessorResult.conf");
    try {/*from www.  j a  va2s  .  c o  m*/
        FileUtils.writeStringToFile(newFile, "Test Config Content", CharEncoding.UTF_8);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
    FileContext newFileContext = new FileContext().file(newFile).charset(CharEncoding.UTF_8);

    applyFileHeader(newFileContext, fileHeader, context);

    return ImmutableList.of(newFileContext);
}

From source file:net.rptools.tokentool.AppSetup.java

public static void install(String versionString) {
    System.setProperty("appHome", getAppHome("logs").getAbsolutePath());
    log = LogManager.getLogger(AppSetup.class);

    File overlayVer = new File(getAppHome().getAbsolutePath() + "/version.txt");
    Collection<File> existingOverLays = FileUtils.listFiles(AppConstants.OVERLAY_DIR,
            ImageUtil.SUPPORTED_FILE_FILTER, TrueFileFilter.INSTANCE);
    log.info("Overlays installed: " + existingOverLays.size());

    // Only install overlays once or if version.text is missing or version is newer
    // Overlays are stored in a version packaged structure so we can later install only newer overlays if wanted
    String installedVersion = "0";
    try {/*from   ww w.  j  a  va2 s . co  m*/
        if (overlayVer.exists()) {
            installedVersion = FileUtils.readFileToString(overlayVer, Charset.defaultCharset());
        } else {
            FileUtils.writeStringToFile(overlayVer, versionString, Charset.defaultCharset());
        }
    } catch (IOException ioe) {
        log.error(ioe);
    }

    if (existingOverLays.isEmpty() || isNewerVersion(TokenTool.getVersion(), installedVersion)) {
        try {
            installDefaultOverlays();
        } catch (IOException e) {
            log.error(e);
        }

        // Update version file to new version
        try {
            FileUtils.writeStringToFile(overlayVer, versionString, Charset.defaultCharset());
        } catch (IOException e) {
            log.error(e);
        }
    }
}

From source file:com.uwsoft.editor.data.manager.SceneDataManager.java

public SceneVO createNewScene(String name) {
    SceneVO vo = new SceneVO();
    vo.sceneName = name;/* w  ww . j a  va 2  s  . c  om*/
    try {
        String projPath = dataManager.getCurrentWorkingPath() + "/" + dataManager.currentProjectVO.projectName;
        FileUtils.writeStringToFile(new File(projPath + "/project.dt"),
                dataManager.currentProjectInfoVO.constructJsonString(), "utf-8");
        FileUtils.writeStringToFile(new File(projPath + "/scenes/" + vo.sceneName + ".dt"),
                vo.constructJsonString(), "utf-8");
        dataManager.currentProjectInfoVO.scenes.add(vo);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return vo;
}

From source file:net.sf.taverna.raven.helloworld.HelloWorld.java

public void run(PrintStream out) throws IOException {
    File tmpFile = File.createTempFile("helloworld", "test");
    tmpFile.deleteOnExit();/*from  ww w . j a v a 2 s.  c  o  m*/
    FileUtils.writeStringToFile(tmpFile, TEST_DATA, "utf8");
    String read = FileUtils.readFileToString(tmpFile, "utf8");
    out.print(read);
}

From source file:gov.va.chir.tagline.TagLineApp.java

private static void writeLog(final File file, final String s) throws IOException {
    final String output = String.format("%s%s", s, System.getProperty("line.separator"));
    FileUtils.writeStringToFile(file, output, true);

    if (TO_CONSOLE) {
        System.out.print(output);
    }/* w  w  w . j  a va  2 s .  com*/
}

From source file:gov.va.chir.tagline.dao.DatasetScoredSaver.java

private void saveHeader() throws IOException {
    final StringBuilder builder = new StringBuilder();

    builder.append(DatasetUtil.DOC_ID);/* w w w  . j a v  a 2 s.c om*/
    builder.append("\t");

    builder.append(DatasetUtil.LINE_ID);
    builder.append("\t");

    builder.append(PRED_LABEL);
    builder.append("\t");

    builder.append(TEXT);
    builder.append(System.getProperty("line.separator"));

    FileUtils.writeStringToFile(file, builder.toString(), false);
}

From source file:at.medevit.elexis.gdt.tools.GDTFileHelper.java

public static <U extends GDTSatzNachricht> boolean writeGDTSatzNachricht(U gdtSatzNachricht,
        IGDTCommunicationPartner cp) {//from w  w w  . j a v a 2 s .  co  m
    String[] outLines = gdtSatzNachricht.getMessage();
    String zeichensatz = GDTConstants.getCharsetStringByInt(cp.getOutgoingDefaultCharset());
    String directory = cp.getOutgoingDirectory();
    String outgoingFileName = determineOutgoingFileName(cp);

    try {
        File destination = new File(directory + File.separatorChar + outgoingFileName);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < outLines.length; i++) {
            sb.append(outLines[i]);
        }
        FileUtils.writeStringToFile(destination, sb.toString(), zeichensatz);
    } catch (IOException e) {
        String message = "GDT: Fehler beim Schreiben der Ausgangsdatei " + outgoingFileName;
        Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, message, e);
        StatusManager.getManager().handle(status, StatusManager.SHOW);
        logger.log(e, message, Log.WARNINGS);
        return false;
    }
    return true;
}

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

@Test
public void testSerializeActionConfig() throws Exception {

    ReleaseConfig release = new ReleaseConfig();
    ActionConfig action = new JenkinsActionConfig();
    action.getProperties().put("myProp1", "Hallo Welt1");
    action.getProperties().put("myProp2", "Hallo Welt2");

    ActionConfig action2 = new JenkinsActionConfig();
    action2.getProperties().put("myProp2", "Hallo asxasxsxWelt");

    release.setTyp("demo-release");
    release.getActions().add(action);/* w w w  .j a v  a  2  s  .  c  o m*/
    release.getActions().add(action2);

    File file = new File(testFolder.getRoot(), "action.yml");
    FileUtils.writeStringToFile(file, configSerializer.convertEntry(release), "UTF-8");

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

}

From source file:com.mtt.myapp.operation.service.SystemConfigService.java

/**
 * Save content to system configuration file.
 *
 * @param content file content.//from  w ww.  j  a v  a 2  s.  c o  m
 *
 * @return save successfully or not.
 */
public boolean save(String content) {
    try {
        FileUtils.writeStringToFile(home.getSubFile("system.conf"), content, "UTF-8");
    } catch (IOException e) {
        LOG.error("Error while writing system configuration file.");
        return false;
    }
    return true;
}

From source file:net.acesinc.data.json.generator.log.FileLogger.java

private void logEvent(String event) {
    try {//  ww w  . j av a2  s. c  om
        File f = File.createTempFile(filePrefix, fileExtension, outputDirectory);
        FileUtils.writeStringToFile(f, event, "UTF-8");
    } catch (IOException ioe) {
        log.error("Unable to create temp file");
    }

}