List of usage examples for com.google.common.io Files write
public static void write(CharSequence from, File to, Charset charset) throws IOException
From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.FixedUserIDMapper.java
public static String getCurrentGroup() { File script = null;/*from w ww . ja v a 2s . co m*/ try { script = File.createTempFile("group", ".sh"); String[] cmd = { "bash", script.getAbsolutePath() }; Files.write("groups | cut -d ' ' -f 1", script, Charsets.UTF_8); return Shell.execCommand(cmd).trim(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (script != null) { script.delete(); } } }
From source file:org.eclipse.epp.internal.logging.aeri.ui.utils.AnonymousId.java
private static UUID readOrCreateUUID() throws IOException { File f = new File(getUserHome(), ".eclipse/org.eclipse.recommenders/anonymousId"); if (f.exists()) { String uuid = Files.readFirstLine(f, Charsets.UTF_8); return UUID.fromString(uuid); } else {/*from w ww . ja va 2 s. c o m*/ f.getParentFile().mkdirs(); UUID uuid = UUID.randomUUID(); Files.write(uuid.toString(), f, Charsets.UTF_8); return uuid; } }
From source file:eu.numberfour.n4js.antlr.internal.AntlrCodeQualityHelper.java
/** * Remove all unnecessary comments from the java code that was produced by Antlr *//*from w w w.j a v a 2s.c om*/ public static void stripUnnecessaryComments(String javaFile, Charset encoding) throws IOException { String content = Files.toString(new File(javaFile), encoding); content = new NewlineNormalizer().toUnixLineDelimiter(content); content = content.replaceAll("(?m)^(\\s+)// .*/(\\w+\\.g:.*)$", "$1// $2"); content = content.replaceAll("(public String getGrammarFileName\\(\\) \\{ return \").*/(\\w+\\.g)(\"; \\})", "$1$2$3"); Files.write(content, new File(javaFile), encoding); }
From source file:org.opendaylight.alto.ext.cli.fileconverter.FileConverterHelper.java
public void save(String path, String content) throws Exception { File file = new File(path); Files.write(content, file, StandardCharsets.US_ASCII); }
From source file:org.dswarm.tools.utils.DswarmToolUtils.java
public static void writeToFile(final String content, final String directory, final String fileName) throws IOException { checkDirExistenceOrCreateMissingParts(directory); final File file = org.apache.commons.io.FileUtils.getFile(directory, fileName); Files.write(content, file, Charsets.UTF_8); }
From source file:org.glowroot.common.util.PropertiesFiles.java
public static void upgradeIfNeeded(File propFile, Map<String, String> findReplacePairs) throws IOException { // properties files must be ISO_8859_1 String content = Files.toString(propFile, ISO_8859_1); boolean modified = false; for (Map.Entry<String, String> entry : findReplacePairs.entrySet()) { String find = entry.getKey(); if (content.contains(find)) { content = content.replace(find, entry.getValue()); modified = true;/*from www. java 2 s . c om*/ } } if (modified) { Files.write(content, propFile, ISO_8859_1); } }
From source file:bwfla.modules.pdp.client.Helper.java
/** * //from w ww . ja v a 2 s . c o m * @param path * @param content */ public static void writeContentToFile(@NonNull String path, @NonNull String content) { URL url = Helper.class.getClassLoader().getResource(path); try { Files.write(content, new File(url.getFile()), Charsets.UTF_8); } catch (IOException e) { log.error("Could not write to file " + path, e); } }
From source file:com.github.rinde.rinsim.scenario.measure.MetricsIO.java
/** * Writes the specified list of {@link Point}s to the specified file. Each * point is printed on a separate line using the following format: * * <pre>//from w ww .j av a2 s . c om * {@code x y } * </pre> * * i.e. the coordinates are space-separated. * @param locations The locations to write to file. * @param f The file to write to, non-existing parent directories will be * created. */ public static void writeLocationList(List<Point> locations, File f) { final StringBuilder sb = new StringBuilder(); for (final Point p : locations) { sb.append(p.x).append(SPACE).append(p.y).append(System.lineSeparator()); } try { Files.createParentDirs(f); Files.write(sb.toString(), f, Charsets.UTF_8); } catch (final IOException e) { throw new IllegalStateException(e); } }
From source file:org.apache.brooklyn.entity.chef.ChefServerTasks.java
/** extract key to a temp file, but one per machine, scheduled for deletion afterwards; * we extract the key because chef has no way to accept passphrases at present */ synchronized static File extractKeyFile(SshMachineLocation machine) { File f = new File(getExtractedKeysDir(), machine.getAddress().getHostName() + ".pem"); if (f.exists()) return f; KeyPair data = machine.findKeyPair(); if (data == null) return null; try {/*from www. ja v a 2s. c om*/ f.deleteOnExit(); Files.write(SecureKeys.stringPem(data), f, Charset.defaultCharset()); return f; } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:info.servertools.core.util.FileUtils.java
/** * Write a string to file//from w w w . j a v a 2 s . c o m * <p> * <b>IO is done on a separate thread!</b> * </p> * * @param string * the string to write * @param file * the file to write to */ public static void writeStringToFile(final String string, final File file) { new Thread() { @Override public void run() { try { Files.write(string, file, Reference.CHARSET); } catch (IOException e) { ServerTools.LOG.log(Level.WARN, "Failed to save file to disk", e); } } }.start(); }