List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data) throws IOException
From source file:hu.bme.mit.incqueryd.engine.util.EObjectDeserializer.java
public static EObject deserializeFromString(final String model, Set<? extends EPackage> packages) throws IOException { final File tempFile = EObjectSerializer.createTempFile(); FileUtils.writeStringToFile(tempFile, model); return deserializeFromFile(tempFile.getPath(), packages); }
From source file:de.tudarmstadt.ukp.clarin.webanno.support.JSONUtil.java
public static void generateJson(Object aObject, File aFile) throws IOException { FileUtils.writeStringToFile(aFile, toJsonString(aObject)); }
From source file:com.athena.meerkat.controller.web.provisioning.util.ProvisioningUtil.java
public static int getJobNum(File jobBaseDir) throws IOException { File jobFile = new File(jobBaseDir.getAbsolutePath() + File.separator + JOB_NUM_FILE_NAME); int jobNum = 0; if (jobFile.exists()) { jobNum = Integer.parseInt(FileUtils.readFileToString(jobFile)); }//from w ww. jav a2 s .c o m FileUtils.writeStringToFile(jobFile, String.valueOf(++jobNum)); return jobNum; }
From source file:edu.illinois.cs.cogcomp.nlp.corpusreaders.ereReader.CoNLL2002Writer.java
/** * Pass in the view, text annotation and the filename, it will produce the labels in the view to * a file named filename in CoNLL2002 format. * /*from w w w .j a v a 2s. c o m*/ * @param view the view with the labels to produce. * @param ta the text annotation. * @param filename the filename. * @throws IOException */ static public void writeViewInCoNLL2002Format(View view, TextAnnotation ta, String filename) throws IOException { String text = produceCoNLL2002Annotations(view, ta); FileUtils.writeStringToFile(new File(filename), text); }
From source file:com.googlecode.promnetpp.research.main.CompareOutputMain.java
private static void doSeedRun(int seed) throws IOException, InterruptedException { System.out.println("Running with seed " + seed); String pattern = "int random = <INSERT_SEED_HERE>;"; int start = sourceCode.indexOf(pattern); int end = start + pattern.length(); String line = sourceCode.substring(start, end); line = line.replace("<INSERT_SEED_HERE>", Integer.toString(seed)); String sourceCodeWithSeed = sourceCode.replace(pattern, line); File tempFile = new File("temp.pml"); FileUtils.writeStringToFile(tempFile, sourceCodeWithSeed); //Create a "project" folder String fileNameWithoutExtension = fileName.split("[.]")[0]; File folder = new File("test1-" + fileNameWithoutExtension); if (folder.exists()) { FileUtils.deleteDirectory(folder); }//from ww w.j a v a 2 s .com folder.mkdir(); //Copy temp.pml to our new folder FileUtils.copyFileToDirectory(tempFile, folder); //Simulate the model using Spin List<String> spinCommand = new ArrayList<String>(); spinCommand.add(GeneralData.spinHome + "/spin"); spinCommand.add("-u1000000"); spinCommand.add("temp.pml"); ProcessBuilder processBuilder = new ProcessBuilder(spinCommand); processBuilder.directory(folder); processBuilder.redirectOutput(new File(folder, "spin-" + seed + ".txt")); Process process = processBuilder.start(); process.waitFor(); //Translate via PROMNeT++ List<String> PROMNeTppCommand = new ArrayList<String>(); PROMNeTppCommand.add("java"); PROMNeTppCommand.add("-enableassertions"); PROMNeTppCommand.add("-jar"); PROMNeTppCommand.add("\"" + GeneralData.getJARFilePath() + "\""); PROMNeTppCommand.add("temp.pml"); processBuilder = new ProcessBuilder(PROMNeTppCommand); processBuilder.directory(folder); processBuilder.environment().put("PROMNETPP_HOME", GeneralData.PROMNeTppHome); process = processBuilder.start(); process.waitFor(); //Run opp_makemake FileUtils.copyFileToDirectory(new File("opp_makemake.bat"), folder); List<String> makemakeCommand = new ArrayList<String>(); if (Utilities.operatingSystemType.equals("windows")) { makemakeCommand.add("cmd"); makemakeCommand.add("/c"); makemakeCommand.add("opp_makemake.bat"); } else { throw new RuntimeException("Support for Linux/OS X not implemented" + " here yet."); } processBuilder = new ProcessBuilder(makemakeCommand); processBuilder.directory(folder); process = processBuilder.start(); process.waitFor(); //Run make FileUtils.copyFileToDirectory(new File("opp_make.bat"), folder); List<String> makeCommand = new ArrayList<String>(); if (Utilities.operatingSystemType.equals("windows")) { makeCommand.add("cmd"); makeCommand.add("/c"); makeCommand.add("opp_make.bat"); } else { throw new RuntimeException("Support for Linux/OS X not implemented" + " here yet."); } processBuilder = new ProcessBuilder(makeCommand); processBuilder.directory(folder); process = processBuilder.start(); process.waitFor(); System.out.println(Utilities.getStreamAsString(process.getInputStream())); System.exit(1); }
From source file:iotest.WriteToFileTest.java
@Ignore @Test//www. j a v a 2 s .c o m public void writeToFile() { System.out.println("Writing to file"); try { File newFIle = new File("geekin.xml"); FileUtils.writeStringToFile(newFIle, "Dubem is a geek "); FileInputStream fi = new FileInputStream(newFIle); File fo = new File("geekout.xml"); FileUtils.copyInputStreamToFile(fi, fo); } catch (FileNotFoundException ex) { Logger.getLogger(WriteToFileTest.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException io) { io.printStackTrace(); } }
From source file:com.martinwunderlich.nlp.arg.aifdb.util.AIFdbArgumentMapUtil.java
public static void printNodesToFile(List<AIFdbArgumentMap> list, NODE_TYPES type, String outfilePath) throws IOException { StringBuilder builder = new StringBuilder(); for (AIFdbArgumentMap map : list) { for (AIFdbNode node : map.getNodes()) if (node.getType().equals(type)) builder.append(node.getText() + "\n"); }/*from w w w . java 2 s.c o m*/ FileUtils.writeStringToFile(new File(outfilePath), builder.toString()); }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.PlanPlotter.java
public static void printLogicalPlan(ILogicalPlan plan) throws AlgebricksException { int indent = 5; StringBuilder out = new StringBuilder(); int randomInt = 10000 + randomGenerator.nextInt(100); appendln(out, "digraph G {"); for (Mutable<ILogicalOperator> root : plan.getRoots()) { printVisualizationGraph((AbstractLogicalOperator) root.getValue(), indent, out, "", randomInt); }/*from w w w . j av a 2 s . co m*/ appendln(out, "\n}\n}"); try { File file = File.createTempFile("logicalPlan", ".txt"); FileUtils.writeStringToFile(file, out.toString()); file.deleteOnExit(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.legstar.protobuf.cobol.ProtoCobolUtilsTest.java
public void testExtractNoPackageNameFromProtoFile() throws Exception { File protoFile = File.createTempFile(getName(), ".proto"); protoFile.deleteOnExit();/*from w w w . jav a 2 s.c o m*/ FileUtils.writeStringToFile(protoFile, ""); ProtoFileJavaProperties javaProperties = ProtoCobolUtils.getJavaProperties(protoFile); assertNull(javaProperties.getJavaPackageName()); }
From source file:IO.FileWriter.java
/** * Write a given string to file//from w w w. j av a2 s. c om * * @param text some text * @param destinationFilePath the path of the destination file */ public static void WriteFile(String text, String destinationFilePath) { try { FileUtils.writeStringToFile(new File(destinationFilePath), text); } catch (IOException e) { Console.PrintException("Error writing string to file", e); } }