|
Stream has been edited by Claus Ibsen (Jan 15, 2009). Content:Stream ComponentThe stream: component provides access to the System.in, System.out and System.err streams together with allowing streaming of output to a file. URI formatstream:in stream:out stream:err stream:file?file=/foo/bar.txt (@deprecated) stream:url (@deprecated) stream:header
Message contentThe stream: component supports either String or byte[] for writing to streams. Just add to the message.in.body either a Stirng or byte[] content. SamplesIn this sample we output to System.out the content from the message when its put on the direct:in queue. public void testStringContent() throws Exception { template.sendBody("direct:in", "Hello Text World\n"); } public void testBinaryContent() { template.sendBody("direct:in", "Hello Bytes World\n".getBytes()); } protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from("direct:in").to("stream:out"); } }; } This sample demonstrates how the header type can be used to determine which stream to use. In the sample we use our own output stream (MyOutputStream). private OutputStream mystream = new MyOutputStream(); private StringBuffer sb = new StringBuffer(); public void testStringContent() { template.sendBody("direct:in", "Hello"); // StreamProducer appends \n in text mode assertEquals("Hello\n", sb.toString()); } public void testBinaryContent() { template.sendBody("direct:in", "Hello".getBytes()); // StreamProducer is in binary mode so no \n is appended assertEquals("Hello", sb.toString()); } protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from("direct:in").setHeader("stream", constant(mystream)). to("stream:header"); } }; } private class MyOutputStream extends OutputStream { public void write(int b) throws IOException { sb.append((char)b); } } See Also |
Unsubscribe or edit your notifications preferences
