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.daveayan.rjson.utils.RjsonUtil.java
public static void recordJsonToFile(Object object, String absolutePath, Rjson rjson) { try {//from w ww .j a va2 s.c om FileUtils.writeStringToFile(new File(absolutePath), rjson.toJson(object)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.jwm123.loggly.reporter.TripleDesCipher.java
private void getKey() throws NoSuchAlgorithmException, IOException { File keyFile = appDir.getFileDir(keyPath); if (keyFile.exists()) { key = Base64.decode(FileUtils.readFileToString(keyFile)); } else {//from w ww. j a v a 2 s. c om KeyGenerator generator = KeyGenerator.getInstance("DESede"); SecretKey desKey = generator.generateKey(); key = desKey.getEncoded(); FileUtils.writeStringToFile(keyFile, new String(Base64.encode(key))); } }
From source file:net.itransformers.idiscover.v2.core.listeners.node.sdnDeviceXmlFileLogDiscoveryListener.java
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(labelDirName); if (!baseDir.exists()) baseDir.mkdir();// w w w.ja v a 2 s .com File deviceXmlXslt = new File(System.getProperty("base.dir"), deviceXmlXsltTransformator); File deviceXmlDataDir = new File(deviceXmlDataDirName); if (!deviceXmlDataDir.exists()) deviceXmlDataDir.mkdir(); String deviceName = discoveryResult.getNodeId(); String rawDataXml = new String((byte[]) discoveryResult.getDiscoveredData("rawData")); try { //Create DeviceXml File ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream(); ByteArrayInputStream inputStream; XsltTransformer transformer = new XsltTransformer(); inputStream = new ByteArrayInputStream(rawDataXml.getBytes()); transformer.transformXML(inputStream, deviceXmlXslt, outputStream1); logger.info("Transforming raw-data to DeviceXml for " + deviceName); logger.debug("Raw Data \n" + rawDataXml.toString()); File deviceXmlFile = new File(deviceXmlDataDir, "node" + "-" + "floodLight" + "-" + deviceName + ".xml"); FileUtils.writeStringToFile(deviceXmlFile, outputStream1.toString()); logger.info("Raw-data transformed to device-xml for " + deviceName); logger.debug("Node Data \n" + outputStream1.toString()); } catch (IOException e) { logger.error(e); } catch (ParserConfigurationException e) { logger.error(e); //To change body of catch statement use File | Settings | File Templates. } catch (SAXException e) { logger.error(e); //To change body of catch statement use File | Settings | File Templates. } catch (TransformerException e) { logger.error(e); //To change body of catch statement use File | Settings | File Templates. } }
From source file:edu.ku.brc.specify.config.SpecifyDataObjFieldFormatMgr.java
protected void saveXML(final String xml) { // save resource back to database if (doingLocal) { File outFile = XMLHelper.getConfigDir(localFileName); try {//from www. j ava2 s . c om FileUtils.writeStringToFile(outFile, xml); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifyDataObjFieldFormatMgr.class, ex); } } else if (AppContextMgr.getInstance() != null) { SpecifyUIFieldFormatterMgr.saveDisciplineResource(getAppContextMgr(), DATAOBJFORMATTERS, xml); } }
From source file:jenkins.plugins.shiningpanda.utils.TestFilePathUtil.java
public void testIsFileOrNullExists() throws Exception { File file = new File(createTmpDir(), "file.txt"); FileUtils.writeStringToFile(file, "hello"); FilePath filePath = FilePathUtil.isFileOrNull(new FilePath(file)); assertNotNull("file exists, this should not return null", filePath); }
From source file:cc.altruix.econsimtr01.App.java
private void createCsvFile(final File dir, File simResults) throws IOException { final String actualConvertedSimResults = new Simulation1TimeSeriesCreator().prologToCsv(simResults); final File simResultsCsvFile = new File(String.format("%s/simResults.csv", dir.getAbsolutePath())); FileUtils.writeStringToFile(simResultsCsvFile, actualConvertedSimResults); }
From source file:com.searchbox.framework.service.DirectoryService.java
public File createFile(String fname, String content) { File file = this.createFile(fname); try {//from ww w . jav a 2s . co m FileUtils.writeStringToFile(file, content); } catch (IOException e) { LOGGER.error("Could not write to temp file in directoryService", e); } return file; }
From source file:annis.visualizers.component.AbstractDotVisualizer.java
public void writeOutput(VisualizerInput input, OutputStream outstream) { StringBuilder dot = new StringBuilder(); try {//from www . ja va2s .com File tmpInput = File.createTempFile("annis-dot-input", ".dot"); tmpInput.deleteOnExit(); // write out input file StringBuilder dotContent = new StringBuilder(); createDotContent(input, dotContent); FileUtils.writeStringToFile(tmpInput, dotContent.toString()); // execute dot String dotPath = input.getMappings().getProperty("dotpath", "dot"); ProcessBuilder pBuilder = new ProcessBuilder(dotPath, "-Tpng", tmpInput.getCanonicalPath()); pBuilder.redirectErrorStream(false); Process process = pBuilder.start(); InputStream inputFromProcess = process.getInputStream(); for (int chr = inputFromProcess.read(); chr != -1; chr = inputFromProcess.read()) { outstream.write(chr); } inputFromProcess.close(); int resultCode = process.waitFor(); if (resultCode != 0) { InputStream stderr = process.getErrorStream(); StringBuilder errorMessage = new StringBuilder(); for (int chr = stderr.read(); chr != -1; chr = stderr.read()) { errorMessage.append((char) chr); } if (!"".equals(errorMessage.toString())) { log.error( "Could not execute dot graph-layouter.\ncommand line:\n{}\n\nstderr:\n{}\n\nstdin:\n{}", new Object[] { StringUtils.join(pBuilder.command(), " "), errorMessage.toString(), dot.toString() }); } } // cleanup if (!tmpInput.delete()) { log.warn("Cannot delete " + tmpInput.getAbsolutePath()); } } catch (Exception ex) { log.error(null, ex); } }
From source file:ddf.catalog.source.solr.TestConfigurationFileProxy.java
/** * Tests that if a change was made to a file or if the file already exists, the bundle would not * overwrite that file./* ww w . jav a2s . co m*/ * * @throws IOException */ @Test public void testKeepingExistingFiles() throws IOException { File tempLocation = new File("target/temp"); File file1 = new File(tempLocation, FILE_NAME_1); File file2 = new File(tempLocation, FILE_NAME_2); delete(file1, file2); BundleContext bundleContext = givenBundleContext(); ConfigurationFileProxy proxy = new ConfigurationFileProxy(bundleContext, ConfigurationStore.getInstance()); proxy.writeBundleFilesTo(tempLocation); verifyFilesExist(tempLocation); LOGGER.info("Contents Before Writing:" + FileUtils.readFileToString(file1)); String newContents = FILE_NAME_2; FileUtils.writeStringToFile(file1, newContents); LOGGER.info("Contents switched to:" + FileUtils.readFileToString(file1)); proxy.writeBundleFilesTo(tempLocation); String fileContents = FileUtils.readFileToString(file1); LOGGER.info("Final File contents:" + fileContents); assertThat(fileContents, is(newContents)); }
From source file:com.legstar.protobuf.cobol.ProtoCobolUtilsTest.java
public void testExtractDefaultClassNameFromProtoFile() throws Exception { File protoFile = File.createTempFile(getName(), ".proto"); protoFile.deleteOnExit();//from w ww.j av a 2s.com FileUtils.writeStringToFile(protoFile, ""); ProtoFileJavaProperties javaProperties = ProtoCobolUtils.getJavaProperties(protoFile); assertEquals(ProtoCobolUtils.getDefaultJavaClassName(protoFile), javaProperties.getJavaClassName()); }