alright, try this...convert to InputStream, then to byte[], then aggregate
(as ArrayList<bytep[]>), then to your processor...

from("file:/tmp/inbox")
        .convertBodyTo(InputStream.class)
        .process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                        InputStream is = 
exchange.getIn().getBody(InputStream.class);

                        ByteArrayOutputStream buffer = new 
ByteArrayOutputStream();
                        int nRead;
                        byte[] data = new byte[16384];
                        while ((nRead = is.read(data, 0, data.length)) != -1) {
                          buffer.write(data, 0, nRead);
                        }
                        buffer.flush();
                        is.close();

                        byte[] bytes = buffer.toByteArray();
                        exchange.getIn().setBody(bytes);
                }
        })
        .aggregate(constant(true), new
ListAggregatingStrategy()).completionInterval(1000)
        .process(new Processor() {
                public void process(Exchange exchange) throws Exception {
                        ArrayList list = 
exchange.getIn().getBody(ArrayList.class);
                        System.out.println("list->" + list.size());
                }
        });
        
class ListAggregatingStrategy implements AggregationStrategy {
    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {

                Object newBody = newExchange.getIn().getBody();
                ArrayList list;
        if (oldExchange == null) {
                        list = new ArrayList();
                        list.add(newBody);
                        newExchange.getIn().setBody(list);
                        return newExchange;
        } else {
                list = oldExchange.getIn().getBody(ArrayList.class);
                        list.add(newBody);
                        return oldExchange;
                }
    }
}


-----
Ben O'Day
IT Consultant -http://consulting-notes.com

--
View this message in context: 
http://camel.465427.n5.nabble.com/read-all-files-in-folder-tp4474104p4477520.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to