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.android.build.gradle.integration.common.fixture.app.LargeTestProject.java
@Override public void write(@NonNull File projectDir, @Nullable String buildScriptContent) throws IOException { GradleModule gradleModule = createProject(factory, 0, ":", projectDir, "0"); createSettingsGradle(gradleModule, projectDir); createGradleProperties(projectDir);/*from w w w .ja v a 2 s .c o m*/ Files.write(buildScriptContent, new File(projectDir, "build.gradle"), Charset.defaultCharset()); }
From source file:org.eclipse.xtext.xtext.ui.ecore2xtext.Ecore2XtextGenerator.java
@Override protected void invokeInternal(final WorkflowContext ctx, ProgressMonitor monitor, final Issues issues) { createXtextProjectInfo(issues);/*from w w w .j a v a 2s . c o m*/ CharSequence grammar = xtextProjectInfo.getRuntimeProject().grammar(); try { Files.write(grammar, new File(genPath, xtextProjectInfo.getRuntimeProject().getGrammarFilePath()), Charsets.ISO_8859_1); } catch (IOException e) { String message = "Can't create grammar file"; log.error(message, e); issues.addError(Ecore2XtextGenerator.this, message, this, e, null); } }
From source file:org.gradle.internal.nativeplatform.filesystem.GenericFileSystem.java
private File createFile(String content) throws IOException { File file = File.createTempFile("gradle_fs_probing", null, null); Files.write(content, file, Charsets.UTF_8); return file;/*from w ww .j av a2 s . co m*/ }
From source file:com.android.build.gradle.integration.common.fixture.app.AbstractAndroidTestApp.java
@Override public void write(@NonNull File projectDir, @Nullable String buildScriptContent) throws IOException { // Create build.gradle. if (buildScriptContent != null) { Files.write(buildScriptContent, new File(projectDir, "build.gradle"), Charset.defaultCharset()); }/*from w w w .j a va 2 s . c o m*/ for (TestSourceFile srcFile : getAllSourceFiles()) { srcFile.writeToDir(projectDir); } }
From source file:org.opendaylight.controller.config.yang.test.plugin.ProcessSources.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (directory == null || !directory.exists()) { super.getLog().error("Directory does not exists."); }//from ww w .j a va 2s .c om File sourceDirectory = new File( directory.getPath() + Util.replaceDots(".org.opendaylight.controller.config.yang.test.impl")); if (!sourceDirectory.exists()) { super.getLog().error(String.format("Source directory does not exists %s", sourceDirectory.getPath())); } File[] sourceFiles = sourceDirectory.listFiles(); for (File sourceFile : sourceFiles) { if (sourceFile.getName().endsWith(".java")) { String sourceContent; try { sourceContent = Files.toString(sourceFile, StandardCharsets.UTF_8); } catch (IOException e) { getLog().error(String.format("Cannot read %s", sourceFile.getAbsolutePath()), e); continue; } if (sourceFile.getName().endsWith("Module.java") || sourceFile.getName().endsWith("ModuleFactory.java")) { File stubFile = new File(sourceFile.getPath().replace(".java", "Stub.txt")); if (stubFile.exists()) { String stubContent = null; try { stubContent = Files.toString(stubFile, StandardCharsets.UTF_8); } catch (IOException e) { getLog().error(String.format("Cannot read %s", stubFile.getAbsolutePath()), e); } if (stubContent != null) { sourceContent = rewriteStub(sourceContent, stubContent); } } } // remove copyright headers as they can contain timestamp sourceContent = removeCopyrights(sourceContent); // replace the file content try { Files.write(sourceContent, sourceFile, StandardCharsets.UTF_8); } catch (IOException e) { getLog().error(String.format("Cannot write %s", sourceFile.getAbsolutePath()), e); } } } }
From source file:com.autoupdater.client.xml.creators.ConfigurationXMLCreator.java
/** * Creates XML document with installation data and stores it info file. * //from w w w . ja v a 2 s. c om * @param destination * destination file * @param clientSettings * client's settings * @param programsSettings * programs's settings * @throws IOException * thrown when error occurs during storing data to file */ public void createXML(File destination, ClientSettings clientSettings, Set<ProgramSettings> programsSettings) throws IOException { logger.debug("Save confuguration data at: " + destination.getCanonicalPath()); Document settings = DocumentHelper.createDocument(); settings.addComment(XMLCreationConfiguration.DO_NOT_EDIT_FILE_MANUALLY_WARNING); Element configuration = settings.addElement(ConfigurationSchema.configuration); Element client = configuration.addElement(ConfigurationSchema.Configuration.client); client.addAttribute(ConfigurationSchema.Configuration.Client.name, clientSettings.getClientName()); client.addAttribute(ConfigurationSchema.Configuration.Client.executable, clientSettings.getClientExecutableName()); addLocationsSettings(client, clientSettings); addProxySettings(client, clientSettings); addProgramsSettings(configuration, programsSettings); Files.createParentDirs(destination); Files.write(settings.asXML(), destination, XMLCreationConfiguration.XML_ENCODING); logger.trace("Saved configuration cache data at: " + destination.getCanonicalPath()); }
From source file:spv.sherpa.custom.CustomModelsManager.java
public void addModel(CustomModel model, String type) throws IOException { File file = new File(model.getUrl().getFile()); File destination = null;/*from www . j av a2 s .c o m*/ if (type.equals("Template Library")) destination = templatesDir; if (type.equals("Python Function")) destination = functionsDir; if (type.equals("Table")) destination = tablesDir; String name; if (model.getName() == null) model.setName(""); name = model.getName().isEmpty() ? model.getUrl().getFile().substring(model.getUrl().getFile().lastIndexOf(File.separator) + 1) : model.getName(); File target = new File(destination.getAbsolutePath() + File.separator + name); if (file.equals(target)) { File temp = new File(file.getAbsolutePath() + ".temp"); Files.copy(file, temp); Files.copy(temp, target); temp.delete(); } else { Files.copy(file, target); } File specs = new File(target.getAbsolutePath() + ".specs"); String functionName = destination.equals(functionsDir) ? model.getFunctionName() : "None"; Files.write(functionName + "\n", specs, Charsets.UTF_8); Files.append(model.getParnames() + "\n", specs, Charsets.UTF_8); Files.append(model.getParvals() + "\n", specs, Charsets.UTF_8); Files.append(model.getParmins() + "\n", specs, Charsets.UTF_8); Files.append(model.getParmaxs() + "\n", specs, Charsets.UTF_8); Files.append(model.getParfrozen() + "\n", specs, Charsets.UTF_8); }
From source file:com.tibco.businessworks6.sonar.plugin.file.XmlFile.java
/** * Create a temporary file without any character before the prolog and * update the following attributes in order to correctly report issues: * <ul>/* ww w . jav a 2 s . co m*/ * <li>lineDeltaForIssue * <li>file */ private void processCharBeforePrologInFile(Charset charset, int lineDelta) { try { String content = Files.toString(file, charset); File tempFile = File.createTempFile(file.getName(), ".tmp"); int index = content.indexOf(XML_PROLOG_START_TAG); Files.write(content.substring(index), tempFile, charset); file = tempFile; if (lineDelta > 1) { lineDeltaForIssue = lineDelta - 1; } } catch (IOException e) { LOG.warn("Unable to analyse file {}", file.getAbsolutePath(), e); } }
From source file:org.opennms.newts.cassandra.AbstractCassandraTestCase.java
public CQLDataSet getDataSet() { try {//from w w w.ja v a 2 s .co m String schema = Resources.toString(getClass().getResource(getSchemaResource()), Charsets.UTF_8); schema = schema.replace(KEYSPACE_PLACEHOLDER, CASSANDRA_KEYSPACE); File schemaFile = File.createTempFile("schema-", ".cql", new File("target")); Files.write(schema, schemaFile, Charsets.UTF_8); return new FileCQLDataSet(schemaFile.getAbsolutePath(), false, true, CASSANDRA_KEYSPACE); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:com.android.build.gradle.tasks.CompatibleScreensManifest.java
@TaskAction public void generate() throws IOException { StringBuilder content = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " package=\"\">\n" + "\n" + " <compatible-screens>\n"); String density = getScreenDensity(); // convert unsupported values to numbers. density = convert(density, Density.XXHIGH, Density.XXXHIGH); for (String size : getScreenSizes()) { content.append(" <screen android:screenSize=\"").append(size) .append("\" " + "android:screenDensity=\"").append(density).append("\" />\n"); }//from w ww. ja v a2 s .c o m content.append(" </compatible-screens>\n" + "</manifest>"); Files.write(content.toString(), getManifestFile(), Charsets.UTF_8); }