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.door43.translationstudio.core.TargetTranslationMigrator.java

/**
 * Performs a migration on a manifest object.
 * We just throw it into a temporary directory and run the normal migration on it.
 * @param manifestJson//from ww w  . j  av  a  2 s.c om
 * @return
 */
public static JSONObject migrateManifest(JSONObject manifestJson) {
    File tempDir = new File(AppContext.context().getCacheDir(), System.currentTimeMillis() + "");
    // TRICKY: the migration can change the name of the translation dir so we nest it to avoid conflicts.
    File fakeTranslationDir = new File(tempDir, "translation");
    fakeTranslationDir.mkdirs();
    JSONObject migratedManifest = null;
    try {
        FileUtils.writeStringToFile(new File(fakeTranslationDir, "manifest.json"), manifestJson.toString());
        fakeTranslationDir = migrate(fakeTranslationDir);
        if (fakeTranslationDir != null) {
            migratedManifest = new JSONObject(
                    FileUtils.readFileToString(new File(fakeTranslationDir, "manifest.json")));
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // clean up
        FileUtils.deleteQuietly(tempDir);
    }
    return migratedManifest;
}

From source file:com.wendal.java.dex.decomplier.toolkit.IO_Tool.java

public static void write2File(String rootDir, String package_name, String filename, String data)
        throws IOException {
    String tmp[] = package_name.split("[.]");
    String tmp_str = rootDir;/*from   w w  w  . ja  v a2s .c o  m*/
    for (int i = 0; i < tmp.length; i++) {
        tmp_str += "\\";
        tmp_str += tmp[i];
    }
    File dir_file = new File(tmp_str + "\\");
    dir_file.mkdirs();

    File src_file = new File(dir_file.getPath() + "\\" + filename);
    src_file.createNewFile();
    FileUtils.writeStringToFile(src_file, data);
}

From source file:com.mayalogy.mayu.io.LocalDataManager.java

public static void writeToFile(List<String> list, File file) throws IOException {
    StringBuilder sb = new StringBuilder();
    for (String w : list) {
        sb.append(w);/*from  www .j a  v a2 s  .  co m*/
        sb.append("\n");
    }
    FileUtils.writeStringToFile(file, sb.toString());
}

From source file:de.tudarmstadt.ukp.dkpro.tc.ml.liblinear.LiblinearUtils.java

public static void savePredictions(File outputFile, List<Double> predictions) throws IOException {
    StringBuilder sb = new StringBuilder();
    for (Double prediction : predictions) {
        sb.append(prediction);// w  ww.j  a va  2  s. c  o  m
        sb.append("\n");
    }
    FileUtils.writeStringToFile(outputFile, sb.toString());
}

From source file:de.tudarmstadt.ukp.dkpro.tc.core.util.SaveModelUtils.java

public static void writeFeatureInformation(File outputFolder, List<String> featureSet) throws Exception {
    String featureExtractorString = StringUtils.join(featureSet, "\n");
    FileUtils.writeStringToFile(new File(outputFolder, MODEL_FEATURE_EXTRACTORS), featureExtractorString);
}

From source file:android.databinding.tool.writer.JavaFileWriter.java

public void writeToFile(File exactPath, String contents) {
    File parent = exactPath.getParentFile();
    parent.mkdirs();/*  w  w  w .j a  v a 2s  .c  o  m*/
    try {
        L.d("writing file %s", exactPath.getAbsoluteFile());
        FileUtils.writeStringToFile(exactPath, contents);
    } catch (IOException e) {
        L.e(e, "Could not write to %s", exactPath);
    }
}

From source file:ch.bender.evacuate.Testconstants.java

/**
 * Creates a new file with given name in given parent directory.
 * <p>//  ww w. jav a 2 s  . c om
 * The path of the new file is written into the file.
 * <p>
 * 
 * @param aParent
 *        must be an existing directory       
 * @param aNewFileName
 *        the name of the new file
 * @return the path object of the new file
 * @throws IOException
 */
public static Path createNewFile(Path aParent, String aNewFileName) throws IOException {
    if (!Files.isDirectory(aParent)) {
        throw new IllegalArgumentException("Given parent is not a directory or does not exist");
    }

    Path file1 = Paths.get(aParent.toString(), aNewFileName);
    Files.createFile(file1);
    FileUtils.writeStringToFile(file1.toFile(), file1.toString() + "\n");
    return file1;
}

From source file:com.enonic.cms.framework.util.HttpServletRangeUtilTest.java

public HttpServletRangeUtilTest() throws Exception {
    final URL url = getClass().getResource("input.dat");

    INPUT_FILE = File.createTempFile("range-test", "dat");

    FileUtils.writeStringToFile(INPUT_FILE, Resources.toString(url, Charsets.UTF_8));

    INPUT_FILE.deleteOnExit();//from w  ww. ja va  2 s .co m
}

From source file:ezbake.security.persistence.impl.FileRegManagerTest.java

private static void writeDefaultFile(File path) throws IOException {
    FileUtils.writeStringToFile(path,
            "  - !!ezbake.security.persistence.model.AppPersistenceModel\n" + "    id: _Ez_Deployer\n"
                    + "    appDn: CN=_Ez_Deployer\n" + "    authorizationLevel: high\n"
                    + "    formalAuthorizations: [ A, B, C]\n"
                    + "  - !!ezbake.security.persistence.model.AppPersistenceModel\n" + "    id: _Ez_INS\n"
                    + "    appDn: CN=_Ez_INS\n" + "    authorizationLevel: high\n"
                    + "    formalAuthorizations: [ A, B, C]\n" + "    x509Cert: |\n"
                    + "      -----BEGIN CERTIFICATE-----\n" + "      lksdjfksjfkjsfksdfj");
}

From source file:net.sf.taverna.t2.maven.plugins.Utils.java

public static String uploadFile(File file, String resourceName, Wagon wagon, Log log)
        throws MojoExecutionException {
    String resourceUrl = getResourceUrl(wagon, resourceName);
    File digestFile = new File(file.getPath() + ".md5");
    try {/*from w w  w.  j a v  a  2  s .c o m*/
        String digestString = DigestUtils.md5Hex(new FileInputStream(file));
        FileUtils.writeStringToFile(digestFile, digestString);
    } catch (IOException e) {
        throw new MojoExecutionException(String.format("Error generating digest for %1$s", file), e);
    }
    try {
        log.info(String.format("Uploading %1$s to %2$s", file, resourceUrl));
        wagon.put(file, resourceName);
        wagon.put(digestFile, resourceName + ".md5");
    } catch (TransferFailedException e) {
        throw new MojoExecutionException(String.format("Error transferring %1$s to %2$s", file, resourceUrl),
                e);
    } catch (ResourceDoesNotExistException e) {
        throw new MojoExecutionException(String.format("%1$s does not exist", resourceUrl), e);
    } catch (AuthorizationException e) {
        throw new MojoExecutionException(
                String.format("Authentication error transferring %1$s to %2$s", file, resourceUrl), e);
    }
    return resourceUrl;
}