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:me.lucko.luckperms.api.sponge.simple.persisted.SubjectStorage.java
public void saveToFile(SimplePersistedSubject subject, File file) throws IOException { file.getParentFile().mkdirs();//from www. j a va 2s. c o m if (file.exists()) { file.delete(); } file.createNewFile(); Files.write(saveToString(new SimpleSubjectDataHolder(subject.getSubjectData())), file, Charset.defaultCharset()); }
From source file:com.technophobia.substeps.glossary.HTMLSubstepsPublisher.java
public void publish(final List<StepImplementationsDescriptor> stepimplementationDescriptors) { final Map<String, List<StepDescriptor>> sectionSorted = new TreeMap<String, List<StepDescriptor>>(); for (final StepImplementationsDescriptor descriptor : stepimplementationDescriptors) { for (final StepDescriptor stepTag : descriptor.getExpressions()) { String section = stepTag.getSection(); if (section == null || section.isEmpty()) { section = "Miscellaneous"; }// w ww. j a v a 2 s. com List<StepDescriptor> subList = sectionSorted.get(section); if (subList == null) { subList = new ArrayList<StepDescriptor>(); sectionSorted.put(section, subList); } subList.add(stepTag); } } final String html = buildHtml(sectionSorted); outputFile.delete(); // write out try { if (outputFile.createNewFile()) { Files.write(html, outputFile, Charset.defaultCharset()); } else { // TODO } } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.streamsets.datacollector.main.StandaloneRuntimeInfo.java
private String getSdcId(String dir) { File dataDir = new File(dir); if (!dataDir.exists()) { if (!dataDir.mkdirs()) { throw new RuntimeException(Utils.format("Could not create data directory '{}'", dataDir)); }/* w w w . j ava 2 s . c o m*/ } File idFile = new File(dataDir, "sdc.id"); if (!idFile.exists()) { try { Files.write(Generators.timeBasedGenerator().generate().toString(), idFile, StandardCharsets.UTF_8); } catch (IOException ex) { throw new RuntimeException( Utils.format("Could not create SDC ID file '{}': {}", idFile, ex.toString()), ex); } } try { return Files.readFirstLine(idFile, StandardCharsets.UTF_8).trim(); } catch (IOException ex) { throw new RuntimeException(Utils.format("Could not read SDC ID file '{}': {}", idFile, ex.toString()), ex); } }
From source file:org.eclipse.jdt.ls.core.internal.ResourceUtils.java
/** * Writes content to file, outside the workspace. No change event is * emitted.//w w w . java2 s . com */ public static void setContent(URI fileURI, String content) throws CoreException { if (content == null) { content = ""; } try { Files.write(content, new File(fileURI), Charsets.UTF_8); } catch (IOException e) { throw new CoreException(StatusFactory.newErrorStatus("Can not write to " + fileURI, e)); } }
From source file:de.dennishoersch.web.jsf.resources.javascript.JavascriptBuilder.java
/** * * @return the resource metadata// www . j a va 2 s .c om * @throws IOException */ public GeneratedResourceMetadata build() throws IOException { String scripts = readAndConcatFileContents(); scripts = ClosureCompiler.compile(scripts); String scriptFilename = getGeneratedFilename(); String resourceFileName = asAbsoluteResourceFileName(scriptFilename); Files.write(scripts, new File(resourceFileName), Charset.defaultCharset()); return newGeneratedResourceMetadata(scriptFilename); }
From source file:de.hh.changeRing.migration.ParseDumpFile.java
private ParseDumpFile(File from, File toFolder) { try {/*w w w . j a v a 2 s . c o m*/ this.content = Files.toString(from, UTF_8); replace("`", ""); replace("SET @saved_cs_client = @@character_set_client;", ""); replace("SET character_set_client = utf8;", ""); replace("SET character_set_client = @saved_cs_client;", ""); //content = content.replaceAll("ENGINE=MyISAM AUTO_INCREMENT=[0-9]+ DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci", ""); replace("ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci PACK_KEYS=0;", ""); //replace("text collate latin1_german2_ci", "varchar(2048)"); //replace("collate latin1_german2_ci ", ""); //replace(" auto_increment", ""); replace("\\'", "''"); replace("),(", ")\n,("); content = content.replaceAll("LOCK TABLES [a-z]+ WRITE;", ""); replace("UNLOCK TABLES;", ""); toFolder.delete(); toFolder.mkdirs(); for (String contentPart : Splitter.on("DROP TABLE IF EXISTS ").split(content)) { String tableName = contentPart.substring(0, contentPart.indexOf(';')); if (!tableName.contains(" ")) { File file = new File(toFolder, tableName + ".sql"); file.delete(); Files.write("DROP TABLE IF EXISTS " + contentPart, file, UTF_8); log(tableName, file, contentPart); } } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:co.mitro.keyczar.RoundTripper.java
private static void encrypt(String keyPath, String message, String outpath) throws KeyczarException, IOException { Encrypter key = new Encrypter(Util.readJsonFromPath(keyPath)); System.out.println("encrypting message length " + message.length()); String output = key.encrypt(message); Files.write(output, new File(outpath), Charsets.UTF_8); }
From source file:com.andune.minecraft.commonlib.reflections.YamlSerializer.java
@Override public File save(Reflections reflections, String filename) { try {// w w w . ja va 2 s. c o m File file = Utils.prepareFile(filename); Files.write(toString(reflections), file, Charset.defaultCharset()); return file; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.bund.bfr.knime.pmmlite.io.xmlwriter.XmlWriterNodeModel.java
/** * {@inheritDoc}/*from w w w. j a va 2s. c o m*/ */ @Override protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) throws Exception { Set<String> names = new LinkedHashSet<>(); for (Identifiable obj : ((PmmPortObject) inObjects[0]).getData(Identifiable.class)) { String name = KnimeUtils.createNewValue(PmmUtils.createId(obj.getName()), names); names.add(name); Files.write(EmfUtils.identifiableToXml(obj), KnimeUtils.getFile(outPath.getStringValue() + "/" + name + ".xml"), StandardCharsets.UTF_8); } return new PortObject[] {}; }
From source file:cn.dreampie.ClosureMinifier.java
private void compile(Result result, File destFile, Compiler compiler) { log.debug(result.debugLog);//w ww . ja v a2s . c om for (JSError error : result.errors) { log.error("Closure Minifier Error: " + error.sourceName + " Description: " + error.description); } for (JSError warning : result.warnings) { log.info("Closure Minifier Warning: " + warning.sourceName + " Description: " + warning.description); } if (result.success) { try { Files.write(compiler.toSource(), destFile, Charsets.UTF_8); } catch (IOException e) { throw new ClosureException("Failed to write minified file to " + destFile, e); } } else { throw new ClosureException("Closure Compiler Failed - See error messages on System.err"); } }