I would try using the Camel EIP Splitter

http://camel.apache.org/splitter.html


*Chris Odom | Sr Consultant | Media Driver*
512.799.0270 | chris.o...@mediadriver.com
810 Hester's Crossing, Suite 165, Round Rock, TX 78681

On Mon, Sep 5, 2016 at 10:18 AM, Louisa <lesgen...@hotmail.fr> wrote:

> Hello evereybody,
>
> I use Java Camel to my project (Talend).
> I need your help for a method to solve this problem. I have this file:
>
>     D0000000000000000000
>     EEASTDE
>     ELASPDF
>     ELASQML
>     EEASTDE
>     ELASPDF
>     ELASQHG
>     F00000006
>
> How I can cut in java this way (in 2 file) ?
>
>     EEASTDE
>     ELASPDF
>     ELASQML
>
> And:
>
>     EEASTDE
>     ELASPDF
>     ELASQHG
>
>
> I have to cut the file according to the head EEASTDE. It's an example, I
> could have several times the header EEASTDE (3, 4, 5...).
> I thought of the HashMap, the arraylist but I don't know how to make the
> code because I'm not indicate the line EEASTDE as a unique key.
>
> Here is my test code but it doesn't work:
>
>
>     public class bean_test implements Processor{
>
>
>         private static final String MDS_ENDPOINT_NAME = "MDSEndpoint";
>         private static final String EEASTD_HEADER = "EEASTDE";
>         private static final int EEASTD_HEADER_START_POSITION = 0;
>         private static final int EEASTD_HEADER_END_POSITION = 7;
>         private static final String START_OF_FILE_TAG = "D";
>         private static final String END_OF_FILE_TAG = "F";
>
>         @Override
>         public void process(Exchange exchange) throws Exception {
>
>                 ProducerTemplate producerTemplate =
> exchange.getContext().createProducerTemplate();
>                 String MDSEndpoint = exchange.getIn().getHeader(
> MDS_ENDPOINT_NAME,
> String.class);
>                 InputStream is = new
> ByteArrayInputStream(exchange.getIn().getBody(String.class).getBytes());
>                 extractFromMDS(producerTemplate, is, MDSEndpoint, new
> HashMap<String,
> Object>(exchange.getIn().getHeaders()));
>
>         }
>
>         private void extractFromMDS(ProducerTemplate producerTemplate,
> InputStream
> content, String MDSEndpoint, Map<String, Object> headers){
>                 BufferedReader br = new BufferedReader(new
> InputStreamReader(content));
>                 String line;
>                 try {
>                         while((line = br.readLine()) != null){
>                                 if(!line.startsWith(START_OF_FILE_TAG) &&
> !line.startsWith(END_OF_FILE_TAG)){
>                                         StringBuilder stringBuilder = null;
>                                         if(line.substring(EEASTD_
> HEADER_START_POSITION,
> EEASTD_HEADER_END_POSITION).equals(EEASTD_HEADER)){
>                                                 stringBuilder = new
> StringBuilder();
>                                                 stringBuilder.append("\n"+(
> line));
>
>                                         }
>                                 producerTemplate.sendBodyAndHeaders(
> MDSEndpoint,
> stringBuilder.toString(), headers);
>                         }
>                 }
>                 } catch (IOException e) {
>                         e.printStackTrace();
>                 }
>                 finally{
>                         try {
>                                 if(br != null)br.close();
>                         } catch (IOException e) {
>                                 e.printStackTrace();
>                         }
>                 }
>         }
>     }
>
> Have you an idea ?
>
> Thank you in advance.
>
> Natacha.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Cut-a-file-into-multiple-files-tp5787210.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Reply via email to