List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data) throws IOException
From source file:dk.deck.remoteconsole.proxy.LocalExecutor.java
public void executeAsScript(String command, String[] arguments, final PrintStream out, final PrintStream error) throws IOException, InterruptedException { File scriptFile = new File(LOCAL_SCRIPT); String script = command;/*from w w w . j av a 2 s . c o m*/ for (String argument : arguments) { script += " " + argument; } scriptFile.createNewFile(); FileUtils.writeStringToFile(scriptFile, script); Runtime.getRuntime().exec("chmod +x " + LOCAL_SCRIPT); execute("/bin/bash", new String[] { LOCAL_SCRIPT }, out, error); scriptFile.delete(); }
From source file:com.machinelinking.render.DefaultHTMLRenderTest.java
@Test public void testRender() throws IOException, NodeRenderException { final JsonNode node = JSONUtils.parseJSON(this.getClass().getResourceAsStream("Enrichment1.json")); final URL documentURL = new URL("http://en.wikipedia.org/page/Fake"); final DocumentContext context = new DefaultDocumentContext(RenderScope.FULL_RENDERING, documentURL); final String html = DefaultHTMLRenderFactory.getInstance().createRender().renderDocument(context, node); FileUtils.writeStringToFile(new File("./test-render.html"), html); }
From source file:de.tudarmstadt.ukp.dkpro.tc.core.io.JsonDataWriter.java
@Override public void write(File outputDirectory, FeatureStore featureStore, boolean useDenseInstances, String learningMode, boolean applyWeighting) throws Exception { FileUtils.writeStringToFile(new File(outputDirectory, JSON_FILE_NAME), gson.toJson(featureStore)); }
From source file:naftoreiclag.flowchartarch.ParseFiler.java
public static void writeGenes(Genes genes) { StringBuilder builder = new StringBuilder(); appendElementData(builder, 0, genes); try {/*from www .j a v a 2 s.c o m*/ FileUtils.writeStringToFile(new File("file.txt"), builder.toString()); System.out.println(" Successuful print"); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:edu.umn.msi.tropix.proteomics.test.ProteomicsInputTest.java
public void testProteomicsInput(final boolean readFromFile) throws Exception { BiomlWriter input = null;//w ww . j a v a 2 s.co m if (readFromFile) { final File tempFile = File.createTempFile("tpxtest", ""); tempFile.deleteOnExit(); FileUtils.writeStringToFile(tempFile, IOUtils.toString(getClass().getResourceAsStream("proteomicsInput1.xml"))); input = new BiomlWriter(tempFile.getAbsolutePath()); } else { input = new BiomlWriter(getClass().getResourceAsStream("proteomicsInput1.xml")); } boolean wasException = false; try { input.addVariable("test heading", "test"); } catch (final IllegalArgumentException e) { wasException = true; } assert wasException; input.addHeader("test heading 2"); input.addVariable("test heading 2", "param1", "param1 value again"); input.addVariable("test heading 2", "param2", "param2 value"); final String xml = input.toString(); assert xml.contains("label=\"test heading 2\"") : "XML did not contain heading 2 label"; assert xml.contains("label=\"test heading 2, param1\"") : "XML did not contain param1 input"; assert xml.contains("label=\"test heading 2, param2\"") : "XML did not contain param2 input"; assert xml.contains(">param1 value again<") : "XML did not contain param1 value"; assert xml.contains(">param2 value<") : "XML did not contain param2 value"; assert xml.contains("label=\"test heading, param1\"") : "XML did not contain old param1 value"; assert xml.contains(">param1 value<") : "XML did not contain old param1 value"; }
From source file:bear.main.CompiledEntry.java
public void saveText(String text) { try {// w w w.j a v a2s .c o m FileUtils.writeStringToFile(file, text); } catch (IOException e) { throw Exceptions.runtime(e); } }
From source file:com.dianping.maven.plugin.tools.misc.file.TemplateBasedFileGenerator.java
public void generate(File file, T context) throws Exception { FileUtils.writeStringToFile(file, buildContent(context)); }
From source file:com.cloudbees.jenkins.support.api.FileContentTest.java
@Test public void truncation() throws Exception { File f = tmp.newFile();//from w w w .j av a 2 s. c o m FileUtils.writeStringToFile(f, "hello world\n"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new FileContent("-", f).writeTo(baos); assertEquals("hello world\n", baos.toString()); baos.reset(); new FileContent("-", f, 10).writeTo(baos); assertEquals("hello worl", baos.toString()); baos.reset(); new FileContent("-", f, 20).writeTo(baos); assertEquals("hello world\n", baos.toString()); }
From source file:com.github.neio.filesystem.paths.TestFilePath.java
@Test public void test_FileSuccessfullyInstantiated() throws IOException { FileUtils.writeStringToFile(new File(testDir, "testFile"), "Hello World"); new FilePath("./testTempDir/testFile"); }
From source file:com.elasticgrid.amazon.boot.BootstrapperTest.java
@Test public void testMonitorLaunch() throws IOException, EC2Exception { String data = "CLUSTER_NAME=test\n" + "AWS_ACCESS_ID=123456123456\n" + "AWS_SECRET_KEY=123456123456\n" + "AWS_EC2_AMI32=ami-bdcb2dd4\n" + "AWS_EC2_AMI64=ami-fdcb2d94\n" + "AWS_EC2_KEYPAIR=eg-keypair\n" + "AWS_SQS_SECURED=true\n" + "DROP_BUCKET=elastic-grid-drop-target"; FileUtils.writeStringToFile(new File("/tmp/user-data"), data); FileUtils.writeStringToFile(new File("/tmp/security-groups"), "elastic-grid, elastic-grid-cluster-test, eg-monitor"); System.setProperty("EG_HOME", System.getProperty("java.io.tmpdir")); new File(System.getProperty("java.io.tmpdir") + File.separatorChar + "config").mkdir(); Bootstrapper bootstrapper = new Bootstrapper(); Properties props = new Properties(); props.load(new FileInputStream(System.getProperty("java.io.tmpdir") + "/config/eg.properties")); Assert.assertEquals("Wrong AWS Access ID", "123456123456", props.getProperty(EC2Configuration.AWS_ACCESS_ID)); Assert.assertEquals("Wrong AWS Secret Key", "123456123456", props.getProperty(EC2Configuration.AWS_SECRET_KEY)); Assert.assertEquals("Wrong AWS AMI for 32 bits", "ami-bdcb2dd4", props.getProperty(EC2Configuration.AWS_EC2_AMI32)); Assert.assertEquals("Wrong AWS AMI for 64 bits", "ami-fdcb2d94", props.getProperty(EC2Configuration.AWS_EC2_AMI64)); Assert.assertEquals("Wrong AWS KeyPair", "eg-keypair", props.getProperty(EC2Configuration.AWS_EC2_KEYPAIR)); Assert.assertEquals("Wrong AWS SQS security setting", "true", props.getProperty(EC2Configuration.AWS_SQS_SECURED)); Assert.assertEquals("Wrong EG Cluster name", "test", props.getProperty(EC2Configuration.EG_CLUSTER_NAME)); Assert.assertEquals("Wrong EG Drop Bucket", "elastic-grid-drop-target", props.getProperty(EC2Configuration.EG_DROP_BUCKET)); }