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.legstar.protobuf.cobol.ProtoCobolUtilsTest.java
public void testExtractPackageNameNoWhiteSpacesFromProtoFile() throws Exception { File protoFile = File.createTempFile(getName(), ".proto"); protoFile.deleteOnExit();/*from w ww . j av a 2 s.c om*/ FileUtils.writeStringToFile(protoFile, "option java_package=\"com.example.tutorial\";"); ProtoFileJavaProperties javaProperties = ProtoCobolUtils.getJavaProperties(protoFile); assertEquals("com.example.tutorial", javaProperties.getJavaPackageName()); }
From source file:com.thoughtworks.go.util.Log4jDirectConfigurer.java
public void afterPropertiesSet() throws Exception { LogManager.getLogger("httpclient.wire").setLevel(Level.INFO); if (!isLog4jExist()) { File log4j = new File(log4jLocation); FileUtils.writeStringToFile(log4j, DEFAULT_LOG4J); Log4jConfigurer.initLogging(log4j.getAbsolutePath(), refreshInterval); Logger.getLogger(Log4jDirectConfigurer.class) .info("created log4j file at [" + log4j.getAbsolutePath() + "]"); }//www . j ava2 s . co m }
From source file:com.cloud.agent.dao.impl.PropertiesStorageTest.java
@Test public void configureWithExistingFile() throws IOException { String fileName = "target/existingfile" + System.currentTimeMillis(); File file = new File(fileName); FileUtils.writeStringToFile(file, "a=b\n\n"); PropertiesStorage storage = new PropertiesStorage(); HashMap<String, Object> params = new HashMap<String, Object>(); params.put("path", fileName); Assert.assertTrue(storage.configure("test", params)); Assert.assertEquals("b", storage.get("a")); Assert.assertTrue(file.exists());//from w ww . ja v a 2 s . c o m storage.persist("foo", "bar"); Assert.assertEquals("bar", storage.get("foo")); storage.stop(); file.delete(); }
From source file:cz.prochy.cellar.Cellar.java
@RequestMapping(value = "/store", method = RequestMethod.POST) public ResponseEntity<String> store(@RequestBody String body, HttpServletRequest request) { String filename = "blob_" + System.currentTimeMillis() + "_" + random.nextInt(100000); try {/*from w w w.j a v a 2 s. c o m*/ FileUtils.writeStringToFile(new File(filename), body); logger.info("Written blob: " + filename); } catch (IOException e) { logger.error("Failed to write blob: " + filename); } return respond(); }
From source file:cc.kave.commons.utils.json.JsonUtilsTest.java
private void writeToTemp(String json) throws IOException { FileUtils.writeStringToFile(tmpFile, json); }
From source file:com.thoughtworks.studios.shine.net.StubGoURLRepository.java
public void registerArtifact(String path, String content) { File file = new File(artifactRoot, path); file.getParentFile().mkdirs();//from w ww .j a v a 2s.co m try { FileUtils.writeStringToFile(file, content); } catch (IOException e) { throw new RuntimeException("Could not write to file", e); } }
From source file:au.com.borner.salesforce.util.FileUtilities.java
public static File createMetadataFile(String path, String fileNameWithExtension, AbstractSourceCode sObject) throws Exception { File metadataFile = new File(path + File.separator + fileNameWithExtension + ".sfmd"); SourceFileMetaData sourceFileMetaData = new SourceFileMetaData(fileNameWithExtension, sObject.getId(), sObject.getApiVersion());/*from ww w . j a v a2s .c o m*/ FileUtils.writeStringToFile(metadataFile, sourceFileMetaData.toString()); return metadataFile; }
From source file:de.systemoutprintln.junit4examples.rules.TemporaryFolderRuleTest.java
@Test public void createTempFile() throws IOException { txtFile = folder.newFile("some.txt"); // it actually exists! :) assertTrue(txtFile.exists());/*from www. jav a 2 s . co m*/ // and we can write to it... assertTrue(txtFile.canWrite()); // let's try that FileUtils.writeStringToFile(txtFile, "I'm writing to a temp file!"); String contents = FileUtils.readFileToString(txtFile); assertEquals("I'm writing to a temp file!", contents); }
From source file:net.przemkovv.sphinx.Utils.java
public static List<File> prepareFilesystem(List<SourceFile> source_files, String dir_prefix) throws IOException { File temp_dir = createRandomTempDirectory(dir_prefix); List<File> files = new ArrayList<>(); for (SourceFile source_file : source_files) { File src_file = new File(temp_dir, source_file.filename); FileUtils.writeStringToFile(src_file, source_file.source); files.add(src_file);/*from ww w . j a va 2 s . c o m*/ } return files; }
From source file:com.thesmartweb.swebrank.YahooResults.java
/** * Method to get the links for a specific query * @param quer the query//from www .ja va2s . c om * @param yahoo_results_number the number of results to return * @param example_dir a directory to save the yahoo search engine response * @param config_path the directory with yahoo! api keys * @return an array with the urls of the results */ public String[] Get(String quer, int yahoo_results_number, String example_dir, String config_path) { String[] links = new String[yahoo_results_number]; try { quer = quer.replace("+", "%20"); YahooConn yc = new YahooConn(); String line = yc.connect(quer, config_path); if (!line.equalsIgnoreCase("fail")) { //write the json-ticket text to a file File json_t = new File(example_dir + "yahoo/" + quer + "/json" + ".txt"); FileUtils.writeStringToFile(json_t, line); //initialize JSONparsing JSONparsing gg = new JSONparsing(yahoo_results_number); //get the links in an array links = gg.YahooJsonParsing(line, yahoo_results_number); } return links; } catch (IOException ex) { Logger.getLogger(YahooResults.class.getName()).log(Level.SEVERE, null, ex); System.out.print("\n*********fail-yahoo results*********\n"); return links; } }