In Section 8.1.3-"Splitting big messages", it briefly discusses using streaming with the splitter in context of the tokenizer, which only processes strings. It states that tokenizer uses java.util.Scanner to read chunks of data into memory. So the Scanner reads a "stream" of data, based on a token. The Scanner object is then passed back to Camel as an Expression, which Camel then uses to iterate over and deliver as parts. Is this correct?
I am in need of a similar implementation but for binary streams. Instead of getting the message body, i.e. splitBody(@Body byte body), I need to get the Exchange, i.e. splitBody(Exchange exchange). From the Exchange I could get the file and perform custom streaming to then create my Iterator. Does this sound feasible. How do I get the Exchange passed to the custom split method?
Do you know of any implementations such as this? Or would you recommend another approach of reading large binary files? Does the Stream component (ex. ) provide any value here to be able to stream the file that I then can read as streaming input?
If you use a custom Iterator to read the file piece by piece then that works well with the streaming mode of the Camel Splitter EIP.
This is similar to as how the Scanner works. If you just want to split your file by a special token etc then the Scanner is a great choice. And Camel DSL have syntax sugar for this using the tokenizer.
If you need something more advanced/custom, then just use a custom Iterator. For example you can read in X number of bytes at each iteration step.
Would you be able to provide the sample code on this example?
On the following page: http://camel.apache.org/splitter.html , there is an excerpt that I have questions about.
++ Excerpt - Start ++
import static org.apache.camel.builder.ExpressionBuilder.beanExpression;
.split(beanExpression(new MyCustomIteratorFactory(), "iterator"))
++ Excerpt - End ++
Can someone provided me with same code for the MyCustomIteratorFactory class?
Basically I have one huge file, that I want to split into many jms messages.
The following is an outline of my current thoughts...
public void configure() throws Exception
from( "file://file-item-list/general?initialDelay=1000&delay=5000&delete=true" )
.transacted( "PROPAGATION_REQUIRED" )
.split(ExpressionBuilder.beanExpression(new MyCustomFileChunkIterator(), "iterator")) // split big file of items into smaller chunks
Edited by: marks1900 on Dec 16, 2011 7:18 AM