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.thoughtworks.go.security.ResetCipher.java
public void setupAESCipherFile(String cipher) throws IOException { ReflectionUtil.setField(aesCipherProvider, "cachedKey", null); FileUtils.writeStringToFile(systemEnvironment.getAESCipherFile(), cipher, UTF_8); }
From source file:com.iyonger.apm.web.service.AnnouncementService.java
/** * Save content to announcement.conf file. * /*from w w w . ja v a 2s.c om*/ * @param content * file content. * @return save successfully or not. */ public boolean save(String content) { try { FileUtils.writeStringToFile(config.getHome().getSubFile("announcement.conf"), content, "UTF-8"); config.loadAnnouncement(); } catch (IOException e) { LOGGER.error("Error while writing announcement file."); return false; } return true; }
From source file:com.github.bomas.concat.ConcatMojo.java
public void execute() throws MojoExecutionException { if (validate()) { getLog().debug("Going to concatenate files to destination file: " + outputFile.getAbsolutePath()); try {// w w w .j a v a 2 s . co m for (File inputFile : concatFiles) { getLog().debug("Concatenating file: " + inputFile.getAbsolutePath()); String input = FileUtils.readFileToString(inputFile); FileUtils.writeStringToFile(outputFile, input, true); if (appendNewline) { FileUtils.writeStringToFile(outputFile, System.getProperty("line.separator"), true); } } } catch (IOException e) { throw new MojoExecutionException("Failed to concatenate", e); } } }
From source file:com.ms.commons.test.integration.apachexmlparse.internal.LocalResourceLoader.java
public Resource getResource(String location) { System.out.println("Get resource: " + location); try {/* w w w . j a v a 2s.co m*/ boolean isFromCache = true; String dtdFileName = IntlTestGlobalConstants.TESTCASE_DTD_DIR + File.separator + StringUtil.replaceNoWordChars(location) + ".dtd"; if (DTD_MAP.get(dtdFileName) == null) { File dtdFile = new File(dtdFileName); if (!dtdFile.exists()) { // load dtd from net isFromCache = false; String dtdContent = StringUtils.join( IOUtils.readLines((new URL(location)).openStream(), "UTF-8"), IntlTestGlobalConstants.LINE_SEPARATOR); FileUtils.writeStringToFile(dtdFile, dtdContent, "UTF-8"); DTD_MAP.put(dtdFileName, dtdContent); } else { DTD_MAP.put(dtdFileName, FileUtils.readFileToString(dtdFile, "UTF-8")); } } if (isFromCache) { System.out.println("Get resource from cache: " + location); } else { System.out.println("Get resource from net: " + location); } return new ByteArrayResource(DTD_MAP.get(dtdFileName).getBytes("UTF-8")); } catch (Exception e) { return parent.getResource(location); } }
From source file:de.bund.bfr.fskml.RScriptTest.java
public void testScript() throws IOException { // Creates temporary file. Fails the test if an error occurs. File f = File.createTempFile("temp", ""); f.deleteOnExit();/*from ww w. j a v a 2 s. c o m*/ String origScript = "# This is a comment line: It should not appear in the simplified version\n" + "library(triangle)\n" // Test library command without quotes + "library(\"dplyr\")\n" // Test library command with double quotes + "library('devtools')\n" // Test library command with simple quotes + "library(foreign) # (a)\n" // Test library command followed by a comment (with parentheses) + "source('other.R')\n" // Source command with simple quotes + "source(\"other2.R\")\n" // Source command with double quotes + "hist(result, breaks=50, main=\"PREVALENCE OF PARENT FLOCKS\")\n"; FileUtils.writeStringToFile(f, origScript, "UTF-8"); RScript rScript = new RScript(f); assertEquals(origScript, rScript.getScript()); assertEquals(Arrays.asList("triangle", "dplyr", "devtools", "foreign"), rScript.getLibraries()); assertEquals(Arrays.asList("other.R", "other2.R"), rScript.getSources()); }
From source file:it.drwolf.ridire.utility.test.NewsCleaner.java
public NewsCleaner() throws IOException { // this.removeDirtyHtml(); File dir2 = new File(DIR2); List<File> dir2files = new ArrayList(FileUtils.listFiles(dir2, null, false)); for (File f : dir2files) { String content = FileUtils.readFileToString(f); content = StringEscapeUtils.unescapeHtml(content); content = content.replaceAll("\\\\\n", " "); File nf = new File(f.getAbsolutePath().substring(0, f.getAbsolutePath().length() - 5)); FileUtils.writeStringToFile(nf, content, "UTF-8"); }//from ww w . ja va2 s . co m }
From source file:com.thoughtworks.go.security.AESCipherProvider.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 w w.ja v a2s . c o m*/ byte[] newKey = generateKey(); FileUtils.writeStringToFile(cipherFile, encodeHexString(newKey), UTF_8); LOGGER.info("AES cipher not found. Creating a new cipher file"); cachedKey = newKey; } catch (Exception e) { throw new RuntimeException(e); } } } } }
From source file:jsentvar.GenerateTestsResults.java
public void getUrisResult() throws IOException { System.out.println("getUris"); String term_value0 = "intelligent_systems"; String term_value = term_value0.substring(0, 1).toUpperCase() + term_value0.substring(1); Surrogate sur = new Surrogate(term_value, this.model); String mode = "wide"; String term_id = term_value.replace(" ", "_"); String queryString = sur.preQuery(mode, term_id); DataMapper instance = new DataMapper(); instance.setModel(this.model); ArrayList<String> result0 = instance.getUris(queryString, mode); System.out.println("Generating getUrisResult:"); System.out.println(result0.toString()); //Utils.writeFile("resources/test/getUrisResult.txt", result0.toString()); FileUtils.writeStringToFile(new File("resources/test/getUrisResult.txt"), result0.toString(), "utf8"); }
From source file:com.smartling.api.sdk.file.commandline.RetrieveFile.java
protected static File retrieve(String[] args) throws ApiException, IOException { RetrieveFileParams retrieveFileParams = getParameters(args); File file = new File(retrieveFileParams.getPathToFile()); FileApiClientAdapter smartlingFAPI = new FileApiClientAdapterImpl(retrieveFileParams.isProductionMode(), retrieveFileParams.getApiKey(), retrieveFileParams.getProjectId()); StringResponse response = smartlingFAPI.getFile(file.getName(), retrieveFileParams.getLocale(), null); File translatedFile = new File(getTranslatedFilePath(file, retrieveFileParams.getLocale(), retrieveFileParams.getPathToStoreFile())); FileUtils.writeStringToFile(translatedFile, response.getContents(), response.getEncoding()); return translatedFile; }
From source file:com.thoughtworks.go.server.service.support.toggle.FeatureToggleRepositoryTest.java
@After public void tearDown() throws Exception { FileUtils.writeStringToFile(availableTogglesFile(), "", UTF_8); }