I'm being given a file containing numeric IDs that are delimited by newlines ("\n
"):
123948
939904
129384
234049
etc. I want to use Camel to transform the file into an instance of the following POJO:
public class IDFile {
private String fileName; // The name of the file
private List<Long> ids; // All the IDs in the file (123948, 939904, etc.)
// Constructor, getters/setters, etc.
}
I'm trying to see if I can use Camel's Splitter component to do this form me, but it feels like I'm trying to force a round peg into a square hole:
<route>
<from uri="file://input/idfile"/>
<split streaming="true">
<tokenize token="\n" />
<to uri="bean://idfileProcessor?method=process"/>
</split>
</route>
The above looks like it would split my file into a List<Long>
, but I need the file name associated with the list as well. Any ideas?
There is a header "CamelFileName" on the exchange. Your processor/bean is passed a reference to the exchange and you can get the header from there and associate it with the token you have been invoked with.
Your route could look like this:
The bean you are using to maintain the state on the exchange object:
A file containing the rows
fed to the route under the names splitter.text and splitter_2.txt yields the following log output:
HTH