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.atoito.jeauty.FileProcessor.java
private RunResult processFile(File f) { //System.out.println( "PROCESS FILE:" + f ); String filePath = f.getAbsolutePath(); EnhancementResult result = beautifier.enhance(filePath); if (result.success) { if (options.isWrite()) { //System.out.println( " >> write contents to " + filePath ); try { Files.write(result.contents, f, options.getCharset()); } catch (IOException e) { return RunResult.fail(e); }//from w ww . j ava 2 s . c o m } else { System.out.printf("Would write %s%n", filePath); } } else { return RunResult.fail(result); } return RunResult.successful(); }
From source file:org.apache.sentry.tests.e2e.hive.PolicyFileEditor.java
public void removePolicy(String line) throws IOException { List<String> result = Lists.newArrayList(); for (String s : Files.readLines(policy, Charsets.UTF_8)) { if (!s.equals(line)) { result.add(s);// w ww .j a va 2 s . c om } } Files.write(Joiner.on(NL).join(result), policy, Charsets.UTF_8); }
From source file:org.opendaylight.yangtools.checkstyle.LogMessageExtractorCheck.java
protected void updateMessagesReportFile(LogMessageOccurence log) { try {//w w w . ja v a 2 s .c o m final File file = getLogMessagesReportFile(); file.getParentFile().mkdirs(); if (file.exists()) { Files.append(log.toString() + "\n", file, StandardCharsets.UTF_8); } else { Files.write(log.toString() + "\n", file, StandardCharsets.UTF_8); } } catch (IOException e) { LOG.error("Failed to append to file: {}", logMessagesReportFile.getPath(), e); } }
From source file:org.yes.cart.installer.ApacheTomcat7Configurer.java
private void configureHTTP() throws IOException { File serverXMLFile = new File(tomcatHome, "conf" + File.separator + "server.xml"); Files.write( Files.toString(serverXMLFile, Charset.forName("UTF-8")).replace("8080", String.valueOf(httpPort)), serverXMLFile, Charset.forName("UTF-8")); }
From source file:com.github.benmanes.caffeine.cache.simulator.report.TextReporter.java
/** Writes the report to the output destination. */ @Override/*from w ww. j av a 2s . c o m*/ public void print() throws IOException { results.sort(comparator()); String report = assemble(results); String output = settings.report().output(); if (output.equalsIgnoreCase("console")) { System.out.println(report); } else { File file = Paths.get(output).toFile(); Files.write(report, file, StandardCharsets.UTF_8); } }
From source file:uk.bl.dpt.qa.flint.CoreAppStepDefs.java
@Given("^I have a file \"(.*?)\" with the following content:$") public void i_have_a_file_with_the_following_content(String fileName, String content) throws Throwable { Files.write(content, new File(tempDir, fileName), Charset.defaultCharset()); }
From source file:com.huangyunkun.jviff.core.impl.HtmlResultReport.java
@Override public void report(List<StepResult> stepResults, File outputDir) throws IOException { Iterable<StepResult> stepResultIterable = Iterables.filter(stepResults, new Predicate<StepResult>() { @Override//ww w.j a v a 2 s .c o m public boolean apply(StepResult input) { return input.getStep().getRecord(); } }); final Context ctx = new Context(); ctx.setVariable("stepResults", stepResultIterable); String templateFile = Resources.getResource("html/index.html").getPath(); String html = templateEngine.process(templateFile, ctx); File outputFile = new File(outputDir, "index.html"); Files.write(html, outputFile, Charset.forName("utf8")); copyResources(outputDir); }
From source file:org.sonar.javascript.it.ProfileGenerator.java
public static void generateProfile(Orchestrator orchestrator) { Set<String> ruleKeys = getRuleKeys(orchestrator); ruleKeys.remove("CommentRegularExpression"); try {/* ww w. java 2 s .c om*/ StringBuilder sb = new StringBuilder().append("<profile>").append("<name>rules</name>") .append("<language>js</language>").append("<rules>"); for (String key : ruleKeys) { sb.append("<rule>").append("<repositoryKey>javascript</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.eclipse.xtext.xtext.wizard.cli.CliProjectsCreator.java
public void createProject(final ProjectDescriptor project) { String _location = project.getLocation(); final File projectRoot = new File(_location); projectRoot.mkdirs();/*from w w w .ja va 2 s . c om*/ final Consumer<AbstractFile> _function = (AbstractFile it) -> { try { String _pathFor = project.getConfig().getSourceLayout().getPathFor(it.getOutlet()); String _plus = (_pathFor + "/"); String _relativePath = it.getRelativePath(); final String projectRelativePath = (_plus + _relativePath); final File file = new File(projectRoot, projectRelativePath); file.getParentFile().mkdirs(); boolean _matched = false; if (it instanceof TextFile) { _matched = true; final String normalizedContent = ((TextFile) it).getContent().replace(Strings.newLine(), this.lineDelimiter); Files.write(normalizedContent, file, project.getConfig().getEncoding()); } if (!_matched) { if (it instanceof BinaryFile) { _matched = true; Files.write(Resources.toByteArray(((BinaryFile) it).getContent()), file); } } boolean _isExecutable = it.isExecutable(); if (_isExecutable) { file.setExecutable(true); } } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }; project.getFiles().forEach(_function); final Consumer<String> _function_1 = (String it) -> { new File(projectRoot, it).mkdirs(); }; project.getSourceFolders().forEach(_function_1); }
From source file:org.gradle.api.internal.resources.ApiTextResourceAdapter.java
@Override public File asFile(String targetCharset) { try {// w w w . j ava2 s .c o m File file = getWrappedTextResource().getFile(); if (file == null) { file = tempFileProvider.createTemporaryFile("wrappedInternalText", ".txt", "resource"); Files.write(getWrappedTextResource().getText(), file, Charset.forName(targetCharset)); return file; } Charset sourceCharset = getWrappedTextResource().getCharset(); Charset targetCharsetObj = Charset.forName(targetCharset); if (targetCharsetObj.equals(sourceCharset)) { return file; } File targetFile = tempFileProvider.createTemporaryFile("uriTextResource", ".txt", "resource"); try { Files.asCharSource(file, sourceCharset).copyTo(Files.asCharSink(targetFile, targetCharsetObj)); return targetFile; } catch (IOException e) { throw new ResourceException( "Could not write " + getDisplayName() + " content to " + targetFile + ".", e); } } catch (Exception e) { throw ResourceExceptions.readFailed(getDisplayName(), e); } }