List of usage examples for org.apache.commons.io IOUtils toInputStream
public static InputStream toInputStream(String input)
From source file:fr.paris.lutece.plugins.crm.modules.form.service.draft.InMemoryBlobStoreService.java
/** * {@inheritDoc}//w w w . ja va 2 s.c om */ @Override public InputStream getBlobInputStream(String strKey) { byte[] bValue = getBlob(strKey); if (bValue != null) { return IOUtils.toInputStream(new String(bValue)); } return null; }
From source file:edu.northwestern.bioinformatics.studycalendar.core.StudyCalendarXmlTestCase.java
public static <R> Collection<R> parseCollectionDocumentString( StudyCalendarXmlCollectionSerializer<R> serializer, String doc) { return serializer.readCollectionDocument(IOUtils.toInputStream(doc)); }
From source file:com.smartitengineering.event.hub.spi.db.PersistentEvent.java
public InputStream getContentStream() { return IOUtils.toInputStream(new String(content)); }
From source file:com.norconex.committer.AbstractFileQueueCommitterTest.java
@Test public void testMultipleCommitThread() throws Exception { final AtomicInteger counter = new AtomicInteger(); final AbstractFileQueueCommitter committer = new AbstractFileQueueCommitter() { @Override//from w ww .j a v a2 s . c o m protected void commitAddition(IAddOperation operation) throws IOException { counter.incrementAndGet(); operation.delete(); } @Override protected void commitDeletion(IDeleteOperation operation) throws IOException { counter.incrementAndGet(); operation.delete(); } @Override protected void commitComplete() { } }; File queue = temp.newFolder(); committer.setQueueDir(queue.getPath()); // Use a bigger number to make sure the files are not // committed while they are added. committer.setQueueSize(1000); // Queue 50 files for additions for (int i = 0; i < 50; i++) { Properties metadata = new Properties(); committer.add(Integer.toString(i), IOUtils.toInputStream("hello world!"), metadata); } // Queue 50 files for deletions for (int i = 50; i < 100; i++) { Properties metadata = new Properties(); committer.remove(Integer.toString(i), metadata); } ExecutorService pool = Executors.newFixedThreadPool(10); for (int i = 0; i < 10; i++) { pool.submit(new Runnable() { @Override public void run() { try { committer.commit(); } catch (Exception e) { e.printStackTrace(); } } }); } pool.shutdown(); pool.awaitTermination(10, TimeUnit.SECONDS); // Each file should have been processed exactly once assertEquals(100, counter.intValue()); // All files should have been processed Collection<File> files = FileUtils.listFiles(queue, null, true); assertTrue(files.isEmpty()); }
From source file:com.norconex.importer.handler.transformer.impl.ReduceConsecutivesTransformerTest.java
@Test public void testWriteRead() throws IOException { ReduceConsecutivesTransformer t = new ReduceConsecutivesTransformer(); Reader reader = new InputStreamReader(IOUtils.toInputStream(xml)); t.loadFromXML(reader);/*from w ww. j a v a 2s.c o m*/ reader.close(); System.out.println("Writing/Reading this: " + t); ConfigurationUtil.assertWriteRead(t); }
From source file:fi.solita.datatree.xml.XmlVulnerabilitiesTest.java
@Test public void notices_XML_bombs() { // See http://msdn.microsoft.com/en-us/magazine/ee335713.aspx String xml = "<?xml version=\"1.0\"?>" + "<!DOCTYPE foo [" + " <!ENTITY a \"aaaaaaaaaaaaaaaaaa\">" + "]>" + "<foo>&a;&a;&a;&a;&a;&a;&a;&a;&a;</foo>"; // this would use gigabytes of memory: // attacker = "<?xml version=\"1.0\"?>\n" + // "<!DOCTYPE lolz [\n" + // " <!ENTITY lol \"lol\">\n" + // " <!ENTITY lol2 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + // " <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + // " <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + // " <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + // " <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + // " <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + // " <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + // " <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + // "]>\n" + // "<lolz>&lol9;</lolz>"; thrown.expect(IllegalArgumentException.class); thrown.expectMessage("DOCTYPE is disallowed"); XmlVulnerabilities.check(IOUtils.toInputStream(xml)); }
From source file:com.graphaware.test.integration.NeoTestServer.java
public void start() throws IOException, InterruptedException { temporaryFolder.create();/*ww w.j ava 2 s .co m*/ temporaryFolder.getRoot().deleteOnExit(); String serverConfigContents = IOUtils .toString(new ClassPathResource(neo4jServerConfigFile).getInputStream()); serverConfigContents = serverConfigContents.replaceAll("=conf/", "=" + temporaryFolder.getRoot().getAbsolutePath() + "/conf/"); serverConfigContents = serverConfigContents.replaceAll("=data/", "=" + temporaryFolder.getRoot().getAbsolutePath() + "/data/"); temporaryFolder.newFolder("conf"); File serverConfig = temporaryFolder.newFile("conf/neo4j-server.properties"); IOUtils.copy(IOUtils.toInputStream(serverConfigContents), new FileOutputStream(serverConfig)); IOUtils.copy(new ClassPathResource(neo4jConfigFile).getInputStream(), new FileOutputStream(temporaryFolder.newFile("conf/neo4j.properties"))); System.setProperty(Configurator.NEO_SERVER_CONFIG_FILE_KEY, serverConfig.getAbsolutePath()); bootstrapper = Bootstrapper.loadMostDerivedBootstrapper(); bootstrapper.start(new String[0]); }
From source file:edu.utah.further.core.xml.xquery.UTestXQueryServiceBaseX.java
@Before public void setup() { final StringBuilder sbXq = new StringBuilder(); sbXq.append("xquery version \"1.0\";"); sbXq.append("let $message := 'Hello World!'"); sbXq.append("return"); sbXq.append("<results>"); sbXq.append("<message>{$message}</message>"); sbXq.append("</results>"); testXQuery = IOUtils.toInputStream(sbXq.toString()); final StringBuilder sbXml = new StringBuilder(); sbXml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sbXml.append("<input></input>"); testXmlDocument = IOUtils.toInputStream(sbXml.toString()); }
From source file:com.cognifide.cq.cqsm.core.servlets.ScriptResultServlet.java
@Override protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException, IOException { String fileName = request.getParameter("filename"); String content = request.getParameter("content"); if (fileName == null || fileName.length() == 0) { LOGGER.error("Parameter fileName is required"); return;/*from www.j ava 2 s . c o m*/ } response.setContentType("application/octet-stream"); // Your content type response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8")); InputStream input = IOUtils.toInputStream(content); int read = 0; byte[] bytes = new byte[BYTES_DOWNLOAD]; OutputStream os = response.getOutputStream(); while ((read = input.read(bytes)) != -1) { os.write(bytes, 0, read); } input.close(); os.flush(); os.close(); }
From source file:baggage.guerilla.GuerillaParserTest.java
public void testDiscardText() throws Exception { String snippet = "Text here and <there is=\"a\" nice=\"tag\" /> and now for more text"; GuerillaParser parser = new GuerillaParser(IOUtils.toInputStream(snippet)); OpeningTag tag = (OpeningTag) parser.next(true); assertEquals("there", tag.getStringValue()); assertEquals(2, tag.getAttributes().size()); assertNull(parser.next(false));/*ww w.j a v a 2s . com*/ }