camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: CAMEL-7337 Make sure PGPDataFormat unmarshal close the streams correctly with thanks to Franz
Date Wed, 02 Apr 2014 11:03:29 GMT
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/efc51be2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/efc51be2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/efc51be2

Branch: refs/heads/camel-2.13.x
Commit: efc51be2e45041009511032f7ea4e60ed200a772
Parents: 21e3688
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Apr 2 18:58:01 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Apr 2 18:58:48 2014 +0800

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


http://git-wip-us.apache.org/repos/asf/camel/blob/efc51be2/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 {


Mime
View raw message