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.axelor.meta.schema.actions.ActionExport.java
protected String doExport(String dir, Export export, ActionHandler handler) throws IOException { String templatePath = handler.evaluate(export.template).toString(); Reader reader = null;//from w w w. j a v a2 s. c o m File template = new File(templatePath); if (template.isFile()) { reader = new FileReader(template); } if (reader == null) { InputStream is = ClassUtils.getResourceStream(templatePath); if (is == null) { throw new FileNotFoundException("No such template: " + templatePath); } reader = new InputStreamReader(is); } String name = export.getName(); if (name.indexOf("$") > -1) { name = handler.evaluate("eval: \"\"\"" + name + "\"\"\"").toString(); } log.info("export {} as {}", templatePath, name); Templates engine = new StringTemplates('$', '$'); if ("groovy".equals(export.engine)) { engine = new GroovyTemplates(); } File output = getExportPath(); output = FileUtils.getFile(output, dir, name); String contents = null; try { contents = handler.template(engine, reader); } finally { reader.close(); } Files.createParentDirs(output); Files.write(contents, output, Charsets.UTF_8); log.info("file saved: {}", output); return FileUtils.getFile(dir, name).toString(); }
From source file:org.sonar.plugins.l10n.L10nHackyPropertiesUpdater.java
private static void fixSpacesAroundEqualsAndScrewUpEncoding(File localizedBundle) throws IOException { String lines = Files.toString(localizedBundle, Charset.forName("ISO-8859-1")); lines = lines.replaceAll(" = ", "="); lines = StringEscapeUtils.unescapeJava(lines); // Yeah, this is *really* weird, as properties files are by definition encoded in ISO-8859-1 // but seems like SQ l10n plugins are done this way :-/ Files.write(lines, localizedBundle, Charset.forName("UTF-8")); }
From source file:com.google.devtools.j2objc.pipeline.InputFilePreprocessor.java
private void processRegularSource(ProcessingContext input) throws IOException { InputFile file = input.getFile();/*from w w w. j a va 2 s. c o m*/ String source = FileUtil.readFile(file); boolean doIncompatibleStripping = source.contains("J2ObjCIncompatible"); if (!(Options.shouldMapHeaders() || doIncompatibleStripping)) { // No need to parse. return; } CompilationUnit compilationUnit = parser.parseWithoutBindings(file.getUnitName(), source); if (compilationUnit == null) { // An error occured, reported by the JdtParser. return; } String qualifiedName = FileUtil.getQualifiedMainTypeName(file, compilationUnit); if (Options.shouldMapHeaders()) { Options.getHeaderMap().put(qualifiedName, input.getGenerationUnit().getOutputPath() + ".h"); } if (doIncompatibleStripping) { String newSource = J2ObjCIncompatibleStripper.strip(source, compilationUnit); File strippedDir = getCreatedStrippedSourcesDir(); String relativePath = qualifiedName.replace('.', File.separatorChar) + ".java"; File strippedFile = new File(strippedDir, relativePath); Files.createParentDirs(strippedFile); Files.write(newSource, strippedFile, Options.getCharset()); input.setFile(new RegularInputFile(strippedFile.getPath(), relativePath)); } }
From source file:com.longuh.BasicCrawler.java
@Override public void visit(Page page) { int docid = page.getWebURL().getDocid(); String url = page.getWebURL().getURL(); int parentDocid = page.getWebURL().getParentDocid(); logger.debug("Docid: {}", docid); logger.info("URL: {}", url); logger.debug("Docid of parent page: {}", parentDocid); if (page.getParseData() instanceof HtmlParseData) { HtmlParseData htmlParseData = (HtmlParseData) page.getParseData(); String html = htmlParseData.getHtml(); //jsoup preprocess raw html file Document doc = Jsoup.parse(html, "UTF-8"); Element titleElement = doc.select("div.title_news").first(); Element timeElement = doc.select("div.block_timer.left.txt_666").first(); Element contentElement = doc.select("div.fck_detail.width_common").first(); StringBuilder text = new StringBuilder(); text.append("Url=" + url + "\n"); text.append("Title=" + titleElement.text() + "\n"); text.append("Time=" + timeElement.text() + "\n"); text.append("Content=" + contentElement.text() + "\n"); //end add Set<WebURL> links = htmlParseData.getOutgoingUrls(); String fileName = "./" + myController.getConfig().getCrawlStorageFolder() + "/doc-" + docid + ".txt"; File file = new File(fileName); try {//www . ja va 2 s . c om Files.write(text.toString(), file, Charsets.UTF_8); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } logger.debug("Text length: {}", contentElement.text().length()); logger.debug("Html length: {}", html.length()); logger.debug("Number of outgoing links: {}", links.size()); } logger.debug("============="); }
From source file:org.codebite.jsass.mojo.JsassCompileMojo.java
File[] compile(File sourceFile, File outputDirectory) throws IOException, CompilationException { File cssFile = new File(outputDirectory, toCssName(sourceFile)); File mapFile = null;/* www . j a v a2 s. c o m*/ if (writeSourceMaps) { mapFile = new File(outputDirectory, toCssName(sourceFile) + ".map"); options.setSourceMapFile(mapFile.toURI()); } Output output = jsass.compileFile(sourceFile.toURI(), cssFile.toURI(), options); Files.write(output.getCss(), cssFile, Charset.defaultCharset()); if (writeSourceMaps) { Files.write(output.getSourceMap(), mapFile, Charset.defaultCharset()); } return mapFile != null ? new File[] { cssFile, mapFile } : new File[] { cssFile }; }
From source file:com.android.build.gradle.integration.common.fixture.app.LargeTestProject.java
private static void createGradleProperties(@NonNull File location) throws IOException { Files.write("org.gradle.jvmargs=-Xmx6096m -XX:MaxPermSize=1024m\n" + "org.gradle.daemon=true\n", new File(location, "gradle.properties"), Charset.defaultCharset()); }
From source file:com.android.build.gradle.internal.test.fixture.GradleProjectTestRule.java
@Override public Statement apply(final Statement base, Description description) { testDir = new File("build/tmp/tests/" + description.getTestClass().getName()); // Create separate directory based on test method name if @Rule is used. // getMethodName() is null if this rule is used as a @ClassRule. if (description.getMethodName() != null) { testDir = new File(testDir, description.getMethodName()); }//from w ww. j ava 2s . c o m buildFile = new File(testDir, "build.gradle"); sourceDir = new File(testDir, "src"); return new Statement() { @Override public void evaluate() throws Throwable { if (testDir.exists()) { deleteRecursive(testDir); } assertTrue(testDir.mkdirs()); assertTrue(sourceDir.mkdirs()); Files.write("ext {\n" + " buildToolsVersion = System.env.CUSTOM_BUILDTOOLS != null ? System.env.CUSTOM_BUILDTOOLS : '20.0.0'\n" + "}\n" + "\n" + "buildscript {\n" + " def gradleVersion = System.env.CUSTOM_GRADLE != null ? System.env.CUSTOM_GRADLE : '" + ANDROID_GRADLE_VERSION + "'\n" + "\n" + " repositories {\n" + " if (System.env.CUSTOM_REPO != null) {\n" + " maven { url System.env.CUSTOM_REPO }\n" + " } else {\n" + " mavenCentral()\n" + " }\n" + " }\n" + " dependencies {\n" + " classpath \"com.android.tools.build:gradle:$gradleVersion\"\n" + " }\n" + "}", buildFile, Charsets.UTF_8); createLocalProp(testDir, sdkDir, ndkDir); base.evaluate(); } }; }
From source file:org.renyan.leveldb.impl.Filename.java
/** * Make the CURRENT file point to the descriptor file with the * specified number./*from w w w . j a va 2 s . c om*/ * @return true if successful; false otherwise */ public static boolean setCurrentFile(File databaseDir, long descriptorNumber) throws IOException { String manifest = descriptorFileName(descriptorNumber); String temp = tempFileName(descriptorNumber); File tempFile = new File(databaseDir, temp); Files.write(manifest + "\n", tempFile, Charsets.UTF_8); File to = new File(databaseDir, currentFileName()); boolean ok = tempFile.renameTo(to); if (!ok) { tempFile.delete(); Files.write(manifest + "\n", to, Charsets.UTF_8); } return ok; }
From source file:org.apache.whirr.service.hadoop.HadoopConfigurationConverter.java
public static void createClientSideHadoopSiteFile(File file, Properties config) { try {//from www. j a v a 2s. co m Files.write(generateHadoopConfigurationFile(config), file, Charsets.UTF_8); LOG.info("Wrote file {}", file); } catch (IOException e) { LOG.error("Problem writing file {}", file, e); } }
From source file:net.sourceforge.vaticanfetcher.man.Manual.java
@RecursiveMethod private static void convert(@NotNull PegDownProcessor processor, @NotNull PageProperties props, @NotNull File srcDir, @NotNull File dstDir, boolean isTopLevel) throws IOException { for (File mdFile : Util.listFiles(srcDir)) { String name = mdFile.getName(); if (mdFile.isDirectory()) { File dstSubDir = new File(dstDir, name); dstSubDir.mkdirs();//from w ww . java2s . co m convert(processor, props, mdFile, dstSubDir, false); } else if (mdFile.isFile()) { if (mdFile.equals(props.propsFile)) continue; if (!name.endsWith(".markdown")) { Files.copy(mdFile, new File(dstDir, name)); 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 = isTopLevel ? convertMainPage(props, mdFile, htmlBody) : convertSubPage(props, mdFile, htmlBody); Files.write(html, htmlFile, Charsets.UTF_8); } } }