Camel: How to skip multiple header lines in CSV files

人盡茶涼 提交于 2019-12-13 07:29:28

问题


I'm going to process CSV files using Apache Camel. My files have multiple header lines. In Camel I only find skipFirstLine or skipHeaderRecord (which is not clear for me) but how to skip more than one line?


回答1:


If the number of lines to skip is fixed, then you can use the simple language to skip X number. You likely need to covert the message to a String first,

  .convertBodyTo(String.class)
  .transform(simple("${skip(3)}")

See more about skip method at: http://camel.apache.org/simple

This requires Camel 2.19 onwards.

Using older releases you would need to build some custom code yourself to skip the lines.




回答2:


You can use tokenize method on your body before processing the body.

tokenize(String token, int group, boolean skipFirst)

Example:

`from("filePath").
    split(body().tokenize("\n",1,true)).
    streaming().
    process(exchange -> {....}).
to("filePath");`


来源:https://stackoverflow.com/questions/43520162/camel-how-to-skip-multiple-header-lines-in-csv-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!