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.android.build.gradle.internal.incremental.InstantRunWrapperTask.java
@TaskAction public void executeAction() { // done with the instant run context. instantRunBuildContext.close();/* w w w.j a va2s . co m*/ // saves the build information xml file. try { // only write past builds in incremental mode. String xml = instantRunBuildContext.toXml(); if (logger.isEnabled(LogLevel.DEBUG)) { logger.debug("build-id $1$l, build-info.xml : %2$s", instantRunBuildContext.getBuildId(), xml); } Files.createParentDirs(buildInfoFile); Files.write(xml, buildInfoFile, Charsets.UTF_8); } catch (Exception e) { throw new RuntimeException(String.format("Exception while saving build-info.xml : %s", e.getMessage())); } // since we closed and produce the build-info.xml, delete any temporary one. if (tmpBuildInfoFile.exists()) { if (!tmpBuildInfoFile.delete()) { logger.warn(String.format("Cannot delete %1$s", tmpBuildInfoFile)); } } // Record instant run status in analytics for this build ProcessRecorder.getGlobalProperties() .setInstantRunStatus(InstantRunAnalyticsHelper.generateAnalyticsProto(instantRunBuildContext)); }
From source file:com.github.rinde.gpem17.GenerateParams.java
static void generateTuningExperiments() throws IOException { // #tt-td-ot/*from w ww. j a v a 2 s . c o m*/ for (String weights : ImmutableList.of("1-1-1", ".5-1-1")) { // seeds obtained from random.org for (long seed : ImmutableList.of(91404445L, 56862982L, 76980253L)) { StringBuilder sb = new StringBuilder("parent.0 = ../gpem17tuning-common.params"); sb.append(System.lineSeparator()).append(System.lineSeparator()).append("seed.0 = ").append(seed) .append(System.lineSeparator()).append("eval.obj_func_weights = ").append(weights) .append(System.lineSeparator()); File dir = new File("files/config/tuning-experiments"); dir.mkdir(); File f = new File(dir, seed + "-" + weights + ".params"); Files.write(sb.toString(), f, Charsets.UTF_8); } } }
From source file:org.trancecode.xproc.PipelineResult.java
public void readNode(final String portName, final File outputFile) { Preconditions.checkNotNull(outputFile); final XdmNode node = Iterables.getOnlyElement(readNodes(portName)); try {/*from ww w .j a v a2 s . c o m*/ Files.write(node.toString(), outputFile, Charset.defaultCharset()); } catch (final IOException e) { throw new RuntimeIOException(e); } }
From source file:com.insightml.utils.io.IoUtils.java
public static void write(final String text, final File file, final Charset charset) { try {//from ww w . j a v a2 s .c o m Files.write(Check.length(text, 0, 1999999999), file, charset); } catch (final IOException e) { throw new IllegalArgumentException(e); } }
From source file:com.streamsets.datacollector.util.MiniSDCSystemProcessImpl.java
public MiniSDCSystemProcessImpl(String name, File tempDir, List<String> args, File testDir) { super(name, tempDir, testDir); if (args.contains("start")) { int index = args.indexOf("--class"); // add properties file for yarn configs for mini test cases args.add(index, "--properties-file"); LOG.debug("Spark property file is at " + System.getProperty("SPARK_PROPERTY_FILE")); args.add(index + 1, System.getProperty("SPARK_PROPERTY_FILE")); }//from ww w .ja v a2 s .co m File yarnCommand = new File(tempDir, "yarn-command"); if (!yarnCommand.isFile() || !yarnCommand.canExecute()) { if (!yarnCommand.delete()) { LOG.warn("Failed to delete yarn command file " + yarnCommand); } try { Files.write(YARN_COMMAND_TEXT, yarnCommand, StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } if (!yarnCommand.canExecute() && !yarnCommand.setExecutable(true)) { throw new RuntimeException("Could not set " + yarnCommand + " executable"); } } this.yarnCommand = yarnCommand.getAbsolutePath(); this.args = ImmutableList.copyOf(args); this.testDir = testDir; }
From source file:com.autoupdater.client.xml.creators.InstallationDataXMLCreator.java
/** * Creates XML document with installation data and stores it info file. * //ww w. ja v a 2s. c o m * @param destination * destination file * @param installationData * programs which data needs to be saved * @throws IOException * thrown when error occurs during storing data to file */ public void createXML(File destination, SortedSet<Program> installationData) throws IOException { logger.debug("Save installation data at: " + destination.getCanonicalPath()); Document installationDataXML = DocumentHelper.createDocument(); installationDataXML.addComment(XMLCreationConfiguration.DO_NOT_EDIT_FILE_MANUALLY_WARNING); Element installed = installationDataXML.addElement(InstallationDataSchema.installed); addPrograms(installed, installationData); Files.write(installationDataXML.asXML(), destination, XMLCreationConfiguration.XML_ENCODING); logger.trace("Saved installation data at: " + destination.getCanonicalPath()); }
From source file:com.android.builder.internal.TemplateProcessor.java
private void writeFile(File file, String content) throws IOException { Files.write(content, file, Charsets.UTF_8); }
From source file:de.dennishoersch.web.jsf.resources.stylesheet.ProcessingStylesheetBuilder.java
/** * * @return the resource metadata/*from w w w. j ava 2 s. c om*/ * @throws IOException */ public GeneratedResourceMetadata build() throws IOException { String stylesheet = readAndConcatFileContents(); stylesheet = _processor.process(stylesheet, _context); String cssFilename = getGeneratedFilename(); String resourceFileName = asAbsoluteResourceFileName(cssFilename); Files.write(stylesheet, new File(resourceFileName), Charset.defaultCharset()); return newGeneratedResourceMetadata(cssFilename); }
From source file:net.minecraftforge.gradle.patcher.TaskMergeFiles.java
private void mergeFiles(FileCollection in, String ending, File out) throws IOException { Set<String> lines = Sets.newLinkedHashSet(); for (File f : in.getFiles()) { if (f.isDirectory() || !f.exists() || !f.getName().endsWith(ending)) continue; lines.addAll(Files.readLines(f, Constants.CHARSET)); }// w ww . ja v a 2s . co m out.getParentFile().mkdirs(); Files.write(Joiner.on('\n').join(lines), out, Constants.CHARSET); }
From source file:com.smartbear.soapui.utils.jetty.JettyTestCaseBase.java
protected void replaceInFile(String fileName, String from, String to) throws IOException { File wsdlFile = new File(getResourceBase(), fileName); String wsdl = Files.toString(wsdlFile, Charset.forName("UTF-8")); wsdl = wsdl.replace(from, to);//from w w w . java2 s.co m Files.write(wsdl, wsdlFile, Charset.forName("UTF-8")); }