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.thoughtworks.go.util.Log4jDirectConfigurerTest.java
private void createLog4J() throws IOException { FileUtils.writeStringToFile(log4jExist, DEFAULT_LOG4J); }
From source file:com.galenframework.ide.services.filebrowser.FileBrowserServiceImpl.java
@Override public void saveFile(String path, FileContent fileContent) throws IOException { File file = new File(path); if (file.exists()) { if (file.isFile()) { FileUtils.writeStringToFile(file, fileContent.getContent()); } else/* www .j a va 2 s .c o m*/ throw new RuntimeException("Not a file: " + path); } else throw new RuntimeException("File doesn't exist: " + path); }
From source file:com.legstar.protobuf.cobol.ProtoCobolUtilsTest.java
public void testExtractPackageNameExtraWhiteSpacesFromProtoFile() throws Exception { File protoFile = File.createTempFile(getName(), ".proto"); protoFile.deleteOnExit();/*w w w .ja v a 2s .c o m*/ FileUtils.writeStringToFile(protoFile, "option java_package = \"com.example.tutorial\" ;"); ProtoFileJavaProperties javaProperties = ProtoCobolUtils.getJavaProperties(protoFile); assertEquals("com.example.tutorial", javaProperties.getJavaPackageName()); }
From source file:eu.apenet.dpt.standalone.gui.validation.DownloadReportActionListener.java
public void actionPerformed(ActionEvent e) { String defaultSaveLocation = dataPreparationToolGUI.getDefaultSaveLocation(); File file = new File(defaultSaveLocation + "report.txt"); try {/* w w w. j a va 2 s. c o m*/ FileInstance fileInstance = dataPreparationToolGUI.getFileInstances() .get(((File) dataPreparationToolGUI.getXmlEadList().getSelectedValue()).getName()); FileUtils.writeStringToFile(file, getStringFromMap(fileInstance.getXmlQualityErrors())); JOptionPane.showMessageDialog(dataPreparationToolGUI.getContentPane(), MessageFormat.format(dataPreparationToolGUI.getLabels().getString("dataquality.reportSaved"), defaultSaveLocation), dataPreparationToolGUI.getLabels().getString("fileSaved"), JOptionPane.INFORMATION_MESSAGE, Utilities.icon); } catch (IOException e1) { LOG.error("Could not save the report.txt file", e1); JOptionPane.showMessageDialog(dataPreparationToolGUI.getContentPane(), dataPreparationToolGUI.getLabels().getString("dataquality.reportSavedError"), dataPreparationToolGUI.getLabels().getString("fileSaved"), JOptionPane.ERROR_MESSAGE, Utilities.icon); } }
From source file:cc.kave.episodes.export.ThresholdsFrequency.java
public void writer(int numbRepos) throws IOException { Map<Integer, Set<Episode>> episodes = parser.parse(numbRepos); StringBuilder freqsBuilder = new StringBuilder(); for (Map.Entry<Integer, Set<Episode>> entry : episodes.entrySet()) { if (entry.getKey() == 1) { continue; }/*from ww w.j av a2 s .c o m*/ Logger.log("Writting %d - node episodes", entry.getKey()); Map<Integer, Integer> frequences = statistics.freqsEpisodes(entry.getValue()); String freqsLevel = getFreqsStringRep(entry.getKey(), frequences); freqsBuilder.append(freqsLevel); } FileUtils.writeStringToFile(new File(getFreqPath(numbRepos)), freqsBuilder.toString()); }
From source file:cc.kave.episodes.export.ThresholdsBidirection.java
public void writer(int numbRepos, int frequency) throws IOException { Map<Integer, Set<Episode>> episodes = parser.parse(numbRepos); StringBuilder bdsBuilder = new StringBuilder(); for (Map.Entry<Integer, Set<Episode>> entry : episodes.entrySet()) { if (entry.getKey() == 1) { continue; }/*from w ww .j a v a2s . c om*/ Logger.log("Writting %d - node episodes", entry.getKey()); Map<Double, Integer> bds = statistics.bidirectEpisodes(entry.getValue(), frequency); String bdsLevel = getBdsStringRep(entry.getKey(), bds); bdsBuilder.append(bdsLevel); } FileUtils.writeStringToFile(new File(getPath(numbRepos, frequency)), bdsBuilder.toString()); }
From source file:ch.oakmountain.tpa.web.TpaWebPersistor.java
public static void createMatrix(String name, String outputDir, IMatrix matrix, String htmlData) throws Exception { LOGGER.info("Creating matrix " + name + "...."); String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream("/matrix.html")); content = content.replaceAll(Pattern.quote("$JSONNAME$"), Matcher.quoteReplacement(name)) .replaceAll(Pattern.quote("$HTML$"), Matcher.quoteReplacement(htmlData)); FileUtils.writeStringToFile(Paths.get(outputDir + File.separator + name + ".html").toFile(), content); File file = new File(outputDir + File.separator + name + ".json"); writeMatrix(file, matrix);// ww w . j a v a 2s . com TpaPersistorUtils.copyFromResourceToDir("d3.v2.min.js", outputDir); TpaPersistorUtils.copyFromResourceToDir("miserables.css", outputDir); LOGGER.info("... created matrix " + name + "."); }
From source file:com.intuit.tank.agent.AgentStartup.java
public void run() { logger.info("Starting up..."); if (AmazonUtil.usingEip()) { try {/*from w w w.j a v a 2s . com*/ logger.info("Using EIP. Sleeping for " + WAIT_FOR_RESTART_TIME + " ms."); Thread.sleep(WAIT_FOR_RESTART_TIME); } catch (InterruptedException e1) { logger.info("Exception waiting."); System.exit(0); } } try { if (controllerBase == null) { controllerBase = AmazonUtil.getControllerBaseUrl(); } logger.info("Starting up: ControllerBaseUrl=" + controllerBase); URL url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SETTINGS); logger.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); logger.info("got settings file..."); } finally { IOUtils.closeQuietly(settingsStream); } url = new URL(controllerBase + SERVICE_RELATIVE_PATH + METHOD_SUPPORT); logger.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(); logger.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 jvmArgs = AmazonUtil.getUserDataAsMap().get(TankConstants.KEY_JVM_ARGS); logger.info("Starting apiharness with command: " + API_HARNESS_COMMAND + " -http=" + controllerBase + " " + jvmArgs); Runtime.getRuntime().exec(API_HARNESS_COMMAND + " -http=" + controllerBase + " " + jvmArgs); } catch (Exception e) { logger.error("Error in AgentStartup " + e, e); } }
From source file:cc.altruix.econsimtr01.App.java
public void run(final InputStream stream) { try {/*from ww w. j ava2 s.c om*/ final String dirName = String.format("%s/econsim-tr01-%d", System.getProperty("user.dir"), new Date().getTime()); final File dir = new File(dirName); //noinspection ResultOfMethodCallIgnored dir.mkdir(); final String theoryTxt = IOUtils.toString(stream); final SimParametersProvider simParametersProvider = new SimParametersProvider(theoryTxt, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); final List<ResourceFlow> flows = new LinkedList<>(); final StringBuilder log = new StringBuilder(); new Simulation1(log, flows, simParametersProvider).run(); final File simResults = new File(String.format("%s/simResults.pl", dir.getAbsolutePath())); FileUtils.writeStringToFile(simResults, log.toString()); createCsvFile(dir, simResults); createFlowsDiagram(dir, flows); createParamsFile(dir, theoryTxt); } catch (final IOException exception) { exception.printStackTrace(); } }
From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.report.ConfusionMatrixTools.java
public static void generateNiceTable(File predictionsFile) throws IOException { ConfusionMatrix cm = tokenLevelPredictionsToConfusionMatrix(predictionsFile); File outFile = new File(predictionsFile.getParent(), "niceResults.csv"); FileUtils.writeStringToFile(outFile, prettyPrintConfusionMatrixResults(cm)); System.out.println("Writing " + outFile); }