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.adeshmukh.xml2fs.NodeUtil.java
/** * @param node//from ww w. jav a2 s .co m * @return * @throws TransformerException * @throws IOException */ public void saveFile(Node node) throws IOException, TransformerException { File nodeOutput = toFile(node); ensureDir(nodeOutput.getParentFile()); Files.write(toString(node), toFile(node), UTF_8); }
From source file:at.ac.univie.isc.asio.platform.FileSystemConfigStore.java
/** * Create a marker file in the working directory. Serves as a fail-fast mechanism to detect * filesystem access problems.//from w w w . j a v a 2 s . c o m * * @throws IOException if the marker file cannot be written */ private void touch() throws IOException { final List<String> content = Collections.singletonList(Long.toString(System.currentTimeMillis())); Files.write(this.root.resolve(".asio"), content, Charsets.UTF_8); }
From source file:com.android.build.gradle.tasks.NdkBuildExternalNativeJsonGenerator.java
@Override void processBuildOutput(@NonNull String buildOutput, @NonNull String abi, int abiPlatformVersion) throws IOException { // Discover Application.mk if one exists next to Android.mk // If there is an Application.mk file next to Android.mk then pick it up. File applicationMk = new File(getMakeFile().getParent(), "Application.mk"); // Write the captured ndk-build output to a file for diagnostic purposes. diagnostic("parse and convert ndk-build output to build configuration JSON"); NativeBuildConfigValue buildConfig = new NativeBuildConfigValueBuilder(getMakeFile()) .addCommands(getBuildCommand(abi, abiPlatformVersion, applicationMk), variantName, buildOutput, isWindows())/* w w w . j a va2 s .com*/ .build(); if (applicationMk.exists()) { diagnostic("found application make file %s", applicationMk.getAbsolutePath()); Preconditions.checkNotNull(buildConfig.buildFiles); buildConfig.buildFiles.add(applicationMk); } String actualResult = new GsonBuilder().registerTypeAdapter(File.class, new PlainFileGsonTypeAdaptor()) .setPrettyPrinting().create().toJson(buildConfig); // Write the captured ndk-build output to JSON file File expectedJson = ExternalNativeBuildTaskUtils.getOutputJson(getJsonFolder(), abi); Files.write(actualResult, expectedJson, Charsets.UTF_8); }
From source file:uk.ac.ebi.fg.annotare2.core.magetab.MageTabFiles.java
/** * Substitutes fake values (which were required to build MAGE-TAB graph) to a required values. * * @param file file to be sanitized/* w w w.j a v a 2s . c o m*/ */ private static void sanitize(File file, boolean everything) { try { String str = Files.toString(file, Charsets.UTF_8); str = restoreOriginalNameValues(str); if (everything) { str = restoreAllUnassignedValues(str); } Files.write(str, file, Charsets.UTF_8); } catch (IOException e) { log.error("Unable to sanitize MAGE-TAB file" + file.getAbsolutePath(), e); } }
From source file:net.minecraftforge.gradle.user.TaskSourceCopy.java
@SuppressWarnings("unchecked") @TaskAction//from ww w .j a va 2 s .c om public void doTask() throws IOException { // get the include/exclude patterns from the source (this is different than what's returned by getFilter) PatternSet patterns = new PatternSet(); patterns.setIncludes(source.getIncludes()); patterns.setExcludes(source.getExcludes()); // get output File out = getOutput(); if (out.exists()) deleteDir(out); out.mkdirs(); out = out.getCanonicalFile(); // resolve replacements HashMap<String, String> repl = new HashMap<String, String>(replacements.size()); for (Entry<String, Object> e : replacements.entrySet()) { if (e.getKey() == null || e.getValue() == null) continue; // we dont deal with nulls. Object val = e.getValue(); while (val instanceof Closure) val = ((Closure<Object>) val).call(); repl.put(Pattern.quote(e.getKey()), val.toString()); } getLogger().debug("REPLACE >> " + repl); // start traversing tree for (DirectoryTree dirTree : source.getSrcDirTrees()) { File dir = dirTree.getDir(); getLogger().debug("PARSING DIR >> " + dir); // handle nonexistant srcDirs if (!dir.exists() || !dir.isDirectory()) continue; else dir = dir.getCanonicalFile(); // this could be written as .matching(source), but it doesn't actually work // because later on gradle casts it directly to PatternSet and crashes FileTree tree = getProject().fileTree(dir).matching(source.getFilter()).matching(patterns); for (File file : tree) { File dest = getDest(file, dir, out); dest.getParentFile().mkdirs(); dest.createNewFile(); if (isIncluded(file)) { getLogger().debug("PARSING FILE IN >> " + file); String text = Files.toString(file, Charsets.UTF_8); for (Entry<String, String> entry : repl.entrySet()) text = text.replaceAll(entry.getKey(), entry.getValue()); getLogger().debug("PARSING FILE OUT >> " + dest); Files.write(text, dest, Charsets.UTF_8); } else { Files.copy(file, dest); } } } }
From source file:org.polimi.zarathustra.experiment.DOMsDumpExperiment.java
private static void storeDOMManifest(String url, File outputDir, long time) throws NoSuchAlgorithmException, IOException { String fileName = getFileName(url) + ".manifest"; File output = new File(outputDir, fileName); Files.write(url + ", " + time, output, Charsets.UTF_8); }
From source file:com.google.api.server.spi.tools.GenApiConfigAction.java
/** * Generates API configuration for an array of service classes. * @param classPath Class path to load service classes and their dependencies * @param outputDirPath Directory to write API configuration files into * @param serviceClassNames Array of service class names of the API * @param warPath Directory or file containing a WAR layout * @param outputToDisk Iff {@code true}, outputs a *.api file to disk for each API. * @return JSON-formatted configurations for each API. *///from w ww. ja va 2 s. com public Iterable<String> genApiConfig(URL[] classPath, String outputDirPath, String warPath, List<String> serviceClassNames, boolean outputToDisk) throws ClassNotFoundException, IOException, ApiConfigException { File outputDir = new File(outputDirPath); if (!outputDir.isDirectory()) { throw new IllegalArgumentException(outputDirPath + " is not a directory"); } ClassLoader classLoader = new URLClassLoader(classPath, getClass().getClassLoader()); ApiConfig.Factory configFactory = new ApiConfig.Factory(); ApiConfigValidator validator = new ApiConfigValidator(); JsonConfigWriter jsonConfigWriter = new JsonConfigWriter(classLoader, validator); ApiConfigGenerator generator = new AnnotationApiConfigGenerator(jsonConfigWriter, classLoader, configFactory); Map<String, String> apiConfigs = generator.generateConfig( ServiceContext.create(AppEngineUtil.getApplicationId(warPath), ServiceContext.DEFAULT_API_NAME), loadClasses(classLoader, serviceClassNames)); if (outputToDisk) { for (Map.Entry<String, String> entry : apiConfigs.entrySet()) { String apiConfigFileName = entry.getKey(); String apiConfigFileContent = entry.getValue(); String apiConfigFilePath = outputDir + "/" + apiConfigFileName; Files.write(apiConfigFileContent, new File(apiConfigFilePath), UTF_8); System.out.println("API configuration written to " + apiConfigFilePath); } } return apiConfigs.values(); }
From source file:io.dockstore.webservice.helpers.FileImporter.java
public Map<String, SourceFile> resolveImports(String content, Entry entry, SourceFile.FileType fileType, Version version) {/*from w w w. j a v a 2 s .c om*/ Map<String, SourceFile> imports = new HashMap<>(); if (fileType == SourceFile.FileType.DOCKSTORE_CWL) { YamlReader reader = new YamlReader(content); try { Map<String, ?> map = reader.read(Map.class); handleMap(entry, fileType, version, imports, map); } catch (YamlException e) { SourceCodeRepoInterface.LOG.error("Could not process content from " + entry.getId() + " as yaml"); } Map<String, SourceFile> recursiveImports = new HashMap<>(); for (SourceFile file : imports.values()) { final Map<String, SourceFile> sourceFiles = resolveImports(file.getContent(), entry, fileType, version); recursiveImports.putAll(sourceFiles); } recursiveImports.putAll(imports); return recursiveImports; } else if (fileType == SourceFile.FileType.DOCKSTORE_WDL) { final File tempDesc; try { tempDesc = File.createTempFile("temp", ".wdl", Files.createTempDir()); Files.write(content, tempDesc, StandardCharsets.UTF_8); final List<String> importPaths = sourceCodeRepo.getWdlImports(tempDesc); for (String importPath : importPaths) { SourceFile importFile = new SourceFile(); final String fileResponse = readGitRepositoryFile(fileType, version, importPath); if (fileResponse == null) { SourceCodeRepoInterface.LOG.error("Could not read: " + importPath); continue; } importFile.setContent(fileResponse); importFile.setPath(importPath); importFile.setType(SourceFile.FileType.DOCKSTORE_WDL); imports.put(importFile.getPath(), importFile); } } catch (IOException e) { throw new CustomWebApplicationException("Internal server error, out of space", HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE); } return imports; } else { throw new CustomWebApplicationException("Invalid file type for import", HttpStatus.SC_BAD_REQUEST); } }
From source file:cpw.mods.fml.common.registry.GameData.java
public static void dumpRegistry(File minecraftDir) { if (customItemStacks == null) { return;/*from w ww. j av a 2s . c o m*/ } if (Boolean.valueOf(System.getProperty("fml.dumpRegistry", "false")).booleanValue()) { ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); for (String modId : customItemStacks.rowKeySet()) { builder.putAll(modId, customItemStacks.row(modId).keySet()); } File f = new File(minecraftDir, "itemStackRegistry.csv"); MapJoiner mapJoiner = Joiner.on("\n").withKeyValueSeparator(","); try { Files.write(mapJoiner.join(builder.build().entries()), f, Charsets.UTF_8); FMLLog.log(Level.INFO, "Dumped item registry data to %s", f.getAbsolutePath()); } catch (IOException e) { FMLLog.log(Level.ERROR, e, "Failed to write registry data to %s", f.getAbsolutePath()); } } }
From source file:jp.co.ctc_g.jfw.test.unit.FileInitailize.java
/** * ??????????/*from w ww.j a v a 2s. co m*/ * @param src ?? * @param dest ?? * @return ? */ public File copy(String src, String dest) { L.debug(Strings.substitute(R.getString("D-TEST#0002"), Maps.hash("src", src).map("dest", dest))); InputStream is = null; File destFile = null; InternalException exception = null; try { is = target.getResourceAsStream(URLDecoder.decode(src, URL_ENCODE)); String contents = IOUtils.toString(is, encode); destFile = super.newFile(dest); Files.write(contents, destFile, Charset.forName(encode)); } catch (IOException e) { exception = new InternalException(FileInitailize.class, "E-TEST#0018"); } finally { try { if (is != null) is.close(); } catch (IOException e) { if (exception == null) { exception = new InternalException(FileInitailize.class, "E-TEST#0019"); } } if (exception != null) throw exception; } return destFile; }