List of usage examples for org.apache.commons.io IOUtils toInputStream
public static InputStream toInputStream(String input)
From source file:info.magnolia.ui.form.field.transformer.multi.MultiValueSubChildrenNodePropertiesTransformerTest.java
@Override @Before/*from w w w . j av a2s.c o m*/ public void setUp() throws Exception { super.setUp(); // Init parent Node String nodeProperties = "/parent.@type=mgnl:content\n" + "/parent.propertyString=hello\n" + "/parent/property.@type=mgnl:content\n" + "/parent/property/00.@type=mgnl:content\n" + "/parent/property/00.property1=value11\n" + "/parent/property/00.property2=value12\n" + "/parent/property/11.@type=mgnl:content\n" + "/parent/property/11.property1=value21\n" + "/parent/property/11.property2=value22\n"; Session session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE); new PropertiesImportExport().createNodes(session.getRootNode(), IOUtils.toInputStream(nodeProperties)); session.save(); definition.setName(propertyName); rootNode = session.getRootNode().getNode("parent"); }
From source file:io.druid.segment.realtime.firehose.EventReceiverFirehoseTest.java
@Test public void testSingleThread() throws IOException { EasyMock.expect(req.getContentType()).andReturn("application/json").times(NUM_EVENTS); EasyMock.replay(req);// w w w . jav a2 s . c om for (int i = 0; i < NUM_EVENTS; ++i) { final InputStream inputStream = IOUtils.toInputStream(inputRow); firehose.addAll(inputStream, req); Assert.assertEquals(i + 1, firehose.getCurrentBufferSize()); inputStream.close(); } EasyMock.verify(req); final Iterable<Map.Entry<String, EventReceiverFirehoseMetric>> metrics = register.getMetrics(); Assert.assertEquals(1, Iterables.size(metrics)); final Map.Entry<String, EventReceiverFirehoseMetric> entry = Iterables.getLast(metrics); Assert.assertEquals(SERVICE_NAME, entry.getKey()); Assert.assertEquals(CAPACITY, entry.getValue().getCapacity()); Assert.assertEquals(CAPACITY, firehose.getCapacity()); Assert.assertEquals(NUM_EVENTS, entry.getValue().getCurrentBufferSize()); Assert.assertEquals(NUM_EVENTS, firehose.getCurrentBufferSize()); for (int i = NUM_EVENTS - 1; i >= 0; --i) { Assert.assertTrue(firehose.hasMore()); Assert.assertNotNull(firehose.nextRow()); Assert.assertEquals(i, firehose.getCurrentBufferSize()); } Assert.assertEquals(CAPACITY, entry.getValue().getCapacity()); Assert.assertEquals(CAPACITY, firehose.getCapacity()); Assert.assertEquals(0, entry.getValue().getCurrentBufferSize()); Assert.assertEquals(0, firehose.getCurrentBufferSize()); firehose.close(); Assert.assertFalse(firehose.hasMore()); Assert.assertEquals(0, Iterables.size(register.getMetrics())); }
From source file:eu.seaclouds.platform.dashboard.util.ObjectMapperHelpers.java
/** * Transforms a XML string to an List<Object> using javax.xml.bind.Unmarshaller. * If you want to parse a single Object please @see {#link XmlToObject} * * @param xml string representing a collection of objects * @param type Class of the contained objects within the list * @param <T> target class//from ww w . ja v a 2 s . c o m * @return a List of T * @throws IOException if is not possible to parse the object **/ public static <T> List<T> XmlToObjectCollection(String xml, Class<T> type) throws JAXBException { JAXBContext ctx = JAXBContext.newInstance(ObjectMapperHelpers.JAXBCollection.class, type); Unmarshaller u = ctx.createUnmarshaller(); Source src = new StreamSource(IOUtils.toInputStream(xml)); ObjectMapperHelpers.JAXBCollection<T> collection = u .unmarshal(src, ObjectMapperHelpers.JAXBCollection.class).getValue(); return collection.getItems(); }
From source file:com.nike.cerberus.service.S3StoreServiceTest.java
@Test public void testGet() { AmazonS3 client = mock(AmazonS3.class); S3StoreService service = new S3StoreService(client, S3_BUCKET, S3_PREFIX); String path = "path"; String value = "value"; ArgumentCaptor<GetObjectRequest> request = ArgumentCaptor.forClass(GetObjectRequest.class); S3Object s3Object = new S3Object(); s3Object.setObjectContent(//from www. j a va 2s . c o m new S3ObjectInputStream(IOUtils.toInputStream(value), mock(HttpRequestBase.class))); when(client.getObject(request.capture())).thenReturn(s3Object); // invoke method under test Optional<String> result = service.get(path); assertTrue(result.isPresent()); assertEquals(value, result.get()); assertEquals(S3_BUCKET, request.getValue().getBucketName()); assertEquals(S3_PREFIX + "/" + path, request.getValue().getKey()); }
From source file:com.xing.android.sdk.network.request.RequestUtilsTest.java
@Test public void inputStreamToString() throws Exception { InputStream firsAssertStream = IOUtils.toInputStream("test"); String str = RequestUtils.inputStreamToString(firsAssertStream); assertEquals("test", str); InputStream secondAssertStream = IOUtils.toInputStream(""); str = RequestUtils.inputStreamToString(secondAssertStream); assertEquals("", str); try {/*w w w . ja va 2 s . co m*/ RequestUtils.inputStreamToString(null); fail("Should throw exception"); } catch (Exception expected) { assertNotNull(expected); } }
From source file:at.sti2.spark.handler.SupportHandler.java
@Override public void invoke(Match match) throws SparkwaveHandlerException { boolean twominfilter = false; String xsltLocation = "target/classes/support/fromRDFToEvent.xslt"; String value = handlerProperties.getValue("twominfilter"); if (value == null || (value != null && value.equals("true"))) { twominfilter = true;//from ww w. j a v a 2s .c om } value = handlerProperties.getValue("xsltLocation"); if (value != null && !"".equals(value)) { xsltLocation = value; } /* * TODO This is a hack to stop Impactorium handler of sending thousands of matches regarding the same event. * ******************************************************/ if (twominfilter) { long timestamp = (new Date()).getTime(); if (timestamp - twoMinutesPause < 120000) return; twoMinutesPause = timestamp; } /* *****************************************************/ final String url = handlerProperties.getValue("url"); logger.info("Invoking URL " + url); // formatting match to n-triple format final List<TripleCondition> conditions = handlerProperties.getTriplePatternGraph().getConstruct() .getConditions(); final String formatMatchNTriples = match.outputNTriples(conditions); // converting n-triple string to inputstream final InputStream strIn = IOUtils.toInputStream(formatMatchNTriples); ByteArrayOutputStream out1 = new ByteArrayOutputStream(); // convert n-triple to RDFXML RDFFormatTransformer ntToRDFXML = new RDFFormatTransformer(); ntToRDFXML.init(strIn, out1); ntToRDFXML.setProperty("from", "N3"); ntToRDFXML.setProperty("to", "RDF/XML-ABBREV"); ntToRDFXML.process(); logger.debug("N3 -> RDF/XML output:\n" + out1.toString()); ByteArrayInputStream in1 = new ByteArrayInputStream(out1.toByteArray()); ByteArrayOutputStream out2 = new ByteArrayOutputStream(); // convert RDFXML to XML XSLTransformer rdfxmlToXML = new XSLTransformer(); rdfxmlToXML.init(in1, out2); rdfxmlToXML.setProperty("xsltLocation", xsltLocation); rdfxmlToXML.process(); String strEvent = out2.toString(); logger.debug("RDF/XML -> Event XML output:\n" + strEvent); sendToREST(url, strEvent); }
From source file:info.magnolia.ui.workbench.column.StatusColumnFormatterTest.java
@Override @Before/* w w w . jav a 2 s . co m*/ public void setUp() throws Exception { super.setUp(); // Init parent Node String nodeProperties = "/parent.@type=mgnl:page\n" + "/parent.propertyString=hello\n" + "/parent/child.@type=mgnl:content\n" + "/parent/child.propertyString=chield1\n"; session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE); new PropertiesImportExport().createNodes(session.getRootNode(), IOUtils.toInputStream(nodeProperties)); session.save(); node = session.getRootNode().getNode("parent"); node.addMixin(NodeTypes.LastModified.NAME); node.addMixin(NodeTypes.Activatable.NAME); itemId = JcrItemUtil.getItemId(node); ConfiguredWorkbenchDefinition configuredWorkbench = new ConfiguredWorkbenchDefinition(); // Add view ConfiguredContentPresenterDefinition contentView = new TreePresenterDefinition(); configuredWorkbench.addContentView(contentView); PropertyTypeColumnDefinition colDef1 = new PropertyTypeColumnDefinition(); colDef1.setSortable(true); colDef1.setName("propertyString"); colDef1.setLabel("Label_" + "propertyString"); contentView.addColumn(colDef1); NodeTypeDefinition nodeTypeDefinition = new ConfiguredNodeTypeDefinition(); ((ConfiguredNodeTypeDefinition) nodeTypeDefinition).setName(NodeTypes.Content.NAME); ConfiguredJcrContentConnectorDefinition connectorDefinition = new ConfiguredJcrContentConnectorDefinition(); connectorDefinition.setRootPath("/parent"); connectorDefinition.setWorkspace(RepositoryConstants.WEBSITE); connectorDefinition.addNodeType(nodeTypeDefinition); ConfiguredWorkbenchDefinition workbenchDefinition = configuredWorkbench; HierarchicalJcrContainer hierarchicalJcrContainer = new HierarchicalJcrContainer(connectorDefinition); table = new Table(); table.setContainerDataSource(hierarchicalJcrContainer); statusColumnDefinition.setPermissions(false); }
From source file:com.cimmyt.csv.FileManagerCSVImpl.java
/** * Method that load file in different type of browser * @param media/*from w w w. j a v a 2s. c om*/ * @return */ private Reader getReader(Media media) { Reader reader = null; try { reader = new InputStreamReader(IOUtils.toInputStream(media.getStringData())); return reader; } catch (IllegalStateException ex) { logger.error(ex.getMessage()); } try { reader = media.getReaderData(); return reader; } catch (IllegalStateException ex) { logger.error(ex.getMessage()); ; } try { reader = new InputStreamReader(media.getStreamData()); return reader; } catch (IllegalStateException ex) { ex.printStackTrace(); } return reader; }
From source file:com.norconex.committer.solr.SolrCommitterSolrIntegrationTest.java
@Test public void testCommitAdd() throws Exception { String content = "hello world!"; InputStream is = IOUtils.toInputStream(content); String id = "1"; Properties metadata = new Properties(); metadata.addString("id", id); // Add new doc to Solr committer.add(id, is, metadata);// ww w .j a v a 2 s . c om committer.commit(); IOUtils.closeQuietly(is); // Check that it's in Solr SolrDocumentList results = queryId(id); assertEquals(1, results.getNumFound()); }
From source file:com.collective.celos.ci.testing.fixtures.compare.RecursiveFsObjectComparerTest.java
@Test public void testComparesFilesFail() throws Exception { FixFile file1 = new FixFile(IOUtils.toInputStream("content")); FixFile file2 = new FixFile(IOUtils.toInputStream("contend")); FixObjectCompareResult compareResult = new RecursiveFsObjectComparer(Utils.wrap(file1), Utils.wrap(file2)) .check(null);//from w w w .j av a2 s. c om Assert.assertEquals(compareResult.getStatus(), FixObjectCompareResult.Status.FAIL); }