Hello,

I wrote a custom processor for zipping (partly because I needed to
archive more messages in one archive):

It uses Guava 13 for some operations:

 public static class ZipProcessor implements Processor {

        @Override
        public void process(Exchange exchange) throws Exception {
            List<Exchange> exchanges =
exchange.getProperty(Exchange.GROUPED_EXCHANGE, List.class);
            final ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ZipOutputStream zos = new ZipOutputStream(bos);
            try {
                for (Exchange local : exchanges) {
                    LOG.info("Adding {} to zip archive",
local.getIn().getHeader(Exchange.FILE_NAME));
                    zos.putNextEntry(new
ZipEntry(local.getIn().getHeader(Exchange.FILE_NAME, String.class)));

ByteStreams.copy(local.getIn().getBody(InputStream.class), zos);
                    zos.closeEntry();
                }
            } finally {
                Closeables.closeQuietly(zos);
                exchange.setProperty(Exchange.GROUPED_EXCHANGE, null);
                exchange.getIn().setHeader(Exchange.FILE_NAME, "invoice.zip");
                exchange.getIn().setBody(bos.toByteArray(), byte[].class);
            }
        }
    }

Reply via email to