List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data) throws IOException
From source file:com.vmware.photon.controller.deployer.dcp.DeployerContextTest.java
private void createConfigFile(File scriptFile, String content) throws IOException { scriptFile.createNewFile();// w w w . jav a2 s . c om FileUtils.writeStringToFile(scriptFile, content); }
From source file:io.fabric8.elasticsearch.plugin.auth.FileAuthenticationBackendTest.java
@Before public void setup() throws IOException { tmp = File.createTempFile("passwd", Integer.toString(new Random().nextInt()), new File(System.getProperty("java.io.tmpdir"))); FileUtils.writeStringToFile(tmp, Samples.PASSWORDS.getContent()); givenFilePath(tmp.getAbsolutePath()); givenAuthenticationBackend();/*w ww .j a v a 2 s . co m*/ }
From source file:com.gargoylesoftware.htmlunit.html.XmlSerializer.java
public void save(final HtmlPage page, final File file) throws IOException { String fileName = file.getName(); if (!fileName.endsWith(".htm") && !fileName.endsWith(".html")) { fileName += ".html"; }/* ww w.j a v a2 s . c o m*/ final File outputFile = new File(file.getParentFile(), fileName); if (outputFile.exists()) { throw new IOException("File already exists: " + outputFile); } fileName = fileName.substring(0, fileName.lastIndexOf('.')); outputDir_ = new File(file.getParentFile(), fileName); FileUtils.writeStringToFile(outputFile, asXml(page.getDocumentElement())); }
From source file:com.thoughtworks.go.server.web.ArtifactFolderTest.java
@Test public void shouldRenderFileRelativeToFolderIfItExists() throws IOException { File file = new File(folder, "foo.xml"); file.getParentFile().mkdirs();//w w w .j av a 2 s.c om FileUtils.writeStringToFile(file, "FOO"); assertThat(artifactFolder.renderArtifactFiles("http://uri"), containsString(">\nfoo.xml\n</a>")); assertThat(artifactFolder.renderArtifactFiles("http://uri"), containsString("<a href=\"http://uri/files/pipeline-name/label-111/" + "stage-name/1/job-name/pathRelativeToBaseURL/foo.xml\">")); }
From source file:com.sillelien.dollar.DollarOperatorsRegressionTest.java
public void regression(String symbol, String operation, String variant, @NotNull List<List<var>> result) throws IOException { String filename = operation + "." + variant + ".json"; final JsonArray previous = new JsonArray(IOUtils.toString(getClass().getResourceAsStream("/" + filename))); //Use small to stop massive string creation final File file = new File("target", filename); final var current = $(result); FileUtils.writeStringToFile(file, current.jsonArray().encodePrettily()); System.out.println(file.getAbsolutePath()); SortedSet<String> typeComparison = new TreeSet<>(); SortedSet<String> humanReadable = new TreeSet<>(); for (List<var> res : result) { if (res.size() != 3) { throw new IllegalStateException(res.toString()); }/*from w ww. ja v a2 s . co m*/ typeComparison.add( res.get(0).$type() + " " + operation + " " + res.get(1).$type() + " = " + res.get(2).$type()); humanReadable.add(res.get(0).toDollarScript() + " " + symbol + " " + res.get(1).toDollarScript() + " <=> " + res.get(2).toDollarScript()); } final String typesFile = operation + "." + variant + ".types.txt"; final String humanFile = operation + "." + variant + ".ds"; FileUtils.writeLines(new File("target", typesFile), typeComparison); FileUtils.writeLines(new File("target", humanFile), humanReadable); final TreeSet previousTypeComparison = new TreeSet<String>( IOUtils.readLines(getClass().getResourceAsStream("/" + typesFile))); diff("type", previousTypeComparison.toString(), typeComparison.toString()); diff("result", previous, current.jsonArray()); }
From source file:com.thoughtworks.go.plugin.infra.commons.PluginsListTest.java
@Before public void setUp() throws Exception { initMocks(this); temporaryFolder.create();//from w w w . j ava 2 s . co m bundledPluginsDir = temporaryFolder.newFolder("bundled"); externalPluginsDir = temporaryFolder.newFolder("external"); File bundledYumPlugin = new File(bundledPluginsDir, "yum.jar"); File externalPlugin1 = new File(externalPluginsDir, "external1.jar"); File externalPlugin2 = new File(externalPluginsDir, "external2.jar"); File externalPlugin3 = new File(externalPluginsDir, "external3.jar"); FileUtils.writeStringToFile(bundledYumPlugin, bundledYumPlugin.getName()); FileUtils.writeStringToFile(externalPlugin1, externalPlugin1.getName()); FileUtils.writeStringToFile(externalPlugin2, externalPlugin2.getName()); FileUtils.writeStringToFile(externalPlugin3, externalPlugin3.getName()); when(systemEnvironment.getBundledPluginAbsolutePath()).thenReturn(bundledPluginsDir.getAbsolutePath()); when(systemEnvironment.getExternalPluginAbsolutePath()).thenReturn(externalPluginsDir.getAbsolutePath()); pluginsList = new PluginsList(systemEnvironment); }
From source file:com.francetelecom.clara.cloud.mvn.consumer.maven.PomGenerator.java
public File generatePom(File projectDirectory, MavenReference mavenReference) throws IOException { if (projectDirectory == null) { throw new IllegalArgumentException("projectDirectory cannot be null"); }//ww w.j av a 2 s . c o m if (mavenReference == null) { throw new IllegalArgumentException("mavenReference cannot be null"); } if (!projectDirectory.exists()) { FileUtils.forceMkdir(projectDirectory); } Model project = new Model(); project.setModelVersion("4.0.0"); project.setGroupId(mavenReference.getGroupId()); project.setArtifactId(mavenReference.getArtifactId()); project.setVersion(mavenReference.getVersion()); project.setPackaging(mavenReference.getExtension()); project.setName(mavenReference.getArtifactId() + " (" + mavenReference.getExtension() + ")"); String pom = modelToStringXml(project); logger.debug("generated pom : \n" + pom); File pomFile = new File(projectDirectory.getAbsolutePath() + "/pom.xml"); FileUtils.writeStringToFile(pomFile, pom); return pomFile; }
From source file:com.github.psorobka.appium.StartServerMojo.java
@Override public void execute() throws MojoExecutionException { try {/*from ww w . ja v a2s. c o m*/ getLog().info("Starting Appium server..."); ProcessBuilder processBuilder = new ProcessBuilder(); processBuilder.command("appium", "--log-timestamp", "--log", new File(target, "appiumLog.txt").getAbsolutePath()); processBuilder.redirectError(new File(target, "appiumErrorLog.txt")); processBuilder.redirectOutput(new File(target, "appiumOutputLog.txt")); getLog().debug("Appium server commands " + processBuilder.command()); Process process = processBuilder.start(); if (!Processes.newPidProcess(process).isAlive()) { throw new MojoExecutionException("Failed to start Appium server"); } int pid = PidUtil.getPid(process); getLog().info("Appium server started"); getLog().debug("Appium server PID " + pid); FileUtils.writeStringToFile(new File(target, "appium.pid"), Integer.toString(pid)); //Dumb way to sleep until appium starts - file watcher would be better Thread.sleep(5000); } catch (IOException | InterruptedException ex) { throw new MojoExecutionException("Failed to start Appium server", ex); } }
From source file:ch.sbb.releasetrain.config.YamlSerializerTest.java
@Test public void testSerializeMailReceiverConfig() throws Exception { List<MailReceiver> list = new ArrayList<>(); list.add(createMailReceiver(1, "test")); list.add(createMailReceiver(2, "test")); list.add(createMailReceiver(3, "hallo")); list.add(createMailReceiver(4, "hallo")); File file = new File(testFolder.getRoot(), "mail.yml"); FileUtils.writeStringToFile(file, emailSerializer.convertEntrys(list)); List<MailReceiver> list2 = emailSerializer.convertEntrys(FileUtils.readFileToString(file)); Assert.assertNotNull(list2);/* ww w. ja v a 2 s .c o m*/ Assert.assertEquals(list.size(), list2.size()); Assert.assertEquals(list.get(3), list2.get(3)); }
From source file:net.doubledoordev.backend.util.Settings.java
public static void save() { try {//from www.j ava 2 s .co m FileUtils.writeStringToFile(CONFIG_FILE, GSON.toJson(SETTINGS)); FileUtils.writeStringToFile(SERVERS_FILE, GSON.toJson(SETTINGS.servers.values())); FileUtils.writeStringToFile(USERS_FILE, GSON.toJson(SETTINGS.users.values())); LOGGER.info("Saved settings."); } catch (Exception e) { LOGGER.error("Error saving the config file...", e); } }