Example usage for com.google.common.io Files write

List of usage examples for com.google.common.io Files write

Introduction

In this page you can find the example usage for com.google.common.io Files write.

Prototype

public static void write(CharSequence from, File to, Charset charset) throws IOException 

Source Link

Usage

From source file:com.facebook.buck.step.fs.WriteFileStep.java

@Override
public int execute(ExecutionContext context) {
    try {/*from  w w w .java 2  s .com*/
        // echo by default writes a trailing new line and so should we.
        Files.write(content.get() + "\n", context.getProjectFilesystem().getFileForRelativePath(outputPath),
                Charsets.UTF_8);
        return 0;
    } catch (IOException e) {
        e.printStackTrace(context.getStdErr());
        return 1;
    }
}

From source file:google.registry.tools.GetClaimsListCommand.java

@Override
public void run() throws Exception {
    ClaimsListShard cl = checkNotNull(ClaimsListShard.get(), "Couldn't load ClaimsList");
    String csv = Joiner.on('\n').withKeyValueSeparator(",").join(cl.getLabelsToKeys()) + "\n";
    Files.write(csv, output.toFile(), UTF_8);
}

From source file:org.artifactory.converters.MimeTypeConverter.java

@Override
public void convert(CompoundVersionDetails source, CompoundVersionDetails target) {
    if (!path.exists()) {
        throw new RuntimeException(
                "Couldn't start Artifactory. Mime types file is missing: " + path.getAbsolutePath());
    }//w w  w. j av  a  2  s  . c  o  m

    try {
        String mimeTypesXml = Files.toString(path, Charsets.UTF_8);
        MimeTypesVersion mimeTypesVersion = MimeTypesVersion.findVersion(mimeTypesXml);
        if (!mimeTypesVersion.isCurrent()) {
            String result = mimeTypesVersion.convert(mimeTypesXml);
            Files.write(result, path, Charsets.UTF_8);
        }
    } catch (Exception e) {
        throw new RuntimeException("Failed to execute mimetypes conversion", e);
    }
}

From source file:org.apache.whirr.service.hadoop.HadoopProxy.java

public String[] getProxyCommand() throws IOException {
    checkState(clusterSpec.getPrivateKeyFile() != null || clusterSpec.getPrivateKey() != null,
            "privateKey is needed");
    File identity = clusterSpec.getPrivateKeyFile();
    if (identity == null) {
        identity = File.createTempFile("hadoop", "key");
        identity.deleteOnExit();//  w ww. j ava2s .  com
        Files.write(clusterSpec.getPrivateKey(), identity, Charsets.UTF_8);
    }
    KeyPair.setPermissionsTo600(identity);
    String user = clusterSpec.getClusterUser();
    InetAddress namenode = HadoopCluster.getNamenodePublicAddress(cluster);
    String server = namenode.getHostName();
    return new String[] { "ssh", "-i", identity.getAbsolutePath(), "-o", "ConnectTimeout=10", "-o",
            "ServerAliveInterval=60", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null",
            "-o", "StrictHostKeyChecking=no", "-N", "-D 6666", String.format("%s@%s", user, server) };
}

From source file:com.articulate.sigma.test.CVSExporter.java

public void flushIfEnabled() {
    if (enabled) {
        try {//from w w w  . j  a  v  a 2  s  . c  o m
            File file = new File("testresults-exported-" + System.currentTimeMillis() + ".csv");
            Files.write(collectedOutput.toString(), file, Charsets.UTF_8);
            System.out.println("Results exported to: " + file.getPath());
        } catch (IOException e) {
            e.printStackTrace();
        }
        collectedOutput = null;
    }
}

From source file:org.jboss.maven.plugins.qstools.fixers.XMLTabFixer.java

@Override
public void fixProject(MavenProject project, Document doc) throws Exception {
    List<File> xmlFiles = FileUtils.getFiles(project.getBasedir(), "**/*.xml", "");
    for (File xmlSource : xmlFiles) {
        getLog().debug("Fixing tab on " + xmlSource);
        String source = Files.toString(xmlSource, Charset.forName("UTF-8"));
        String replaced = source.replace("\t", "    ");
        Files.write(replaced, xmlSource, Charset.forName("UTF-8"));
    }//from ww w  .j  a v  a2 s .c o  m

}

From source file:com.autoupdater.client.xml.creators.FileCacheXMLCreator.java

/**
 * Creates XML document with file cache data and stores it info file.
 * /*ww  w  . ja v a 2  s.c  om*/
 * @param destination
 *            destination file
 * @param fileCache
 *            file cache which needs to be saved
 * @throws IOException
 *             thrown when error occurs during storing data to file
 */
public void createXML(File destination, Map<String, String> fileCache) throws IOException {
    logger.debug("Save file cache data at: " + destination.getCanonicalPath());
    Document fileCacheXML = DocumentHelper.createDocument();
    fileCacheXML.addComment(XMLCreationConfiguration.DO_NOT_EDIT_FILE_MANUALLY_WARNING);
    Element files = fileCacheXML.addElement(FileCacheSchema.files);
    addFiles(files, fileCache);
    Files.write(fileCacheXML.asXML(), destination, XMLCreationConfiguration.XML_ENCODING);
    logger.trace("Saved file cache data at: " + destination.getCanonicalPath());
}

From source file:org.ops4j.pax.carrot.ui.EditorController.java

public void save() {

    file = treeBean.getSelectedFile();//from   w w w.  j a  v  a2s . c o  m
    try {
        Files.write(content, file, UTF8);
    } catch (IOException exc) {
        throw new CarrotException(exc);
    }
}

From source file:org.sonar.gherkin.its.ProfileGenerator.java

public static void generateProfile(Orchestrator orchestrator) {
    try {//from w ww .j  a  v  a2s.co  m
        StringBuilder sb = new StringBuilder().append("<profile>").append("<name>rules</name>")
                .append("<language>gherkin</language>").append("<rules>");

        Set<String> ruleKeys = getRuleKeysFromRepository(orchestrator);

        for (String key : ruleKeys) {
            sb.append("<rule>").append("<repositoryKey>gherkin</repositoryKey>").append("<key>").append(key)
                    .append("</key>").append("<priority>INFO</priority>");

            Collection<Parameter> parameters = ProfileGenerator.parameters.get(key);
            if (!parameters.isEmpty()) {
                sb.append("<parameters>");
                for (Parameter parameter : parameters) {
                    sb.append("<parameter>").append("<key>").append(parameter.parameterKey).append("</key>")
                            .append("<value>").append(parameter.parameterValue).append("</value>")
                            .append("</parameter>");
                }
                sb.append("</parameters>");
            }

            sb.append("</rule>");
        }
        sb.append("</rules>").append("</profile>");

        File file = File.createTempFile("profile", ".xml");
        Files.write(sb, file, Charsets.UTF_8);
        orchestrator.getServer().restoreProfile(FileLocation.of(file));
        file.delete();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.cretz.sbnstat.scrape.Cache.java

public void add(String url, String html) throws IOException {
    //create a UUID that will define this document
    String uuid;/*from  www  .  j  a v  a2 s.co m*/
    File file;
    do {
        uuid = UUID.randomUUID().toString();
        file = new File(directory, uuid + ".html");
    } while (file.exists());
    //save HTML
    Files.write(html, file, Charset.forName("UTF8"));
    //add to URL property list
    urls.setProperty(url, uuid);
    //write the urls file
    Writer writer = new FileWriter(urlsFile);
    try {
        urls.store(writer, "Cache");
    } finally {
        Closeables.closeQuietly(writer);
    }
}