Camel ZipSplitter - 如何获取解压缩文件的文件内容?

时间:2017-05-02 11:16:44

标签: java apache-camel camel-zipfile

我在上传到S3之前计算每个文件的MD5。当我使用ZipSplitter时,我想分别计算每个解压缩文件的MD5。 Exchange.getIn()提供整个zip文件,而不是单个解压缩文件。

from(source).choice().when(isZipFile)
                .split(new ZipSplitter())
                .streaming()
                .process(md5HeadersProcessor)
                .process(camelS3HeadersProcessor)
                .to(destination)
                .log("Uploading file ${file:name} completed...")
                .end()
                .endChoice()

MD5HeadersProcessor:

@Override
public void process(Exchange exchange) throws NoSuchAlgorithmException {
    byte[] bytes = exchange.getIn().getBody(byte[].class);
    exchange.getIn().setHeader(S3Constants.CONTENT_MD5, getMD5(bytes));
}

CamelS3HeadersProcessor:

@Override
public void process(Exchange exchange) throws Exception {
    SimpleBuilder simpleBuilder = new SimpleBuilder("${file:onlyname}");
    String fileName = simpleBuilder.evaluate(exchange, String.class);
     exchange.getIn().setHeader(S3Constants.KEY, fileName);
}

我可以在CamelS3HeadersProcessor中设置解压缩的fileName。如何在MD5HeadersProcessor中获取解压缩文件的内容?

1 个答案:

答案 0 :(得分:0)

我将其从ZipSplitter更改为ZipFileDataFormat& Iterator

ZipFileDataFormat zf = new ZipFileDataFormat();
zf.setUsingIterator(true);

from(source).choice().when(isZipFile)
            .unmarshal(zf)
            .split(bodyAs(Iterator.class))
            .streaming()
            .convertBodyTo(String.class)
            .process(md5HeadersProcessor)
            .process(camelS3HeadersProcessor)
            .to(destination)
            .log("Uploading file ${file:name} completed...")
            .end()
            .endChoice()