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.github.fommil.netlib.generator.AbstractNetlibGenerator.java
@Override public void execute() throws MojoExecutionException { try {/*from ww w .ja va2 s. c o m*/ project.addCompileSourceRoot(outputDir.getAbsolutePath()); File output = new File(outputDir, outputName); if (output.exists() && project.getFile().lastModified() < output.lastModified()) { getLog().info("No changes detected, skipping: " + output); return; } if (Strings.isNullOrEmpty(javadoc)) getLog().warn("Javadocs not attached for paranamer."); else paranamer = new CachingParanamer(new JavadocParanamer(getFile(javadoc))); File jar = getFile(input); JarMethodScanner scanner = new JarMethodScanner(jar); List<Method> methods = Lists .newArrayList(Iterables.filter(scanner.getStaticMethods(scan), new Predicate<Method>() { @Override public boolean apply(Method input) { return exclude == null || !input.getName().matches(exclude); } })); String generated = generate(methods); output.getParentFile().mkdirs(); getLog().info("Generating " + output.getAbsoluteFile()); Files.write(generated, output, Charsets.UTF_8); } catch (Exception e) { throw new MojoExecutionException("java generation", e); } }
From source file:net.sourceforge.docfetcher.website.Website.java
private static void convertDir(@NotNull PegDownProcessor processor, @NotNull PageProperties props, @NotNull File srcDir, @NotNull File dstDir) throws IOException { for (File mdFile : Util.listFiles(srcDir)) { if (mdFile.equals(props.propsFile)) continue; if (!mdFile.isFile()) continue; String name = mdFile.getName(); if (!name.endsWith(".markdown")) continue; Util.println("Converting: " + name); String rawText = CharsetDetectorHelper.toString(mdFile); String htmlBody = processor.markdownToHtml(rawText); String newFilename = Util.splitFilename(name)[0] + ".html"; File htmlFile = new File(dstDir, newFilename); String html = convertPage(props, mdFile, htmlBody); Files.write(html, htmlFile, Charsets.UTF_8); }/*from w w w . j a v a 2 s.com*/ }
From source file:org.opendaylight.controller.config.persist.storage.file.FileStorageAdapter.java
@Override public void persistConfig(ConfigSnapshotHolder holder) throws IOException { Preconditions.checkNotNull(storage, "Storage file is null"); String content = Files.toString(storage, ENCODING); if (numberOfStoredBackups == Integer.MAX_VALUE) { resetLastConfig(content);/*from w ww . jav a 2s . c o m*/ persistLastConfig(holder); } else { if (numberOfStoredBackups == 1) { Files.write("", storage, ENCODING); persistLastConfig(holder); } else { int count = StringUtils.countMatches(content, SEPARATOR_S); if ((count + 1) < numberOfStoredBackups) { resetLastConfig(content); persistLastConfig(holder); } else { String contentSubString = StringUtils.substringBefore(content, SEPARATOR_E); contentSubString = contentSubString.concat(SEPARATOR_E_PURE); content = StringUtils.substringAfter(content, contentSubString); resetLastConfig(content); persistLastConfig(holder); } } } }
From source file:com.android.idegen.IntellijProject.java
private void createModulesFile(File ideaDir, Iterable<Module> modules) throws IOException { String modulesContent = Files.toString( new File(DirectorySearch.findTemplateDir(), "idea" + File.separator + MODULES_TEMPLATE_FILE_NAME), CHARSET);//from ww w . ja v a2s . com StringBuilder sb = new StringBuilder(); for (Module mod : modules) { File iml = mod.getImlFile(); sb.append(" <module fileurl=\"file://").append(iml.getCanonicalPath()).append("\" filepath=\"") .append(iml.getCanonicalPath()).append("\" />\n"); } modulesContent = modulesContent.replace("@MODULES@", sb.toString()); File out = new File(ideaDir, "modules.xml"); logger.info("Creating " + out.getCanonicalPath()); Files.write(modulesContent, out, CHARSET); }
From source file:com.facebook.buck.cli.SimulateCommand.java
private void outputReport(ObjectMapper jsonConverter, SimulateReport report) throws IOException { // Pretty print the output. jsonConverter.enable(SerializationFeature.INDENT_OUTPUT); jsonConverter.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); jsonConverter.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); String json = jsonConverter.writeValueAsString(report); LOG.verbose("SimulateReport => [%s]", json); Files.write(json, new File(simulateReportFile), Charsets.UTF_8); }
From source file:org.pshdl.model.simulation.codegenerator.GoCodeGenerator.java
public IHDLInterpreterFactory<NativeRunner> createInterpreter(final File tempDir) { try {/*from www . ja va2 s .c o m*/ IHDLInterpreterFactory<NativeRunner> _xblockexpression = null; { final CharSequence dartCode = this.generateMainCode(); final File dutFile = new File(tempDir, "TestUnit.go"); Files.createParentDirs(dutFile); Files.write(dartCode, dutFile, StandardCharsets.UTF_8); final File testRunner = new File(tempDir, "runner.go"); final InputStream runnerStream = CCodeGenerator.class .getResourceAsStream("/org/pshdl/model/simulation/includes/runner.go"); final FileOutputStream fos = new FileOutputStream(testRunner); try { ByteStreams.copy(runnerStream, fos); } finally { fos.close(); } String _absolutePath = testRunner.getAbsolutePath(); String _absolutePath_1 = dutFile.getAbsolutePath(); ProcessBuilder _processBuilder = new ProcessBuilder("/usr/local/go/bin/go", "build", _absolutePath, _absolutePath_1); ProcessBuilder _directory = _processBuilder.directory(tempDir); ProcessBuilder _redirectErrorStream = _directory.redirectErrorStream(true); final ProcessBuilder goBuilder = _redirectErrorStream.inheritIO(); final Process goCompiler = goBuilder.start(); int _waitFor = goCompiler.waitFor(); boolean _notEquals = (_waitFor != 0); if (_notEquals) { throw new RuntimeException("Compilation of Go Program failed"); } _xblockexpression = new IHDLInterpreterFactory<NativeRunner>() { public NativeRunner newInstance() { try { final File runnerExecutable = new File(tempDir, "runner"); String _absolutePath = runnerExecutable.getAbsolutePath(); ProcessBuilder _processBuilder = new ProcessBuilder(_absolutePath); ProcessBuilder _directory = _processBuilder.directory(tempDir); final ProcessBuilder goBuilder = _directory.redirectErrorStream(true); final Process goRunner = goBuilder.start(); InputStream _inputStream = goRunner.getInputStream(); OutputStream _outputStream = goRunner.getOutputStream(); String _absolutePath_1 = runnerExecutable.getAbsolutePath(); return new NativeRunner(_inputStream, _outputStream, GoCodeGenerator.this.em, goRunner, 5, _absolutePath_1); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } }; } return _xblockexpression; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
From source file:org.apache.isis.tool.mavenplugin.IsisMojoXsd.java
private void writeSchemas(final JaxbService jaxbService, final String dtoClassName, final File outputDir) throws MojoFailureException { final Object instance = InstanceUtil.createInstance(dtoClassName); final Map<String, String> schemaByNamespace = jaxbService.toXsd(instance, commonSchemas ? JaxbService.IsisSchemas.INCLUDE : JaxbService.IsisSchemas.IGNORE); final File schemaDir = separate ? new File(outputDir, dtoClassName) : outputDir; unnamed = 0;/*from ww w. jav a 2 s. co m*/ for (Map.Entry<String, String> entry : schemaByNamespace.entrySet()) { final String namespaceUri = entry.getKey(); final String schemaText = entry.getValue(); final String xsdName = xsdDirNameFor(namespaceUri); final File schemaFile = new File(schemaDir, xsdName); try { Files.createParentDirs(schemaFile); } catch (IOException e) { throw new MojoFailureException(String.format("Failed to create dir: '%s'", schemaFile.getParent())); } try { Files.write(schemaText, schemaFile, Charsets.UTF_8); } catch (IOException e) { throw new MojoFailureException("Failed to write out " + schemaFile); } if (!xsdName.endsWith(".xsd")) { final File schemaFileWithXsdSuffix = new File(schemaDir, xsdName + ".xsd"); try { Files.copy(schemaFile, schemaFileWithXsdSuffix); } catch (IOException e) { throw new MojoFailureException("Failed to copy to " + schemaFileWithXsdSuffix); } } } }
From source file:com.android.sdklib.repository.License.java
/** * Marks this license as accepted./* w ww .j ava2 s . c om*/ * * @param sdkRoot The root directory of the Android SDK * @return true if the acceptance was persisted successfully. */ public boolean setAccepted(@Nullable File sdkRoot) { if (sdkRoot == null) { return false; } if (checkAccepted(sdkRoot)) { return true; } File licenseDir = new File(sdkRoot, LICENSE_DIR); if (licenseDir.exists() && !licenseDir.isDirectory()) { return false; } if (!licenseDir.exists()) { licenseDir.mkdir(); } File licenseFile = new File(licenseDir, mLicenseRef == null ? mLicenseHash : mLicenseRef); try { Files.write(mLicenseHash, licenseFile, Charsets.UTF_8); } catch (IOException e) { return false; } return true; }
From source file:de.tu_berlin.dima.oligos.io.DistributionWriter.java
@Override public void write() throws IOException, SQLException { distributionFile.mkdirs();/* ww w . j a v a2 s. co m*/ distributionFile.delete(); distributionFile.createNewFile(); Files.write(getDistributionString(), distributionFile, Charsets.UTF_8); if (column.isEnumerated()) { domainFile.mkdirs(); domainFile.delete(); domainFile.createNewFile(); Files.write(getDomainString(), domainFile, Charsets.UTF_8); } }
From source file:com.bsiag.htmltools.internal.PublishUtility.java
/** * Take a single HTML file and publish it to the outFolder. * Images and CSS resources are moved, HTML is formatted. * * @param inFolder/*from w w w . j a va 2s .c o m*/ * root folder where the input HTML file is located. * @param outFolder * directory where the post-processed HTML file is saved. * @param cssReplacement * @param pageList * @param root * @param fixXrefLinks * tells if the cross references links should be fixed as described here * https://github.com/asciidoctor/asciidoctor/issues/858 * @param fixExternalLinks * add taget="_blank" on links starting with http(s):// or ftp:// * @throws IOException */ private static void publishHtmlFile(File inFolder, File inFile, File outFolder, Map<String, File> cssReplacement, List<File> pageList, RootItem root, boolean fixXrefLinks, boolean fixExternalLinks) throws IOException { File outFile = new File(outFolder, inFile.getName()); String html = Files.toString(inFile, Charsets.UTF_8); Document doc = Jsoup.parse(html); doc.outputSettings().charset("ASCII"); if (pageList != null && pageList.size() > 1) { fixNavigation(doc, inFile, pageList, root); } if (fixXrefLinks) { fixListingLink(doc); fixFigureLink(doc); fixTableLink(doc); } if (fixExternalLinks) { fixExternalLinks(doc); } Files.createParentDirs(outFile); moveAndCopyImages(doc, inFolder, outFolder, IMAGES_SUB_PATH); moveAndCopyCss(doc, inFolder, outFolder, CSS_SUB_PATH, cssReplacement); String content = trimTrailingWhitespaces(doc.toString()); Files.write(content, outFile, Charsets.UTF_8); }