处理大型pgp文件时的java.lang.OutOfMemoryError

时间:2013-12-20 00:29:40

标签: apache-camel pgp

我想使用Camel 2.12.1来解密一些可能很大的pgp文件。以下流程导致内存不足异常,并且调用堆栈显示PGPDataFormat.unmarshal()函数正在尝试构建一个ByteArray,如果文件很大,它将失败。有没有办法在解组时传递流?

我的路线:

from("file:///home/cps/camel/sftp-in?"
        + "include=.*&"  // find files using this pattern
        + "move=/home/cps/camel/sftp-archive&"  // after done adding records to queue, move file to archive
        + "delay=5000&"
        + "readLock=rename&" // readLock parameters prevent picking up file which is currently changing
        + "readLockCheckInterval=5000")
        .choice()
        .when(header(Exchange.FILE_NAME_ONLY).regex(".*pgp$|.*PGP$|.*gpg$|.*GPG$")).to("direct:decrypt")
        .otherwise()
        .to("file:///home/cps/camel/input");

from("direct:decrypt").unmarshal().pgp("file:///home/cps/.gnupg/secring.gpg", "developer", "set42now")
        .setHeader(Exchange.FILE_NAME).groovy("request.headers.get('CamelFileNameOnly').replace('.gpg', '')")
        .to("file:///home/cps/camel/input/")
        .to("log:done");

显示转换器尝试创建ByteArray的异常:

java.lang.OutOfMemoryError: Java heap space
    at org.apache.commons.io.output.ByteArrayOutputStream.needNewBuffer(ByteArrayOutputStream.java:128)
    at org.apache.commons.io.output.ByteArrayOutputStream.write(ByteArrayOutputStream.java:158)
    at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1026)
    at org.apache.commons.io.IOUtils.copy(IOUtils.java:999)
    at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:218)
    at org.apache.camel.converter.crypto.PGPDataFormat.unmarshal(PGPDataFormat.java:238)
    at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:65)

1 个答案:

答案 0 :(得分:0)

尝试2.13或2.12-SNAPSHOT,因为我们最近改进了数据格式和流媒体。在下一个版本中可能会更好。