That could work for sure.

But would an alternative solution be to read the body and store the records
in a multimap structure (google guava's multimap).

For instance:

Split by new line
   Extract the first column separated by a comma
   Search in multimap if the key exist
       if key exist save the line as a value to that key
       if key is not found create a new entry with the column as key and
line as value

I guess it depends on how big the structure will grow. But yeah, could work
as an alternative.

Best
Souciance

On Wed, Apr 26, 2017 at 11:41 PM, Gary [via Camel] <
[email protected]> wrote:

> I'm thinking about something like this, first get the tokens from the
> message body, then split them based on this list of tokens. psuedo code:
> using beans in the route for split.
> what do you think on this, was hoping for a cleaner approach. thanks!
>
> public class AssetSplitterBean {
>
>             public List<String> splitBody(String body, Exchange exchange)
> {
>
>                 List<String> serviceRecords = new ArrayList<String>();
>
>                 List<String> tokens = 
> (List<String>)exchange.getProperty("splitTokens");
>
>                 for ( String token : tokens ){
>                 String[] records = body.split(token);
>                 for (String record : records) {
>                             serviceRecords.add(record);
>                         }
>                 }
>                 return serviceRecords;
>             }
>
>     public Object initSplitTokens(Exchange exchange) {
>     exchange.setProperty("splitTokens", new ArrayList<String>());
>         return exchange.getIn().getBody();
>     }
>
>     public Object addToken(Exchange exchange) {
>
>     String payload = exchange.getIn().getBody(String.class);
>
>     Scanner sc = new Scanner(payload).useDelimiter("\r\n|\n");
>                 while(sc.hasNextLine()){
>                         String line = sc.nextLine();
>                         String[] aa = line.split(",");
>                         List<String> tokens = 
> (List<String>)exchange.getProperty("splitTokens");
>
>                         if ( !tokens.contains(aa[0]) ){
>                                 ((List<String>)exchange.
> getProperty("splitTokens")).add(aa[0]);
>                         }
>                 } sc.close();
>
>         return null;
>     }
>
> }
> Gary Lee Mills
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://camel.465427.n5.nabble.com/camel-splitter-tp5798339p5798365.html
> To start a new topic under Camel - Users, email ml+s465427n465428h31@n5.
> nabble.com
> To unsubscribe from Camel - Users, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: 
http://camel.465427.n5.nabble.com/camel-splitter-tp5798339p5798366.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to