List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data, String encoding) throws IOException
From source file:com.o2d.pkayjava.editor.proxy.SceneDataManager.java
public SceneVO createNewScene(String name) { SceneVO vo = new SceneVO(); vo.sceneName = name;/*from www . j a va 2 s. co m*/ ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME); try { String projPath = projectManager.getCurrentWorkingPath() + "/" + projectManager.currentProjectVO.projectName; FileUtils.writeStringToFile(new File(projPath + "/project.dt"), projectManager.currentProjectInfoVO.constructJsonString(), "utf-8"); FileUtils.writeStringToFile(new File(projPath + "/scenes/" + vo.sceneName + ".dt"), vo.constructJsonString(), "utf-8"); projectManager.currentProjectInfoVO.scenes.add(vo); } catch (IOException e) { e.printStackTrace(); } return vo; }
From source file:com.thoughtworks.go.config.materials.perforce.P4MaterialUpdaterTestBase.java
@Test void shouldCleanWorkingDir() throws Exception { P4Material material = p4Fixture.material(VIEW); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); File tmpFile = new File(workingDir, "shouldBeDeleted"); FileUtils.writeStringToFile(tmpFile, "testing", UTF_8); assert (tmpFile.exists()); updateTo(material, new RevisionContext(REVISION_2), JobResult.Passed); assert (!tmpFile.exists()); }
From source file:de.wintercloud.CompileJinjaMojo.java
public void execute() throws MojoExecutionException { try {/*w w w .jav a 2 s . c o m*/ // Load the parameters Yaml yaml = new Yaml(); Map<String, Object> context = (Map<String, Object>) yaml .load(FileUtils.readFileToString(varFile, (Charset) null)); // Load template Jinjava jinjava = new Jinjava(); String template = FileUtils.readFileToString(templateFile, (Charset) null); // Render and save String rendered = jinjava.render(template, context); FileUtils.writeStringToFile(outputFile, rendered, (Charset) null); } catch (IOException e) { // Print error and exit with -1 throw new MojoExecutionException(e.getLocalizedMessage(), e); } }
From source file:com.glluch.profilesparser.Writer.java
/** * For each profile, writes an xml file for add to Solr. TODO Make the read dir a var. * @param path The directory where the files will be written. * @throws IOException if can't read o write *///w w w . j a va 2 s.com public void profiles2SolrXML(String path) throws IOException { ProfileHtmlReader phr = new ProfileHtmlReader(); ArrayList<ICTProfile> ps = phr.readerDir("resources/ict_profiles"); for (ICTProfile pp : ps) { HashMap<String, Double> ieee = Profile2IEEE.fillTerms(pp); String xml = "<add><doc>" + System.lineSeparator(); xml += "<field name=\"id\""; xml += ">" + System.lineSeparator(); xml += pp.getTitle(); xml += "</field>" + System.lineSeparator(); xml += "<field name=\"type\">ICT_profile</field>" + System.lineSeparator(); xml += terms2xml("term", ieee); xml += competences2xml(pp.getEcfs()); xml += "</doc></add>"; //competencesXMLsolr String fileTitle = pp.getTitle() + ".xml"; FileUtils.writeStringToFile(new File(path + fileTitle), xml, "utf8"); } }
From source file:de.pixida.logtest.automatondefinitions.JsonAutomatonDefinitionTest.java
@Test(expected = AutomatonLoadingException.class) public void testExceptionIsThrownWhenSyntaxIsInvalid() throws IOException { final File rewrittenConfig = this.testFolder.newFile(); FileUtils.writeStringToFile(rewrittenConfig, "{", JsonAutomatonDefinition.EXPECTED_CHARSET); this.loadAutomatonDefinitionFromFile(rewrittenConfig); }
From source file:com.joyent.manta.client.AuthAwareConfigContextTest.java
public void canMonitorRelevantFieldsInConfig() throws IOException { final AuthAwareConfigContext authConfig = new AuthAwareConfigContext(config); final KeyPair currentKeyPair = authConfig.getKeyPair(); Assert.assertNotNull(currentKeyPair); // key file (move key content to a file) final File keyFile = File.createTempFile("private-key", ""); FileUtils.forceDeleteOnExit(keyFile); FileUtils.writeStringToFile(keyFile, authConfig.getPrivateKeyContent(), StandardCharsets.UTF_8); authConfig.setPrivateKeyContent(null); authConfig.setMantaKeyPath(keyFile.getAbsolutePath()); authConfig.reload();/*from w w w. ja va2s . c om*/ differentKeyPairsSameContent(currentKeyPair, authConfig.getKeyPair()); // key id authConfig.setMantaKeyId("MD5:" + KeyFingerprinter.md5Fingerprint(authConfig.getKeyPair())); authConfig.reload(); differentKeyPairsSameContent(currentKeyPair, authConfig.getKeyPair()); // disable native signatures final ThreadLocalSigner currentSigner = authConfig.getSigner(); authConfig.setDisableNativeSignatures(true); authConfig.reload(); Assert.assertNotSame(currentSigner, authConfig.getSigner()); // disable auth entirely authConfig.setNoAuth(true); authConfig.reload(); Assert.assertNull(authConfig.getKeyPair()); }
From source file:com.thoughtworks.go.domain.ArtifactMd5ChecksumsTest.java
@Test public void shouldLoadThePropertiesFromTheGivenFile() throws IOException { FileUtils.writeStringToFile(file, "first/path:md5=", UTF_8); ArtifactMd5Checksums artifactMd5Checksums = new ArtifactMd5Checksums(file); assertThat(artifactMd5Checksums.md5For("first/path"), is("md5=")); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.file.FileListTest.java
/** * @throws Exception if the test fails// w w w . j a v a 2s. co m */ @Test @Alerts({ "1", "true" }) public void in() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html>\n" + "<head><title>foo</title>\n" + "<script>\n" + "function test() {\n" + " if (document.testForm.fileupload.files) {\n" + " var files = document.testForm.fileupload.files;\n" + " alert(files.length);\n" + " alert(0 in files);\n" + " }\n" + "}\n" + "</script>\n" + "</head>\n" + "<body>\n" + " <form name='testForm'>\n" + " <input type='file' id='fileupload' name='fileupload'>\n" + " </form>\n" + " <button id='testBtn' onclick='test()'>Tester</button>\n" + "</body>\n" + "</html>"; final WebDriver driver = loadPage2(html); final File tstFile = File.createTempFile("HtmlUnitUploadTest", ".txt"); try { FileUtils.writeStringToFile(tstFile, "Hello HtmlUnit", TextUtil.DEFAULT_CHARSET); final String path = tstFile.getCanonicalPath(); driver.findElement(By.name("fileupload")).sendKeys(path); driver.findElement(By.id("testBtn")).click(); verifyAlerts(driver, getExpectedAlerts()); } finally { FileUtils.deleteQuietly(tstFile); } }
From source file:com.thoughtworks.go.security.DESCipherProvider.java
private void primeKeyCache() { if (cachedKey == null) { synchronized (cipherFile.getAbsolutePath().intern()) { if (cachedKey == null) { try { if (cipherFile.exists()) { cachedKey = decodeHex(FileUtils.readFileToString(cipherFile, UTF_8).trim()); return; }//w ww . j a v a 2 s. c o m byte[] newKey = generateKey(); FileUtils.writeStringToFile(cipherFile, encodeHexString(newKey), UTF_8); LOGGER.info("DES cipher not found. Creating a new cipher file"); cachedKey = newKey; } catch (Exception e) { throw new RuntimeException(e); } } } } }
From source file:fr.ericlab.mabed.structure.EventList.java
public void writeEventsToFile(Corpus dataset, String filename) { try {//ww w .ja v a 2 s . c om File textFile = new File("output/" + filename + ".txt"); FileUtils.writeStringToFile(textFile, "", false); for (Event event : list) { FileUtils.writeStringToFile(textFile, " - [" + new SimpleDateFormat("yyyy-MM-dd hh:mm").format(dataset.toDate(event.I.timeSliceA)) + "//" + new SimpleDateFormat("yyyy-MM-dd hh:mm").format(dataset.toDate(event.I.timeSliceB)) + "] " + event.toString(false) + "\n---------------------------------\n", true); } } catch (IOException ex) { Logger.getLogger(MABED.class.getName()).log(Level.SEVERE, null, ex); } }