List of usage examples for org.apache.commons.io IOUtils toInputStream
public static InputStream toInputStream(String input)
From source file:com.github.restdriver.clientdriver.unit.ClientDriverResponseTest.java
@Test public void creatingResponseWithInputStreamContentGives200Status() { ClientDriverResponse response = new ClientDriverResponse(IOUtils.toInputStream("content"), "application/octet-stream"); assertThat(response.getStatus(), is(200)); }
From source file:com.allogy.mime.MimeStreamingReaderTest.java
@Before public void setUp() { StringBuilder mimeBodyPartStringBuilder = new StringBuilder(); knownHeaders = new ArrayList<Header>(); for (int i = 0; i < 3; i++) { Header header = new BasicHeader(UUID.randomUUID().toString(), UUID.randomUUID().toString()); knownHeaders.add(header);// w w w . j av a 2s .c o m mimeBodyPartStringBuilder.append(header.toString()); mimeBodyPartStringBuilder.append("\r\n"); } mimeBodyPartStringBuilder.append("\r\n"); contentString = "hello world"; mimeBodyPartStringBuilder.append(contentString); mimeInputStream = IOUtils.toInputStream(mimeBodyPartStringBuilder.toString()); }
From source file:com.temenos.useragent.generic.mediatype.PlainTextEntityHandler.java
@Override public InputStream getContent() { return IOUtils.toInputStream(plainText); }
From source file:com.allogy.io.BulkUpdateInputStream.java
private void moveToNextInnerInputStream() { currentInputStream = currentInputStreamIterator.next(); if (currentInputStreamIterator.hasNext()) currentInputStream = new SequenceInputStream(currentInputStream, IOUtils.toInputStream(",")); }
From source file:com.norconex.importer.handler.tagger.impl.TestStatisticsTaggerTest.java
@Test public void testTagTextDocument() throws IOException, ImporterHandlerException { String txt = "White Rabbit checking watch" + "\n\n" + " In another moment down went Alice after it, never once " + "considering how in the world she was to get out again." + "\n\n" + " The rabbit-hole went straight on like a tunnel for some way, " + "and then dipped suddenly down, so suddenly that Alice had not a " + "moment to think about stopping herself before she found herself " + "falling down a very deep well." + "\n\n" + "`Well!' thought Alice to herself, `after such a fall as this, I " + "shall think nothing of tumbling down stairs! How brave they'll " + "all think me at home! Why, I wouldn't say anything about it, " + "even if I fell off the top of the house!' (Which was very likely " + "true.)"; TextStatisticsTagger t = new TextStatisticsTagger(); InputStream is = IOUtils.toInputStream(txt); ImporterMetadata meta = new ImporterMetadata(); meta.setString(ImporterMetadata.DOC_CONTENT_TYPE, "text/html"); t.tagDocument("n/a", is, meta, false); is.close();/* w ww . jav a 2s . com*/ Assert.assertEquals(616, meta.getInt("document.stat.characterCount")); Assert.assertEquals(115, meta.getInt("document.stat.wordCount")); Assert.assertEquals(8, meta.getInt("document.stat.sentenceCount")); Assert.assertEquals(4, meta.getInt("document.stat.paragraphCount")); Assert.assertEquals("4.2", meta.getString("document.stat.averageWordCharacterCount")); Assert.assertEquals("77.0", meta.getString("document.stat.averageSentenceCharacterCount")); Assert.assertEquals("14.4", meta.getString("document.stat.averageSentenceWordCount")); Assert.assertEquals("154.0", meta.getString("document.stat.averageParagraphCharacterCount")); Assert.assertEquals("2.0", meta.getString("document.stat.averageParagraphSentenceCount")); Assert.assertEquals("28.8", meta.getString("document.stat.averageParagraphWordCount")); }
From source file:it.govpay.core.utils.client.SOAPUtils.java
public static JAXBElement<?> toJaxb(byte[] msg, Schema schema) throws JAXBException, SAXException, IOException, XMLStreamException { String s = new String(msg); InputStream is = IOUtils.toInputStream(s); return (JAXBElement<?>) unmarshal(is, schema); }
From source file:org.energyos.espi.common.domain.BatchListUnmarshallerTest.java
@Before public void before() throws JAXBException, FeedException { batchList = (BatchList) marshaller// w ww. jav a2 s . c om .unmarshal(new StreamSource(new InputStreamReader(IOUtils.toInputStream(XML_INPUT)))); }
From source file:com.github.restdriver.clientdriver.unit.HttpRealRequestTest.java
@Test public void instantiationWithHttpRequestPopulatesCorrectly() throws IOException { HttpServletRequest mockRequest = mock(HttpServletRequest.class); String expectedPathInfo = "someUrlPath"; String expectedMethod = "GET"; Enumeration<String> expectedHeaderNames = Collections.enumeration(Arrays.asList("header1")); String bodyContent = "bodyContent"; String expectedContentType = "contentType"; when(mockRequest.getPathInfo()).thenReturn(expectedPathInfo); when(mockRequest.getMethod()).thenReturn(expectedMethod); when(mockRequest.getQueryString()).thenReturn("hello=world"); when(mockRequest.getHeaderNames()).thenReturn(expectedHeaderNames); when(mockRequest.getHeader("header1")).thenReturn("thisIsHeader1"); when(mockRequest.getInputStream())//from www . j a v a2 s. co m .thenReturn(new DummyServletInputStream(IOUtils.toInputStream(bodyContent))); when(mockRequest.getContentType()).thenReturn(expectedContentType); RealRequest realRequest = new HttpRealRequest(mockRequest); assertThat((String) realRequest.getPath(), is(expectedPathInfo)); assertThat(realRequest.getMethod(), is(Method.GET)); assertThat(realRequest.getParams().size(), is(1)); assertThat((String) realRequest.getParams().get("hello").iterator().next(), is("world")); assertThat((String) realRequest.getHeaders().get("header1"), is("thisIsHeader1")); assertThat((String) realRequest.getBodyContentType(), is(expectedContentType)); }
From source file:com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptorParserTest.java
@Test public void shouldValidatePluginVersion() throws Exception { InputStream pluginXml = IOUtils.toInputStream("<go-plugin version=\"10\"></go-plugin>"); try {//w w w .ja v a2 s . co m GoPluginDescriptorParser.parseXML(pluginXml, "/tmp/", new File("/tmp/"), true); fail("xsd validation should have failed"); } catch (SAXException e) { assertThat(e.getMessage(), is("XML Schema validation of Plugin Descriptor(plugin.xml) failed")); assertThat(e.getCause().getMessage(), contains("Value '10' of attribute 'version' of element 'go-plugin' is not valid")); } }
From source file:com.collective.celos.ci.testing.fixtures.convert.FixTableToJsonFileConverterTest.java
@Test public void testFixTableToJsonFileConverter() throws Exception { FixTableToJsonFileConverter converter = new FixTableToJsonFileConverter(); List<FixTable.FixRow> fixRows = Lists.newArrayList(); Map<String, String> map = Maps.newHashMap(); map.put("col1", "val1"); map.put("col2", "val2"); Map<String, String> map2 = Maps.newHashMap(); map2.put("col1", "val11"); map2.put("col2", "val22"); FixTable.FixRow row1 = new FixTable.FixRow(map); FixTable.FixRow row2 = new FixTable.FixRow(map2); fixRows.add(row1);/* w w w.j a va2s. com*/ fixRows.add(row2); FixTable fixTable = new FixTable(Lists.newArrayList("col1", "col2"), fixRows); FixFile fixFile = converter.convert(null, fixTable); String tableStr = IOUtils.toString(fixFile.getContent()); String expectedStr = "{\"col1\":\"val1\",\"col2\":\"val2\"}\n" + "{\"col1\":\"val11\",\"col2\":\"val22\"}"; Map<JsonElement, Integer> expected = Utils.fillMapWithJsonFromIS(IOUtils.toInputStream(expectedStr)); Map<JsonElement, Integer> result = Utils.fillMapWithJsonFromIS(IOUtils.toInputStream(tableStr)); Assert.assertEquals(expected, result); }