camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brad Johnson <brad.john...@mediadriver.com>
Subject Re: Cut a file into multiple files
Date Tue, 06 Sep 2016 22:26:17 GMT
I'd definitely look at Beanio and the Camel bundle/library for it.  It's
relatively easy to create identifiers in that way and segregate those out
as beans.  So every bean class might have a header (or not since it seems
static and throwaway) and then 0...M lines that could be mapped into the
bean.  Then you end up with a bean for every set of records that you can
route and write out.  You could then use a file endpoint in the route
instead of trying to write them out yourself. That also means that handlers
and validators down the line do not have to be Processors requiring the
handling of a raw exchange but can be beans themselves that just have a
method that takes your bean like as follows.  Then you can also unit test
the individual handlers/validators or whatever you want to call them
independent of any Camel libraries or routes.

public class BeanHandler {

public void invoke(MyBeanModel model)
{
//some logic.  You have even return the model or a different one.
}

}

On Mon, Sep 5, 2016 at 4:54 PM, Chris Odom <chris.odom@mediadriver.com>
wrote:

> I would try using the Camel EIP Splitter
>
> http://camel.apache.org/splitter.html
>
>
> *Chris Odom | Sr Consultant | Media Driver*
> 512.799.0270 | chris.odom@mediadriver.com
> 810 Hester's Crossing, Suite 165, Round Rock, TX 78681
>
> On Mon, Sep 5, 2016 at 10:18 AM, Louisa <Lesgens59@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.
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message