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:org.caleydo.data.importer.tcga.qualitycontrol.TCGAQCDataSetTypeTask.java
private void generateJSONReport(JsonArray detailedReports, EDataSetType dataSetType, String dataSetTypeSpecificOutputPath) throws IOException { JsonObject report = new JsonObject(); report.addProperty("analysisRun", dataSetType.getName()); report.add("details", detailedReports); report.addProperty("caleydoVersion", GeneralManager.VERSION.toString()); String r = settings.getGson().toJson(report); Files.write(r, new File(dataSetTypeSpecificOutputPath, dataSetType + ".json"), Charset.forName("UTF-8")); }
From source file:org.spongepowered.asm.mixin.transformer.MixinTransformerModuleInterfaceChecker.java
public MixinTransformerModuleInterfaceChecker() { File debugOutputFolder = new File(MixinTransformer.DEBUG_OUTPUT, "audit"); debugOutputFolder.mkdirs();//from ww w. java 2s. c om this.csv = new File(debugOutputFolder, "mixin_implementation_report.csv"); this.report = new File(debugOutputFolder, "mixin_implementation_report.txt"); try { Files.write("Class,Method,Signature,Interface\n", this.csv, Charsets.ISO_8859_1); } catch (IOException ex) { // well this sucks } try { String dateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); Files.write("Mixin Implementation Report generated on " + dateTime + "\n", this.report, Charsets.ISO_8859_1); } catch (IOException ex) { // hmm :( } }
From source file:org.jetbrains.jet.compiler.NamespaceComparator.java
public static void compareNamespaces(@NotNull NamespaceDescriptor nsa, @NotNull NamespaceDescriptor nsb, boolean includeObject, @NotNull File txtFile) { String serialized = new NamespaceComparator(includeObject).doCompareNamespaces(nsa, nsb); try {//w w w . ja va 2s . c o m for (;;) { String expected = Files.toString(txtFile, Charset.forName("utf-8")).replace("\r\n", "\n"); if (expected.contains("kick me")) { // for developer System.err.println("generating " + txtFile); Files.write(serialized, txtFile, Charset.forName("utf-8")); continue; } // compare with hardcopy: make sure nothing is lost in output Assert.assertEquals(expected, serialized); break; } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.eclipse.recommenders.internal.privacy.rcp.services.AnonymousIdService.java
private UUID generateFreshAnonymousId() { UUID freshAnonymousId;/*from www. ja v a 2 s . c o m*/ do { freshAnonymousId = UUID.randomUUID(); } while (freshAnonymousId.equals(anonymousId)); try { Files.write(freshAnonymousId.toString(), anonymousIdFile, Charsets.UTF_8); } catch (IOException e) { LOG.error(MessageFormat.format(Messages.LOG_ERROR_ANONYMOUS_ID_FILE_WRITE, anonymousIdFile), e); } return freshAnonymousId; }
From source file:brooklyn.entity.rebind.persister.FileBasedStoreObjectAccessor.java
@Override public void put(String val) { try {//from www . ja va2 s. c o m if (val == null) val = ""; FileUtil.setFilePermissionsTo600(tmpFile); Files.write(val, tmpFile, Charsets.UTF_8); FileBasedObjectStore.moveFile(tmpFile, file); } catch (IOException e) { throw Exceptions.propagate(e); } catch (InterruptedException e) { throw Exceptions.propagate(e); } }
From source file:net.minecraftforge.gradle.patcher.TaskSubprojectCall.java
@TaskAction public void doTask() throws IOException { // resolve replacements for (Entry<String, Object> entry : replacements.entrySet()) { replacements.put(entry.getKey(), Constants.resolveString(entry.getValue()).replace('\\', '/')); }// ww w .j ava 2 s. c o m // extract extra initscripts List<File> initscripts = Lists.newArrayListWithCapacity(initResources.size()); for (int i = 0; i < initResources.size(); i++) { File file = new File(getTemporaryDir(), "initscript" + i); String thing = Resources.toString(initResources.get(i), Constants.CHARSET); for (Entry<String, Object> entry : replacements.entrySet()) { thing = thing.replace(entry.getKey(), (String) entry.getValue()); } Files.write(thing, file, Constants.CHARSET); initscripts.add(file); } // get current Gradle instance Gradle gradle = getProject().getGradle(); getProject().getLogger().lifecycle("------------------------ "); getProject().getLogger().lifecycle("--------SUB-CALL-------- "); getProject().getLogger().lifecycle("------------------------ "); // connect to project ProjectConnection connection = GradleConnector.newConnector() .useGradleUserHomeDir(gradle.getGradleUserHomeDir()).useInstallation(gradle.getGradleHomeDir()) .forProjectDirectory(getProjectDir()).connect(); //get args ArrayList<String> args = new ArrayList<String>(5); args.addAll(Splitter.on(' ').splitToList(getCallLine())); for (File f : initscripts) { args.add("-I" + f.getCanonicalPath()); } // build connection.newBuild().setStandardOutput(System.out).setStandardInput(System.in).setStandardError(System.err) .withArguments(args.toArray(new String[args.size()])).setColorOutput(false).run(); getProject().getLogger().lifecycle("------------------------ "); getProject().getLogger().lifecycle("------END-SUB-CALL------ "); getProject().getLogger().lifecycle("------------------------ "); }
From source file:org.gradle.language.swift.tasks.CreateSwiftBundle.java
@TaskAction void createBundle() throws IOException { getProject().copy(new Action<CopySpec>() { @Override/*from w w w . j a va 2s. c o m*/ public void execute(CopySpec copySpec) { copySpec.from(getExecutableFile(), new Action<CopySpec>() { @Override public void execute(CopySpec copySpec) { copySpec.into("Contents/MacOS"); } }); copySpec.into(getOutputDir()); } }); File outputFile = getOutputDir().file("Contents/Info.plist").get().getAsFile(); if (!informationFile.isPresent() || !informationFile.get().getAsFile().exists()) { Files.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + "<plist version=\"1.0\">\n" + "<dict/>\n" + "</plist>", outputFile, Charset.forName("UTF-8")); } else { Files.copy(informationFile.get().getAsFile(), outputFile); } getProject().exec(new Action<ExecSpec>() { @Override public void execute(ExecSpec execSpec) { execSpec.setWorkingDir(outputDir.get()); execSpec.executable(swiftStdlibToolLocator.find()); execSpec.args("--copy", "--scan-executable", executableFile.getAsFile().get().getAbsolutePath(), "--destination", outputDir.dir("Contents/Frameworks").get().getAsFile().getAbsolutePath(), "--platform", "macosx", "--resource-destination", outputDir.dir("Contents/Resources").get().getAsFile().getAbsolutePath(), "--scan-folder", outputDir.dir("Contents/Frameworks").get().getAsFile().getAbsolutePath()); } }).assertNormalExitValue(); }
From source file:de.cinovo.cloudconductor.agent.executors.FileExecutor.java
@Override public IExecutor<Set<String>> execute() throws ExecutionError { this.errors = new StringBuilder(); for (ConfigFile file : this.files) { File localFile = new File(file.getTargetPath()); HashCode localFileHash = this.getChecksum(localFile); String serverFile;/* www . j a v a2 s.com*/ try { serverFile = ServerCom.getFileData(file); } catch (TransformationErrorException | CloudConductorException e) { continue; } HashCode serverFileHash = this.getChecksum(serverFile); boolean changeOccured = false; if (!serverFileHash.equals(localFileHash)) { try { Files.createParentDirs(localFile); Files.write(serverFile, localFile, Charset.forName("UTF-8")); changeOccured = true; } catch (IOException e) { // add error to exception list this.errors.append("Failed to write file: " + localFile.getAbsolutePath()); this.errors.append(System.lineSeparator()); // just skip this file continue; } } // set file owner and group try { if (!FileHelper.isFileOwner(localFile, file.getOwner(), file.getGroup())) { FileHelper.chown(localFile, file.getOwner(), file.getGroup()); changeOccured = true; } } catch (IOException e) { this.errors.append("Failed to set user and/or group for file: " + localFile.getAbsolutePath()); this.errors.append(System.lineSeparator()); } // set file mode try { String fileMode = FileHelper.fileModeIntToString(ServerCom.getFileMode(file.getName())); if (!FileHelper.isFileMode(localFile, fileMode)) { FileHelper.chmod(localFile, fileMode); changeOccured = true; } } catch (IOException e) { this.errors.append("Failed to set chmod for file: " + localFile.getAbsolutePath()); this.errors.append(System.lineSeparator()); } catch (CloudConductorException e) { this.errors.append(e.getMessage()); this.errors.append(System.lineSeparator()); } // set services to restart if (file.isReloadable() && changeOccured) { this.restart.addAll(file.getDependentServices()); } } if (!this.errors.toString().trim().isEmpty()) { throw new ExecutionError(this.errors.toString().trim()); } return this; }
From source file:org.yes.cart.installer.ApacheTomcat7Configurer.java
private void configureSSL() throws IOException { if (sslKeyStoreFile == null) { return;/*from ww w . j av a 2 s . c o m*/ } File serverXMLFile = new File(tomcatHome, "conf" + File.separator + "server.xml"); Files.write(Files.toString(serverXMLFile, Charset.forName("UTF-8")) .replace(" <Connector port=\"8009\" protocol=\"AJP/1.3\" redirectPort=\"8443\" />", " <Connector port=\"8009\" protocol=\"AJP/1.3\" redirectPort=\"8443\" />\n" + " <Connector port=\"" + httpsPort + "\" protocol=\"HTTP/1.1\" SSLEnabled=\"true\"\n" + " maxThreads=\"150\" scheme=\"https\" secure=\"true\"\n" + " clientAuth=\"false\" sslProtocol=\"TLS\"\n" + " keystoreFile=\"" + sslKeyStoreFile + "\" " + "keystorePass=\"" + Strings.nullToEmpty(sslKeyStorePassword) + "\" />") .replace("8443", Integer.toString(httpsPort)), serverXMLFile, Charset.forName("UTF-8")); }
From source file:org.opennms.newts.persistence.cassandra.AbstractCassandraTestCase.java
@Override public CQLDataSet getDataSet() { try {/*from w ww . j a v a 2s. com*/ String schema = Resources.toString(getClass().getResource(SCHEMA_RESOURCE), Charsets.UTF_8); schema = schema.replace(KEYSPACE_PLACEHOLDER, KEYSPACE_NAME); File schemaFile = File.createTempFile("schema-", ".cql", new File("target")); Files.write(schema, schemaFile, Charsets.UTF_8); return new FileCQLDataSet(schemaFile.getAbsolutePath(), false, true, KEYSPACE_NAME); } catch (IOException e) { throw Throwables.propagate(e); } }