Reputation: 1092
I am splitting a file into lines using a tokenizer:
.split().tokenize("\n", 1)
However, some of the files I need to process will contain a header line, which will need to be processed differently to the normal lines. Is there an easy way to read the first line, process that, then split the remaining lines?
Upvotes: 13
Views: 7796
Reputation: 22279
You can do something like this. It will use a content based router EIP, then different sub routes for processing.
from(A)
.split().tokenize("\n",1)
.choice()
.when(simple("${property.CamelSplitIndex} > 0"))
.to("direct:processLine")
.otherwise()
.to("direct:processHeader");
from("direct:processLine")
.bean(processLineBean)
.to(B);
from("direct:processHeader")
.bean(processHeaderBean)
.to(B);
Upvotes: 24