List of usage examples for org.apache.commons.io FileUtils writeStringToFile
public static void writeStringToFile(File file, String data) throws IOException
From source file:IntegrationTests.FileStorageUploadIT.java
@Before public void setUp() throws IOException { try {/*from w w w . j av a2s . co m*/ fileShareName = "testshare-" + TestEnvironment.GenerateRandomString(10); testEnv = new TestEnvironment(fileShareName); File directory = new File(fileShareName); if (!directory.exists()) directory.mkdir(); testEnv.account = AzureUtils.getCloudStorageAccount(testEnv.sampleStorageAccount); testEnv.fileShare = testEnv.account.createCloudFileClient().getShareReference(fileShareName); testEnv.fileShare.createIfNotExists(); for (int i = 0; i < testEnv.TOTAL_FILES; i++) { String tempContent = UUID.randomUUID().toString(); File temp = new File(directory.getAbsolutePath(), "upload" + tempContent + ".txt"); FileUtils.writeStringToFile(temp, tempContent); testEnv.uploadFileList.put(tempContent, temp); } } catch (Exception e) { LOGGER.log(Level.SEVERE, null, e); assertTrue(e.getMessage(), false); } }
From source file:com.predic8.membrane.examples.tests.LoadBalancerSession3Test.java
/** * The test as described in README.txt, but "wsimport" (previously called by ant) * was removed and is run directly from this test before everything else. Thereby * we can use a Maven dependency on wsimport and do not have to download it ourselves. */// ww w.ja v a 2s. c om @Test public void test() throws IOException, InterruptedException { File base = getExampleDir("loadbalancer-session-3"); AssertUtils.replaceInFile(new File(base, "proxies.xml"), "8080", "3023"); AssertUtils.replaceInFile(new File(base, "src/com/predic8/chat/Client.java"), "8080", "3023"); AssertUtils.replaceInFile(new File(base, "data/ChatService.wsdl"), "8080", "3023"); Process2 sl = new Process2.Builder().in(base).script("service-proxy").waitForMembrane().start(); try { File buildXML = new File(base, "build.xml"); // remove <exec...</exec> from build.xml String s = Pattern.compile("<exec.*</exec>", Pattern.DOTALL) .matcher(FileUtils.readFileToString(buildXML)).replaceAll(""); FileUtils.writeStringToFile(buildXML, s); File classes = new File(base, "build" + File.separator + "classes"); classes.mkdirs(); File source = new File(base, "src"); source.mkdirs(); // run "wsimport" generating java sources Assert.assertTrue(new com.sun.tools.ws.wscompile.WsimportTool(System.out).run(new String[] { "-quiet", "-Xnocompile", new File(base, "data" + File.separator + "ChatService.wsdl").getAbsolutePath(), "-s", source.getAbsolutePath() })); // call "ant compile" now so that both antNodeX processes do call it at the same time BufferLogger loggerCompile = new BufferLogger(); Process2 antCompile = new Process2.Builder().in(base).withWatcher(loggerCompile) .executable("ant compile").start(); try { int result = antCompile.waitFor(60000); if (result != 0) throw new AssertionError( "'ant compile' returned non-zero " + result + ":\r\n" + loggerCompile.toString()); } finally { antCompile.killScript(); } BufferLogger loggerNode1 = new BufferLogger(); BufferLogger loggerNode2 = new BufferLogger(); Process2 antNode1 = new Process2.Builder().in(base).withWatcher(loggerNode1).executable("ant run-node1") .start(); try { Process2 antNode2 = new Process2.Builder().in(base).withWatcher(loggerNode2) .executable("ant run-node2").start(); try { LoadBalancerUtil.addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4000); LoadBalancerUtil.addLBNodeViaHTML("http://localhost:9000/admin/", "localhost", 4001); Thread.sleep(1000); // wait for nodes to come up Process2 antClient = new Process2.Builder().in(base).executable("ant run-client -Dlogin=jim") .start(); try { antClient.waitFor(60000); } finally { antClient.killScript(); } } finally { antNode2.killScript(); } } finally { antNode1.killScript(); } AssertUtils.assertContains("Hallo World", loggerNode1.toString()); AssertUtils.assertContainsNot("Hallo World", loggerNode2.toString()); } finally { sl.killScript(); } }
From source file:edu.umn.msi.tropix.common.io.FileUtilsImpl.java
public void writeStringToFile(final File file, final String data) { try {//from ww w. ja v a2 s .co m FileUtils.writeStringToFile(file, data); } catch (final IOException e) { throw new IORuntimeException(e); } }
From source file:extraction.com.clearforest.ExtractorRunnable.java
@Override public void run() { System.out.println("Extracting: " + file); try {//from w ww . j av a 2s . c o m //XXX this is not always the case! // String content = new SgmlDocument(new FileReader(file)).getSignalText(); NYTCorpusDocument doc = null; synchronized (nyp) { doc = nyp.parseNYTCorpusDocumentFromFile(file, false); } StringBuilder sb = new StringBuilder(); List<String> titles = doc.getTitles(); if (!titles.isEmpty()) { sb.append(titles.get(0)); for (int i = 1; i < titles.size(); i++) { sb.append("\n" + titles.get(i)); } sb.append("\n" + doc.getBody()); } else { sb.append(doc.getBody()); } Thread.sleep(250); String content = sb.toString(); if (content.length() < LIMIT_SIZE) { String result = new CalaisLocator().getcalaisSoap().enlighten(licenseID, content, paramsXML); FileUtils.writeStringToFile(new File(outputFile), result); } else { int lastIndex = 0; int split = 0; int endIndex = content.substring(lastIndex, Math.min(lastIndex + LIMIT_SIZE, content.length())) .lastIndexOf('\n'); String chunk = content.substring(lastIndex, endIndex); while (!chunk.isEmpty()) { String result = new CalaisLocator().getcalaisSoap().enlighten(licenseID, chunk, paramsXML); FileUtils.writeStringToFile(new File(outputFile + "." + split), result); lastIndex = endIndex; endIndex = lastIndex + content.substring(lastIndex, Math.min(lastIndex + LIMIT_SIZE, content.length())) .lastIndexOf('\n'); chunk = content.substring(lastIndex, endIndex); split++; } } } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ServiceException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:net.itransformers.bgpPeeringMap.BgpPeeringMap.java
public static void discover() throws Exception { Map<String, String> settings = loadProperties(new File(settingsFile)); logger.info("Settings" + settings.toString()); String folderPlaceholder = settings.get("output.dir"); File outputDir = new File(projectDir + File.separator + folderPlaceholder, label); System.out.println(outputDir.getAbsolutePath()); boolean result = outputDir.mkdir(); File graphmlDir = new File(outputDir, "undirected"); result = outputDir.mkdir();// w w w . j av a 2 s . c om XsltTransformer transformer = new XsltTransformer(); logger.info("SNMP walk start"); byte[] rawData = snmpWalk(settings); logger.info("SNMP walk end"); File rawDataFile = new File(outputDir, "raw-data-bgpPeeringMap.xml"); FileUtils.writeStringToFile(rawDataFile, new String(rawData)); logger.info("Raw-data written to a file in folder " + outputDir); logger.info("First-transformation has started with xsltTransformator " + settings.get("xsltFileName1")); ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream(); File xsltFileName1 = new File(projectDir, settings.get("xsltFileName1")); ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData); transformer.transformXML(inputStream1, xsltFileName1, outputStream1, settings); logger.info("First transformation finished"); File intermediateDataFile = new File(outputDir, "intermediate-bgpPeeringMap.xml"); FileUtils.writeStringToFile(intermediateDataFile, new String(outputStream1.toByteArray())); logger.trace("First transformation output"); logger.trace(outputStream1.toString()); logger.info("Second transformation started with xsltTransformator " + settings.get("xsltFileName2")); ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream(); File xsltFileName2 = new File(projectDir, settings.get("xsltFileName2")); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(outputStream1.toByteArray()); transformer.transformXML(inputStream2, xsltFileName2, outputStream2, settings); logger.info("Second transformation info"); logger.trace("Second transformation Graphml output"); logger.trace(outputStream2.toString()); ByteArrayInputStream inputStream3 = new ByteArrayInputStream(outputStream2.toByteArray()); ByteArrayOutputStream outputStream3 = new ByteArrayOutputStream(); File xsltFileName3 = new File(System.getProperty("base.dir"), settings.get("xsltFileName3")); transformer.transformXML(inputStream3, xsltFileName3, outputStream3, null); File outputFile = new File(graphmlDir, "undirected-bgpPeeringMap.graphml"); FileUtils.writeStringToFile(outputFile, new String(outputStream3.toByteArray())); logger.info("Output Graphml saved in a file in" + graphmlDir); //FileUtils.writeStringToFile(nodesFileListFile, "bgpPeeringMap.graphml"); FileWriter writer = new FileWriter(new File(outputDir, "undirected" + ".graphmls"), true); writer.append("undirected-bgpPeeringMap.graphml").append("\n"); writer.close(); }
From source file:com.github.neio.filesystem.paths.TestFilePath.java
@Test public void testExists() throws IOException { FileUtils.writeStringToFile(new File(testDir, "testFile"), "Hello World"); Assert.assertTrue(new FilePath("./testTempDir/testFile").exists()); }
From source file:com.camel.drools.expert.sample.service.OrderAutoFlowService.java
public void createDrlFile(UserRule userRule) { //?freemarker ? Template temp = getTemplate(dslrFtlName); //freemarker??dslr String dslr = generDslrFromFtlFile(userRule, temp); System.out.println(dslr);//from w w w . j a v a 2 s . c o m final Reader dslReader = new InputStreamReader(this.getClass().getResourceAsStream(dslFilePath)); String drl = getDrlFromDsl(new StringReader(dslr), dslReader); System.out.println(drl); File file = new File(KBaseContext.getClassPath() + drlDirPath + userRule.getUserCode() + ".drl"); try { FileUtils.writeStringToFile(file, drl); } catch (IOException e) { e.printStackTrace(); } }
From source file:fr.paris.lutece.plugins.seo.service.RuleFileService.java
/** * Generate the rule file/*from w ww .j av a 2 s .c o m*/ * @throws java.io.IOException If an error occurs */ public static void generateFile() throws IOException { String strFilePath = AppPathService.getWebAppPath() + AppPropertiesService.getProperty(PROPERTY_FILE); File file = new File(strFilePath); FileUtils.writeStringToFile(file, generateFileContent()); }
From source file:edu.umn.msi.tropix.common.io.IOContextsTest.java
@Test(groups = "unit") public void inputForFileFunction() throws IOException { final File file1 = File.createTempFile("tpx", "tst"), file2 = File.createTempFile("tpx", "tst"); try {/*w ww .j a v a2 s . co m*/ FileUtils.writeStringToFile(file1, "Moo Cow"); final InputContext inputContext = InputContexts.getForFileFunction().apply(file1); inputContext.get(file2); final String contents = FileUtils.readFileToString(file2); assert contents.equals("Moo Cow") : contents; } finally { FileUtils.deleteQuietly(file1); FileUtils.deleteQuietly(file2); } }
From source file:avantssar.aslanpp.testing.LibraryTestTask.java
public LibraryTestTask(ISpecProvider specProvider, File modelsDir) throws IOException { this.specProvider = specProvider; ASLanPPSpecification spec = specProvider.getASLanPPSpecification(); StringBuffer sb = new StringBuffer(); sb.append(spec.getSpecificationName()); if (specProvider instanceof IChannelModelFlexibleSpecProvider) { IChannelModelFlexibleSpecProvider cmFlex = (IChannelModelFlexibleSpecProvider) specProvider; sb.append("_"); sb.append(cmFlex.getChannelModel().toString()); if (specProvider instanceof IChannelTypeFlexibleSpecProvider) { IChannelTypeFlexibleSpecProvider ctFlex = (IChannelTypeFlexibleSpecProvider) specProvider; sb.append("_"); sb.append(ctFlex.getChannelType().type.toString()); }//from w w w . ja va 2 s . co m } String baseFileName = sb.toString(); sb.append(".aslan++"); spec.setSpecificationName(baseFileName); aslanPP = new File(FilenameUtils.concat(modelsDir.getAbsolutePath(), sb.toString())); aslan = new File(FilenameUtils.removeExtension(aslanPP.getAbsolutePath()) + ".aslan"); FileUtils.writeStringToFile(aslanPP, spec.toString()); TranslatorOptions options = new TranslatorOptions(); IASLanSpec aslanSpec = specProvider.getExpectedASLanTranslation(options); aslanSpec.getHornClauses(); if (aslanSpec != null) { FileUtils.writeStringToFile(aslan, aslanSpec.getStrippedRepresentation()); } }