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:org.locationtech.geogig.osm.internal.log.WriteOSMFilterFile.java

@Override
protected Void _call() {
    Preconditions.checkNotNull(entry);//from  ww  w . j a  v a2 s .co m
    Preconditions.checkNotNull(filter);
    URL url = command(ResolveOSMLogfile.class).call();
    File logfile = new File(url.getFile());
    File file = new File(logfile.getParentFile(), "filter" + entry.getId().toString());
    try {
        Files.write(filter, file, Charsets.UTF_8);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    return null;
}

From source file:org.opendaylight.controller.config.yangjmxgenerator.plugin.java.GeneratedObject.java

public Optional<Entry<FullyQualifiedName, File>> persist(File srcDirectory, boolean overwrite)
        throws IOException {
    File dstFile = fqn.toFile(srcDirectory);
    if (overwrite || !dstFile.exists()) {
        Files.createParentDirs(dstFile);
        Files.touch(dstFile);/*from   w  w  w . j a  v a 2s  .com*/
        Files.write(content, dstFile, StandardCharsets.UTF_8);
        return Optional.of(Maps.immutableEntry(fqn, dstFile));
    } else {
        return Optional.absent();
    }
}

From source file:com.geico.tfs.matcher.TfsMatcherWriter.java

public void writeFileListXml(Iterable<File> files) {
    appendLine(sb, "  <Files>");
    for (File file : files) {
        appendLine(sb, "    <File>" + file.getAbsolutePath() + "</File>");
    }/*from  w ww.j av a 2  s . c  o m*/
    appendLine(sb, "  </Files>");
    try {
        Files.write(sb, new File(filename), Charsets.UTF_8);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.cloudera.science.ml.client.cmd.GetHeaderCommand.java

@Override
public int execute(Configuration conf) throws IOException {
    HCatalogSpec spec = HCatalog.getSpec(HCatalog.getDbName(table), HCatalog.getTableName(table));
    Files.write(spec.toHeader().toString(), new File(headerFile), Charsets.UTF_8);
    return 0;//from ww w  .ja v  a 2 s  .  co  m
}

From source file:org.geogit.osm.internal.log.WriteOSMMappingEntries.java

@Override
public Void call() {
    Preconditions.checkNotNull(entry);/*from w  w  w  .  j a v  a2  s.  co  m*/
    Preconditions.checkNotNull(mapping);
    final File osmMapFolder = command(ResolveOSMMappingLogFolder.class).call();
    for (MappingRule rule : mapping.getRules()) {
        File file = new File(osmMapFolder, rule.getName());
        try {
            Files.write(entry.toString(), file, Charsets.UTF_8);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
    }
    File file = new File(osmMapFolder, entry.getPostMappingId().toString());
    try {
        Files.write(mapping.toString(), file, Charsets.UTF_8);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    return null;
}

From source file:se.kth.karamel.backend.kandy.KandyRestClient.java

private static void storeLocally(String clusterName, ClusterStats stats) {
    String json = stats.toJsonAndMarkNotUpdated();
    try {/*from   www .j a  v a2 s. c  om*/
        String name = clusterName.toLowerCase();
        File folder = new File(Settings.CLUSTER_STATS_FOLDER(name));
        if (!folder.exists()) {
            folder.mkdirs();
        }
        File file = new File(Settings.CLUSTER_STATS_PATH(name, stats.getLocalId()));
        if (file.exists()) {
            file.delete();
        }
        Files.write(json, file, Charset.forName("UTF-8"));
    } catch (IOException ex) {
        logger.error("Could not save cluster stats locally " + ex.getMessage());
    }
}

From source file:org.eclipse.scout.docs.publish.PublishUtility.java

/**
 * Take a single HTML file and publish it to the outFolder.
 * Images and CSS resources are moved./*from   w w  w. j  a  v a2  s  .co m*/
 *
 * @param inFolder
 *          root folder where the input HTML file is located.
 * @param inFileName
 *          name of the input HTML file (with extension)
 * @param outFolder
 *          directory where the post-processed HTML file is saved.
 * @throws IOException
 */
public static void publishHtmlFile(File inFolder, String inFileName, File outFolder) throws IOException {
    if (!inFolder.exists() || !inFolder.isDirectory()) {
        throw new IllegalStateException("Folder inFolder '" + inFolder.getAbsolutePath() + "' not found.");
    }
    File inFile = new File(inFolder, inFileName);
    if (!inFile.exists()) {
        throw new IllegalStateException("File inFile '" + inFolder.getAbsolutePath() + "' does not exist.");
    }

    File outFile = new File(outFolder, inFile.getName());
    String html = Files.toString(inFile, Charsets.ISO_8859_1);

    Document doc = Jsoup.parse(html);
    doc.outputSettings().charset("ASCII");

    fixListingLink(doc);
    fixFigureLink(doc);

    Files.createParentDirs(outFile);
    moveAndcopyImages(doc, inFolder, outFolder, "images/");

    Files.write(doc.toString(), outFile, Charsets.ISO_8859_1);
}

From source file:com.github.rinde.gpem17.Train.java

static void run(String configFile) {
    AvoidExitUtil.forbidSystemExitCall();
    try {/*from  ww w. j a  va2s.c o  m*/
        Evolve.main(new String[] { "-file", configFile });
    } catch (ExitTrappedException e) {
    } finally {
        AvoidExitUtil.enableSystemExitCall();
    }
    File f = new File("nohup.out");
    if (f.exists()) {
        try {
            FileUtils.copyFileToDirectory(f, new File("files/results/evo/latest"), false);

            Files.write("", f, Charsets.UTF_8);
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
}

From source file:com.google.enterprise.adaptor.GsaFeedFileArchiver.java

public void saveFeed(String feedName, String feedXml) {
    if (archiveDir != null) {
        try {//  w ww. j a  v a 2  s .  c o m
            File file = File.createTempFile(feedName + "-", ".xml", archiveDir);
            Files.write(feedXml, file, CHARSET_UTF8);
        } catch (IOException e) {
            log.log(Level.WARNING, "failed to archive feed file", e);
        }
    }
}

From source file:com.infinities.skyport.util.RSAUtil.java

private static void savePem(File file, String privateKeyStr) throws IOException {
    Files.write(privateKeyStr, file, Charsets.UTF_8);
}