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:org.gradle.api.internal.resources.StringBackedTextResource.java
public File asFile(String charset) { File file = tempFileProvider.createTemporaryFile("string", ".txt", "resource"); try {//from w ww .j a v a2s. c o m Files.write(string, file, Charset.forName(charset)); } catch (IOException e) { throw new UncheckedIOException(e); } return file; }
From source file:org.locationtech.geogig.osm.internal.log.WriteOSMMappingEntries.java
@Override protected Void _call() { Preconditions.checkNotNull(entry);//from w ww. 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:com.ngdata.hbaseindexer.mr.MRTestUtil.java
public static File substituteZkHost(File file, String zkConnectString) throws IOException { String str = Files.toString(file, Charsets.UTF_8); str = str.replace("_MYPATTERN_", zkConnectString); File tmp = File.createTempFile("tmpIndexer", ".xml"); tmp.deleteOnExit();/*from w w w . ja va2 s.c o m*/ Files.write(str, tmp, Charsets.UTF_8); return tmp; }
From source file:com.google.api.tools.framework.importers.swagger.SwaggerFileWriter.java
/** Saves the individual file on disk with the fileContent. */ private static void saveFileOnDisk(FileWrapper fileWrapper) throws IOException { File file = new File(fileWrapper.getFilename()); Files.createParentDirs(file); Files.write(fileWrapper.getFileContents().toStringUtf8(), file, Charset.defaultCharset()); }
From source file:org.eclipse.scada.configuration.world.lib.utils.Helper.java
public static void createFile(final File file, final String data, final IProgressMonitor monitor) throws Exception { logger.debug("Writing string data file: {}", file); file.getParentFile().mkdirs();// ww w . j a v a 2 s .c om Files.write(data, file, Charset.forName("UTF-8")); }
From source file:org.n52.iceland.statistics.generator.ParameterGenerator.java
public void processClass(String filePath, List<Class<?>> classes) throws IOException { MdFormat formatter = new MdFormat(); formatter.setParameters(getParameters(classes)); String printable = formatter.create(); // System.out.println(printable); try {//from ww w. j av a 2 s . c o m Files.write(printable, new File(filePath), Charset.forName("UTF-8")); } catch (IOException e) { e.printStackTrace(); throw e; } }
From source file:net.minecraftforge.gradle.util.caching.WriteCacheAction.java
public void execute(ICachableTask task) { if (!task.doesCache()) return;//from w w w . ja va2 s . c om try { File outFile = task.getProject().file(annot.getValue(task)); if (outFile.exists()) { File hashFile = CacheUtil.getHashFile(outFile); Files.write(CacheUtil.getHashes(annot, inputs, task), hashFile, Constants.CHARSET); } } // error? spit it and do the task. catch (Exception e) { Throwables.propagate(e); } }
From source file:org.freeeed.services.Util.java
public static void writeTextFile(String fileName, String content) throws IOException { Files.write(content, new File(fileName), Charset.defaultCharset()); }
From source file:com.google.javascript.refactoring.ApplySuggestedFixes.java
/** * Applies the provided set of suggested fixes to the files listed in the suggested fixes. * The fixes can be provided in any order, but they may not have any overlapping modifications * for the same file./*from w w w.j a v a2 s.c om*/ */ public static void applySuggestedFixesToFiles(Iterable<SuggestedFix> fixes) throws IOException { Set<String> filenames = new HashSet<>(); for (SuggestedFix fix : fixes) { filenames.addAll(fix.getReplacements().keySet()); } Map<String, String> filenameToCodeMap = new HashMap<>(); for (String filename : filenames) { filenameToCodeMap.put(filename, Files.toString(new File(filename), UTF_8)); } Map<String, String> newCode = applySuggestedFixesToCode(fixes, filenameToCodeMap); for (Map.Entry<String, String> entry : newCode.entrySet()) { Files.write(entry.getValue(), new File(entry.getKey()), UTF_8); } }
From source file:com.cognifide.aet.common.RedirectWriter.java
public void write(String reportUrl) throws AETException { boolean directoryExists = tryCreateDirectory(); if (directoryExists) { File file = new File(getTargetPath()); try {/*from ww w .j a v a2s. co m*/ Files.write(getContent(reportUrl), file, Charsets.UTF_8); } catch (IOException e) { throw new AETException("Failed to create: " + FILE_NAME, e); } } else { throw new AETException("Failed to create directory: " + buildDirectory); } }