Repository: camel
Updated Branches:
  refs/heads/camel-2.13.x 21e3688a0 -> efc51be2e
  refs/heads/master b2104c38e -> dfaa44c45


CAMEL-7337 Make sure PGPDataFormat unmarshal close the streams correctly with 
thanks to Franz


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/dfaa44c4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dfaa44c4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dfaa44c4

Branch: refs/heads/master
Commit: dfaa44c4579535f26461f4a02a1dd97ea29ac737
Parents: b2104c3
Author: Willem Jiang <[email protected]>
Authored: Wed Apr 2 18:58:01 2014 +0800
Committer: Willem Jiang <[email protected]>
Committed: Wed Apr 2 18:58:01 2014 +0800

----------------------------------------------------------------------
 .../crypto/PGPKeyAccessDataFormat.java          | 84 +++++++++++---------
 1 file changed, 45 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dfaa44c4/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPKeyAccessDataFormat.java
----------------------------------------------------------------------
diff --git 
a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPKeyAccessDataFormat.java
 
b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPKeyAccessDataFormat.java
index db05c1c..1ca517a 100644
--- 
a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPKeyAccessDataFormat.java
+++ 
b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPKeyAccessDataFormat.java
@@ -347,48 +347,54 @@ public class PGPKeyAccessDataFormat extends 
ServiceSupport implements DataFormat
         if (encryptedStream == null) {
             return null;
         }
-        InputStream in = PGPUtil.getDecoderStream(encryptedStream);
-        InputStream encData = getDecryptedData(exchange, in);
-        InputStream uncompressedData = getUncompressedData(encData);
-        PGPObjectFactory pgpFactory = new PGPObjectFactory(uncompressedData);
-        Object object = pgpFactory.nextObject();
-
-        PGPOnePassSignature signature;
-        if (object instanceof PGPOnePassSignatureList) {
-            signature = getSignature(exchange, (PGPOnePassSignatureList) 
object);
-            object = pgpFactory.nextObject();
-        } else {
-            // no signature contained in PGP message
-            signature = null;
-            if 
(SIGNATURE_VERIFICATION_OPTION_REQUIRED.equals(getSignatureVerificationOption()))
 {
-                throw new PGPException(
-                        "PGP message does not contain any signatures although 
a signature is expected. Either send a PGP message with signature or change the 
configuration of the PGP decryptor.");
-            }
-        }
+        InputStream in = null;
+        InputStream encData = null;
+        InputStream uncompressedData = null;
+        InputStream litData = null;
 
-        PGPLiteralData ld;
-        if (object instanceof PGPLiteralData) {
-            ld = (PGPLiteralData) object;
-        } else {
-            throw getFormatException();
-        }
-        InputStream litData = ld.getInputStream();
-
-        // enable streaming via OutputStreamCache
         CachedOutputStream cos;
         ByteArrayOutputStream bos;
-        OutputStream os;
-        if (exchange.getContext().getStreamCachingStrategy().isEnabled()) {
-            cos = new CachedOutputStream(exchange);
-            bos = null;
-            os = cos;
-        } else {
-            cos = null;
-            bos = new ByteArrayOutputStream();
-            os = bos;
-        }
+        OutputStream os = null;
 
         try {
+            in = PGPUtil.getDecoderStream(encryptedStream);
+            encData = getDecryptedData(exchange, in);
+            uncompressedData = getUncompressedData(encData);
+            PGPObjectFactory pgpFactory = new 
PGPObjectFactory(uncompressedData);
+            Object object = pgpFactory.nextObject();
+
+            PGPOnePassSignature signature;
+            if (object instanceof PGPOnePassSignatureList) {
+                signature = getSignature(exchange, (PGPOnePassSignatureList) 
object);
+                object = pgpFactory.nextObject();
+            } else {
+                // no signature contained in PGP message
+                signature = null;
+                if 
(SIGNATURE_VERIFICATION_OPTION_REQUIRED.equals(getSignatureVerificationOption()))
 {
+                    throw new PGPException(
+                            "PGP message does not contain any signatures 
although a signature is expected. Either send a PGP message with signature or 
change the configuration of the PGP decryptor.");
+                }
+            }
+
+            PGPLiteralData ld;
+            if (object instanceof PGPLiteralData) {
+                ld = (PGPLiteralData) object;
+            } else {
+                throw getFormatException();
+            }
+            litData = ld.getInputStream();
+
+            // enable streaming via OutputStreamCache
+            if (exchange.getContext().getStreamCachingStrategy().isEnabled()) {
+                cos = new CachedOutputStream(exchange);
+                bos = null;
+                os = cos;
+            } else {
+                cos = null;
+                bos = new ByteArrayOutputStream();
+                os = bos;
+            }
+
             byte[] buffer = new byte[BUFFER_SIZE];
             int bytesRead;
             while ((bytesRead = litData.read(buffer)) != -1) {
@@ -400,9 +406,9 @@ public class PGPKeyAccessDataFormat extends ServiceSupport 
implements DataFormat
             }
             verifySignature(pgpFactory, signature);
         } finally {
-            IOHelper.close(os, litData, encData, in);
+            IOHelper.close(os, litData, uncompressedData, encData, in, 
encryptedStream);
         }
-      
+
         if (cos != null) {
             return cos.newStreamCache();
         } else {

Reply via email to