use of java.io.ByteArrayInputStream in project camel by apache.
the class LogInputStreamTest method testD.
public void testD() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:d");
mock.expectedMessageCount(1);
mock.expectedBodiesReceived("Hello World");
InputStream is = new ByteArrayInputStream("Hello World".getBytes());
template.sendBody("direct:d", is);
assertMockEndpointsSatisfied();
}
use of java.io.ByteArrayInputStream in project camel by apache.
the class ByteArrayInputStreamCacheTest method testByteArrayInputStream.
public void testByteArrayInputStream() throws Exception {
ByteArrayInputStreamCache cache = new ByteArrayInputStreamCache(new ByteArrayInputStream("<foo>bar</foo>".getBytes()));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
cache.writeTo(bos);
String s = context.getTypeConverter().convertTo(String.class, bos);
assertEquals("<foo>bar</foo>", s);
IOHelper.close(cache, bos);
}
use of java.io.ByteArrayInputStream in project camel by apache.
the class StaxConverterTest method testToInputSreamByXmlStreamReader.
public void testToInputSreamByXmlStreamReader() throws Exception {
StringReader src = new StringReader(TEST_XML_7000);
XMLStreamReader xreader = null;
InputStream in = null;
try {
xreader = context.getTypeConverter().mandatoryConvertTo(XMLStreamReader.class, src);
in = context.getTypeConverter().mandatoryConvertTo(InputStream.class, xreader);
// verify
InputStream expected = new ByteArrayInputStream(TEST_XML_7000.getBytes("utf-8"));
byte[] tmp1 = new byte[512];
byte[] tmp2 = new byte[512];
for (; ; ) {
int n1 = 0;
int n2 = 0;
try {
n1 = expected.read(tmp1, 0, tmp1.length);
n2 = in.read(tmp2, 0, tmp2.length);
} catch (IOException e) {
fail("unable to read data");
}
assertEquals(n1, n2);
if (n2 < 0) {
break;
}
assertTrue(Arrays.equals(tmp1, tmp2));
}
} finally {
if (xreader != null) {
xreader.close();
}
if (in != null) {
in.close();
}
}
}
use of java.io.ByteArrayInputStream in project camel by apache.
the class IOConverterTest method testInputStreamToString.
public void testInputStreamToString() throws Exception {
String data = "46°37'00\"N\"";
ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes("UTF-8"));
Exchange exchange = new DefaultExchange(context);
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
String result = IOConverter.toString(is, exchange);
assertEquals("Get a wrong result", data, result);
}
use of java.io.ByteArrayInputStream in project camel by apache.
the class MultiCastParallelAndStreamCachingTest method testReaderCache.
/**
* Tests the ReaderCache.
*
* The sent InputStreamReader is transformed to a ReaderCache before the
* multi-cast processor is called.
*
* @throws Exception
*/
public void testReaderCache() throws Exception {
// sharp-s
String abcScharpS = "ABCß";
MockEndpoint mock = getMockEndpoint("mock:resulta");
mock.expectedBodiesReceived(abcScharpS);
mock = getMockEndpoint("mock:resultb");
mock.expectedBodiesReceived(abcScharpS);
InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(abcScharpS.getBytes("ISO-8859-1")), "ISO-8859-1");
template.sendBody("direct:start", isr);
assertMockEndpointsSatisfied();
}
Aggregations