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.xxg.jdeploy.util.FileUtil.java
public static void writeString(String encoding, String s, File outFile) throws IOException { try {/*from w w w.ja v a 2 s . co m*/ FileUtils.writeStringToFile(outFile, s, encoding); } catch (IOException e) { throw e; } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.createdebate.CorpusPreparator.java
/** * Extracts all debates from raw HTML files in inFolder and stores them into outFolder * as serialized {@link Debate} objects (see {@link DebateSerializer}. * * @param inFolder in folder//from ww w . j a v a 2 s . com * @param outFolder out folder (must exist) * @param debateParser debate parser implementation * @throws IOException exception */ public static void extractAllDebates(File inFolder, File outFolder, DebateParser debateParser) throws IOException { File[] files = inFolder.listFiles(); if (files == null) { throw new IOException("No such dir: " + inFolder); } for (File f : files) { InputStream inputStream = new FileInputStream(f); try { Debate debate = debateParser.parseDebate(inputStream); // we ignore empty debates (without arguments) if (debate != null && !debate.getArgumentList().isEmpty()) { // serialize to xml String xml = DebateSerializer.serializeToXML(debate); // same name with .xml File outputFile = new File(outFolder, f.getName() + ".xml"); FileUtils.writeStringToFile(outputFile, xml, "utf-8"); System.out.println("Saved to " + outputFile.getAbsolutePath()); // ensure we can read it again DebateSerializer.deserializeFromXML(FileUtils.readFileToString(outputFile)); } } catch (IOException ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(inputStream); } } }
From source file:de.bund.bfr.fskml.PythonScriptTest.java
public void testScript() throws IOException { // Creates temporary file. Fails the test if an error occurs. File f = File.createTempFile("temp", ""); f.deleteOnExit();// w w w . ja v a2 s .co m String origScript = "Hello World"; FileUtils.writeStringToFile(f, origScript, "UTF-8"); PythonScript pyScript = new PythonScript(f); assertEquals(origScript, pyScript.getScript()); }
From source file:com.huawei.streaming.cql.executor.PhysicalPlanWriter.java
/** * //from w w w . ja v a 2 s . c om * @param plan * @param file */ public static void write(PhysicalPlan plan, String file) { String s = createStringPlan(plan); try { FileUtils.writeStringToFile(new File(file), XML_HEADER + s, XML_CHARSET); } catch (IOException e) { LOG.error("failed to write physical plan to file {} for io error.", file); } }
From source file:com.bitplan.json.JsonAble.java
/** * save me to my Json File//from w ww . j a v a 2s . c o m * @throws IOException */ default void save() throws IOException { File jsonFile = getJsonFile(); if (!jsonFile.getParentFile().isDirectory()) jsonFile.getParentFile().mkdirs(); FileUtils.writeStringToFile(jsonFile, this.asJson(), "UTF-8"); }
From source file:com.bitplan.jaxb.ManagerImpl.java
/** * save me to an xmlFile/*from ww w. j a v a 2 s .c o m*/ * * @param xmlFile * @throws Exception */ public void saveAsXML(File xmlFile) throws Exception { sort(); String xml = asXML(); FileUtils.writeStringToFile(xmlFile, xml, "UTF-8"); }
From source file:com.ms.commons.test.classloader.util.AntxconfigUtil.java
private static void writeUrlToFile(URL url, File file) throws Exception { InputStream in = url.openStream(); String str = IOUtils.toString(in, ENDODING); str = str.replaceAll("description=\".*\"", "description=\"\""); IOUtils.closeQuietly(in);/*w w w . j a va 2s . com*/ FileUtils.writeStringToFile(file, str, ENDODING); }
From source file:edu.cuhk.hccl.TripAdvisorApp.java
@Override public void run(String[] args) throws IOException { super.run(args); if (cmdLine.hasOption('d')) { File dir = new File(cmdLine.getOptionValue('d')); for (File file : dir.listFiles()) { FileUtils.writeStringToFile(outFile, processStream(file.getAbsolutePath()).toString(), true); }/*from www .j a va2 s . co m*/ System.out.println("Processing is fininshed!"); } }
From source file:cleaner.ExternalHtmlCleaner.java
@Override public String CleanText(String html, String encoding) { try {/* ww w. j a v a2s.c o m*/ File tempIn = File.createTempFile("ExternalParserInput", ".tmp"); String tempInName = tempIn.getCanonicalPath(); File tempOut = File.createTempFile("ExternalParserOutput", ".tmp"); String tempOutName = tempOut.getCanonicalPath(); FileUtils.writeStringToFile(tempIn, html, encoding); String cmd = extScript + " " + tempInName + " " + tempOutName; System.out.println("Executing: " + cmd); Process proc = Runtime.getRuntime().exec(cmd); if (proc == null) { System.err.println("Cannot execute command: " + extScript); return null; } StringWriter err = new StringWriter(); IOUtils.copy(proc.getErrorStream(), err, encoding); String ErrStr = err.toString(); if (!ErrStr.isEmpty()) { System.err.println("External script " + extScript + " returned errors:"); System.err.println(ErrStr); throw new Exception("External script " + extScript + " returned errors"); } String out = FileUtils.readFileToString(tempOut); tempIn.delete(); tempOut.delete(); return LeoCleanerUtil.CollapseSpaces(out); } catch (Exception e) { System.err.println("Failed to run the script " + extScript + " Error: " + e); System.exit(1); } return null; }
From source file:de.qaware.cloud.deployer.plugin.extension.SSLExtensionTest.java
@Test public void testSetCertificate() throws IOException, EnvironmentConfigException, ResourceConfigException { String cert = "CERT"; File certFile = folder.newFile(); FileUtils.writeStringToFile(certFile, "CERT", Charset.defaultCharset()); SSLExtension extension = new SSLExtension(); extension.setCertificate(certFile);/* w w w .ja v a 2s .c o m*/ assertEquals(cert, extension.getCertificate()); }