List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data) throws IOException
From source file:edu.sampleu.common.FreemarkerUtil.java
/** * * @param file//from ww w. ja v a 2s . co m * @param template * @param props * @return * @throws IOException * @throws freemarker.template.TemplateException */ protected static File writeTemplateToFile(File file, Template template, Properties props) throws IOException, TemplateException { String output = FreeMarkerTemplateUtils.processTemplateIntoString(template, props); FileUtils.writeStringToFile(file, output); return file; }
From source file:com.sketchy.SketchyContext.java
public static void save(File jsonFile) throws Exception { synchronized (SketchyContext.class) { Map<String, Object> saveMap = new HashMap<String, Object>(); saveMap.put("hardwareControllerProperties", hardwareControllerProperties); saveMap.put("plotterControllerProperties", plotterControllerProperties); saveMap.put("pathingProcessorProperties", pathingProcessorProperties); saveMap.put("drawingProperties", drawingProperties); FileUtils.writeStringToFile(jsonFile, JSONUtils.toJson(saveMap)); }/* www .ja va 2 s. c o m*/ }
From source file:eu.udig.style.advanced.common.StyleManager.java
/** * Dump the given style to disk./* w w w.jav a 2 s . c o m*/ * * @param styleWrapper the style to write to disk. * @throws Exception */ protected void styleToDisk(StyleWrapper styleWrapper) throws Exception { String name = styleWrapper.getName(); String styleStr = styleWrapper.toXml(); File newFile = new File(styleFolderFile, name + SLD_EXTENTION); FileUtils.writeStringToFile(newFile, styleStr); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.file.FileTest.java
/** * @throws Exception if the test fails/*from ww w . j a v a 2 s. c om*/ */ @Test @Alerts(CHROME = { "1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 16:21:47 GMT+0200 (Central European Summer Time)", "1437920507000", "", "14", "text/plain" }, FF31 = { "1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 16:21:47 GMT+0200", "undefined", "undefined", "14", "text/plain" }, FF38 = { "1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 16:21:47 GMT+0200", "1437920507000", "undefined", "14", "text/plain" }, IE = { "1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 16:21:47 GMT+0200 (Central European Summer Time)", "undefined", "undefined", "14", "text/plain" }) public void properties() 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" + " var file = files[0];\n" + " alert(file.name);\n" + " alert(file.lastModifiedDate);\n" + " alert(file.lastModified);\n" + " alert(file.webkitRelativePath);\n" + " alert(file.size);\n" + " alert(file.type);\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"); // do not use millis here because different file systems // have different precisions tstFile.setLastModified(1437920507000L); final String path = tstFile.getCanonicalPath(); driver.findElement(By.name("fileupload")).sendKeys(path); driver.findElement(By.id("testBtn")).click(); final String[] expected = getExpectedAlerts(); if (expected.length > 1) { expected[1] = tstFile.getName(); } verifyAlerts(driver, getExpectedAlerts()); } finally { FileUtils.deleteQuietly(tstFile); } }
From source file:com.cedarsoft.serialization.serializers.stax.mate.registry.RegistrySerializerDirTest.java
License:asdf
@Before public void setup() { baseDir = TestUtils.createEmptyTmpDir(); access = new DirBasedObjectsAccess(baseDir); serializer = new RegistrySerializer<String, Registry<String>, OutputStream, InputStream>( new DirBasedRegistrySerializingStrategy<String>(access) { @Nonnull//from w w w . j ava 2 s . c o m @Override protected String deserialize(@Nonnull String id, @Nonnull File dir) throws IOException { return FileUtils.readFileToString(new File(dir, "data")); } @Override protected void serialize(@Nonnull String object, @Nonnull String id, @Nonnull File dir) throws IOException { File data = new File(dir, "data"); FileUtils.writeStringToFile(data, object); } }, new RegistrySerializer.IdResolver<String>() { @Override @Nonnull public String getId(@Nonnull String object) { return object; } }); }
From source file:jenkins.plugins.shiningpanda.scm.BuildoutSCM.java
public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath remoteDir, BuildListener listener, File changeLogFile) throws IOException, InterruptedException { FilePath filePath = build.getWorkspace().child(buildoutCfg); FileUtils.writeStringToFile(new File(filePath.getRemote()), buildoutContent); FilePath djangoDir = build.getWorkspace().child(djangoProject); djangoDir.mkdirs();//from ww w . j a v a2s . c o m FileUtils.writeStringToFile(new File(djangoDir.child("__init__.py").getRemote()), ""); FileUtils.writeStringToFile(new File(djangoDir.child("settings.py").getRemote()), ""); return createEmptyChangeLog(changeLogFile, listener, "log"); }
From source file:com.intuit.tank.standalone.agent.StandaloneAgentStartup.java
public void startTest(final StandaloneAgentRequest request) { Thread t = new Thread(new Runnable() { public void run() { try { currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.DELEGATING); sendAvailability();// w w w. java 2 s . c o m LOG.info("Starting up: ControllerBaseUrl=" + controllerBase); URL url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SETTINGS); LOG.info("Starting up: making call to tank service url to get settings.xml " + url.toExternalForm()); InputStream settingsStream = url.openStream(); try { String settings = IOUtils.toString(settingsStream); FileUtils.writeStringToFile(new File("settings.xml"), settings); LOG.info("got settings file..."); } finally { IOUtils.closeQuietly(settingsStream); } url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SUPPORT); LOG.info("Making call to tank service url to get support files " + url.toExternalForm()); ZipInputStream zip = new ZipInputStream(url.openStream()); try { ZipEntry entry = zip.getNextEntry(); while (entry != null) { String name = entry.getName(); LOG.info("Got file from controller: " + name); File f = new File(name); FileOutputStream fout = FileUtils.openOutputStream(f); try { IOUtils.copy(zip, fout); } finally { IOUtils.closeQuietly(fout); } entry = zip.getNextEntry(); } } finally { IOUtils.closeQuietly(zip); } // now start the harness String cmd = API_HARNESS_COMMAND + " -http=" + controllerBase + " -jobId=" + request.getJobId() + " -stopBehavior=" + request.getStopBehavior(); LOG.info("Starting apiharness with command: " + cmd); currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.RUNNING_JOB); sendAvailability(); Process exec = Runtime.getRuntime().exec(cmd); exec.waitFor(); currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.AVAILABLE); sendAvailability(); // } catch (Exception e) { LOG.error("Error in AgentStartup " + e, e); currentAvailability.setAvailabilityStatus(AgentAvailabilityStatus.AVAILABLE); sendAvailability(); } } }); t.start(); }
From source file:de.tudarmstadt.ukp.dkpro.tc.ml.liblinear.LiblinearDataWriter.java
@Override public void write(File outputDirectory, FeatureStore featureStore, boolean useDenseInstances, String learningMode, boolean applyWeighting) throws Exception { FeatureNodeArrayEncoder encoder = new FeatureNodeArrayEncoder(); FeatureNode[][] nodes = encoder.featueStore2FeatureNode(featureStore); // liblinear only supports integer outcomes, thus we need to create a mapping Map<String, Integer> outcomeMapping = getOutcomeMapping(featureStore.getUniqueOutcomes()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < nodes.length; i++) { Instance instance = featureStore.getInstance(i); List<String> elements = new ArrayList<String>(); for (int j = 0; j < nodes[i].length; j++) { FeatureNode node = nodes[i][j]; int index = node.getIndex(); double value = node.getValue(); // write sparse values, i.e. skip zero values if (Math.abs(value) > 0.00000000001) { elements.add(index + ":" + value); }/* w w w. java 2 s . c o m*/ } sb.append(outcomeMapping.get(instance.getOutcome())); sb.append("\t"); sb.append(StringUtils.join(elements, "\t")); sb.append("\n"); } File outputFile = new File(outputDirectory, LiblinearAdapter.getInstance().getFrameworkFilename(AdapterNameEntries.featureVectorsFile)); FileUtils.writeStringToFile(outputFile, sb.toString()); File mappingFile = new File(outputDirectory, LiblinearAdapter.getOutcomeMappingFilename()); FileUtils.writeStringToFile(mappingFile, LiblinearUtils.outcomeMap2String(outcomeMapping)); }
From source file:com.predic8.membrane.examples.DistributionExtractingTestcase.java
private void replaceLog4JConfig() throws IOException { File log4jproperties = new File(membraneHome, "conf" + File.separator + "log4j.properties"); if (!log4jproperties.exists()) throw new RuntimeException("log4j.properties does not exits."); FileUtils.writeStringToFile(log4jproperties, "log4j.appender.stdout=org.apache.log4j.ConsoleAppender\r\n" + "log4j.appender.stdout.Target=System.out\r\n" + "log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\r\n" + "log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n\r\n" + "\r\n" + "log4j.rootLogger=warn\r\n" + "\r\n" + "log4j.logger.com.predic8=debug, stdout"); }
From source file:gov.nist.healthcare.ttt.webapp.common.controller.GetCCDADocumentsController.java
@RequestMapping(method = RequestMethod.GET, produces = "application/json") public @ResponseBody HashMap<String, Object> getDocuments() throws Exception { // Result map HashMap<String, Object> resultMap = new HashMap<>(); // CCDA cache File path String ccdaFilePath = ccdaFileDirectory + File.separator + "ccda_objectives.txt"; File ccdaObjectivesFile = new File(ccdaFilePath); if (ccdaObjectivesFile.exists() && !ccdaObjectivesFile.isDirectory()) { JsonFactory factory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(factory); TypeReference<HashMap<String, Object>> typeRef = new TypeReference<HashMap<String, Object>>() { };/*from www . j a va 2 s. c o m*/ resultMap = mapper.readValue(ccdaObjectivesFile, typeRef); } else { String sha = getHTML( "https://api.github.com/repos/siteadmin/2015-Certification-C-CDA-Test-Data/branches/master") .getJSONObject("commit").get("sha").toString(); JSONArray filesArray = getHTML( "https://api.github.com/repos/siteadmin/2015-Certification-C-CDA-Test-Data/git/trees/" + sha + "?recursive=1").getJSONArray("tree"); for (int i = 0; i < filesArray.length(); i++) { JSONObject file = filesArray.getJSONObject(i); if (!files2ignore.contains(file.get("path"))) { // Get path array String[] path = file.get("path").toString().split("/"); buildJson(resultMap, path); } } // Write the cache file try { JSONObject cacheFile = new JSONObject(resultMap); FileUtils.writeStringToFile(ccdaObjectivesFile, cacheFile.toString(2)); } catch (Exception e) { logger.error("Could not create ccda cache file: " + e.getMessage()); e.printStackTrace(); } } return resultMap; }