List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data) throws IOException
From source file:jenkins.plugins.shiningpanda.workspace.TestSlaveWorkspace.java
public void testGetPackageDirExists() throws Exception { File masterPackagesDir = createPackagesDir(); File masterPackagesFile = new File(masterPackagesDir, "toto.txt"); FileUtils.writeStringToFile(masterPackagesFile, "hello"); FilePath slavePackagesDir = getSlaveWorkspace().getPackagesDir(); File slavePackagesFile = new File(toFile(slavePackagesDir), "toto.txt"); assertContentEquals(masterPackagesFile, slavePackagesFile); assertNotSame("path of package on slave should differ from master one", masterPackagesFile.getAbsolutePath(), slavePackagesFile.getAbsoluteFile()); }
From source file:com.predic8.membrane.examples.tests.LoggingJDBCTest.java
@Test public void test() throws IOException, InterruptedException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { copyDerbyJarToMembraneLib();//ww w . ja v a 2 s . c om File baseDir = getExampleDir("logging-jdbc"); File beansConfig = new File(baseDir, "proxies.xml"); FileUtils.writeStringToFile(beansConfig, FileUtils.readFileToString(beansConfig) .replace("org.apache.derby.jdbc.ClientDriver", "org.apache.derby.jdbc.EmbeddedDriver") .replace("jdbc:derby://localhost:1527/membranedb;create=true", "jdbc:derby:derbyDB;create=true")); Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start(); try { getAndAssert200("http://localhost:2000/"); } finally { sl.killScript(); } assertLogToDerbySucceeded(baseDir); }
From source file:com.creactiviti.piper.core.taskhandler.script.Bash.java
@Override public String handle(Task aTask) throws Exception { File scriptFile = File.createTempFile("_script", ".sh"); File logFile = File.createTempFile("log", null); FileUtils.writeStringToFile(scriptFile, aTask.getRequiredString("script")); try (PrintStream stream = new PrintStream(logFile);) { Process chmod = Runtime.getRuntime().exec(String.format("chmod u+x %s", scriptFile.getAbsolutePath())); int chmodRetCode = chmod.waitFor(); if (chmodRetCode != 0) { throw new ExecuteException("Failed to chmod", chmodRetCode); }/* www. j a va 2 s . c o m*/ CommandLine cmd = new CommandLine(scriptFile.getAbsolutePath()); logger.debug("{}", cmd); DefaultExecutor exec = new DefaultExecutor(); exec.setStreamHandler(new PumpStreamHandler(stream)); exec.execute(cmd); return FileUtils.readFileToString(logFile); } catch (ExecuteException e) { throw new ExecuteException(e.getMessage(), e.getExitValue(), new RuntimeException(FileUtils.readFileToString(logFile))); } finally { FileUtils.deleteQuietly(logFile); FileUtils.deleteQuietly(scriptFile); } }
From source file:com.googlecode.promnetpp.research.main.CoverageMain.java
private static void doSeedRun(int seed) throws IOException, InterruptedException { currentSeed = seed;//from ww w .j av a2 s.c o m 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); FileUtils.writeStringToFile(new File("temp.pml"), sourceCodeWithSeed); //Run Spin first List<String> spinCommand = new ArrayList<String>(); spinCommand.add(GeneralData.spinHome + "/spin"); spinCommand.add("-a"); spinCommand.add("temp.pml"); ProcessBuilder processBuilder = new ProcessBuilder(spinCommand); Process process = processBuilder.start(); process.waitFor(); //Compile PAN next List<String> compilePANCommand = new ArrayList<String>(); compilePANCommand.add("gcc"); compilePANCommand.add("-o"); compilePANCommand.add("pan"); compilePANCommand.add("pan.c"); processBuilder = new ProcessBuilder(compilePANCommand); process = processBuilder.start(); process.waitFor(); //Finally, run PAN List<String> runPANCommand = new ArrayList<String>(); runPANCommand.add("./pan"); String runtimeOptions = PANOptions.getRuntimeOptionsFor(fileName); if (!runtimeOptions.isEmpty()) { runPANCommand.add(runtimeOptions); } processBuilder = new ProcessBuilder(runPANCommand); process = processBuilder.start(); process.waitFor(); String PANOutput = Utilities.getStreamAsString(process.getInputStream()); if (PANOutputContainsErrors(PANOutput)) { throw new RuntimeException("PAN reported errors."); } processPANOutput(PANOutput); }
From source file:com.kotcrab.vis.editor.util.CrashReporter.java
public void processReport() throws IOException { File crashReportFile = new File(logFile.getParent(), "viseditor-crash " + new SimpleDateFormat("yy-MM-dd HH-mm-ss").format(new Date()) + ".txt"); FileUtils.writeStringToFile(crashReportFile, report); Log.info(TAG, "Crash saved to file: " + crashReportFile.getAbsolutePath()); }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.prettyprint.PlanPlotter.java
public static void printOptimizedLogicalPlan(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 a va2 s. c om*/ appendln(out, "\n}\n}"); try { File file = File.createTempFile("logicalOptimizedPlan", ".txt"); FileUtils.writeStringToFile(file, out.toString()); file.deleteOnExit(); } catch (IOException e) { e.printStackTrace(); } }
From source file:gov.nih.nci.cabig.caaers.service.adverseevent.AdditionalInformationDocumentServiceIntegrationTest.java
@Override protected void setUp() throws Exception { super.setUp(); file = File.createTempFile(RandomStringUtils.randomAlphabetic(4), ".txt"); FileUtils.writeStringToFile(file, "sample text"); additionalInformationDocumentService = (AdditionalInformationDocumentService) getDeployedApplicationContext() .getBean("additionalInformationDocumentService"); expeditedAdverseEventReportDao = (ExpeditedAdverseEventReportDao) getDeployedApplicationContext() .getBean("expeditedAdverseEventReportDao"); ExpeditedAdverseEventReport expeditedAdverseEventReport = expeditedAdverseEventReportDao.getById(-1); additionalInformation = expeditedAdverseEventReport.getAdditionalInformation(); }
From source file:com.sangupta.codefix.RemoveCopyright.java
@Override protected String processEachFile(File file) throws IOException { // read contents String contents = FileUtils.readFileToString(file).trim(); // check if file contains comments or not boolean hasCopyright = CopyrightHelper.checkCopyrightExists(contents); if (!hasCopyright) { return "no copyright detected"; }/* w ww . java 2 s . co m*/ // find the ending location int index = CopyrightHelper.findCopyrightEnd(contents); if (index == -1) { return "no proper end to comment detected, skipping!"; } contents = contents.substring(index + 1); FileUtils.writeStringToFile(file, contents); return "copyright removed!"; }
From source file:io.restassured.itest.java.FileUploadingITest.java
@Test public void can_upload_xml_from_file() throws IOException { // Given/*from w w w . j a v a2 s . com*/ File file = folder.newFile("my.xml"); FileUtils.writeStringToFile(file, "<tag attr='value'>"); // When given().contentType(ContentType.XML).body(file).when().post("/validateContentTypeIsDefinedAndReturnBody") .then().statusCode(200).contentType(ContentType.XML).body(equalTo("<tag attr='value'>")); }
From source file:com.wavemaker.tools.project.upgrade.swamis.PanesRenameUpgradeTest.java
public void testUpgrade() throws Exception { File root = IOUtils.createTempDirectory("testUpgrade", "_dir"); Project p = new Project(new FileSystemResource(root.getAbsolutePath() + "/"), new LocalStudioFileSystem()); p.getWebAppRoot().getFile().mkdir(); File panes = new File(p.getWebAppRoot().getFile(), "panes"); panes.mkdir();/*from w w w . jav a 2s . c o m*/ File panesFile = new File(panes, "foo.txt"); FileUtils.writeStringToFile(panesFile, "foo"); File pages = new File(p.getWebAppRoot().getFile(), ProjectConstants.PAGES_DIR); assertFalse(pages.exists()); PanesRenameUpgrade pru = new PanesRenameUpgrade(); pru.doUpgrade(p, new UpgradeInfo()); assertTrue(pages.exists()); assertFalse(panes.exists()); File pagesFile = new File(pages, "foo.txt"); assertTrue(pagesFile.exists()); assertEquals("foo", FileUtils.readFileToString(pagesFile)); }