簡體   English   中英

使用Apache Camel解壓縮文件?

[英]Unzip files with Apache Camel?

如何使用Apache Camel從zip文件中提取文件(一個或多個)? 可能嗎?

我正在嘗試這個

from("file:/home/myinputzip?noop=true&delay=5000&moveFailed=error")
  .split(new ZipSplitter())
    .streaming().convertBodyTo(String.class)      
  .to("file:/home/myinputzip")
.end();

當我啟動應用程序時,文件是從zip中提取的,但是camel會拋出異常並將文件移動到錯誤文件夾:

錯誤:org.apache.camel.processor.DefaultErrorHandler - (ExchangeId上的MessageId:ID-ubuntu-35217-1377806407437-0-5:ID-ubuntu-35217-1377806407437-0-7)的傳遞失敗。 交付嘗試后用盡:1捕獲:org.apache.camel.component.file.GenericFileOperationFailedException:無法將null body寫入文件:/home/myinputzip/aVIII_crrpfp201304.cap org.apache.camel.component.file.GenericFileOperationFailedException:無法寫入null body to file:/home/myinputzip/aVIII_crrpfp201304.cap org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:194)at org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer。 java:257)org.apache上的org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:159)org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:80)位於org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)的.camel.util.AsyncProcessorConverterHelper $ ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)org.apache.camel.processor.SendProcessor $ 2.doInAsyncProducer( SendProcessor.java: 122)org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)

誰能幫我?

我解決了如下問題

from("file:/home/myinputzip?noop=true&delay=5000&moveFailed=error")
  .split(new ZipSplitter())
    .streaming().convertBodyTo(String.class) 
        .choice()
            .when(body().isNotNull())
                .to("file:/home/myinputzip")
        .end()
.end();

我同意你的路線應該有效,但是,你嘗試過這樣的事情:

from("file:/home/myinputzip?noop=true&delay=5000&moveFailed=error")
  .unmarshal().zip()
  .split(body(Iterable.class))
    .streaming().convertBodyTo(String.class)      
  .to("file:/home/myinputzip")
.end();

我從http://camel.465427.n5.nabble.com/zip-file-best-practices-td5713437.html獲取此示例

我希望這對你有用!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM