camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1382416 - /camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
Date Sun, 09 Sep 2012 07:41:06 GMT
Author: davsclaus
Date: Sun Sep  9 07:41:05 2012
New Revision: 1382416

URL: http://svn.apache.org/viewvc?rev=1382416&view=rev
Log:
CAMEL-5583: PGP data format should close streams to avoid issues on windwos when reading from
files. Thanks to Daniel Gredler for the patch.

Modified:
    camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java

Modified: camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java?rev=1382416&r1=1382415&r2=1382416&view=diff
==============================================================================
--- camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
(original)
+++ camel/trunk/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
Sun Sep  9 07:41:05 2012
@@ -66,10 +66,15 @@ public class PGPDataFormat implements Da
             throw new IllegalArgumentException("Public key is null, cannot proceed");
         }
 
-        InputStream plaintextStream = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class,
graph);
-
-        byte[] compressedData = PGPDataFormatUtil.compress(IOUtils.toByteArray(plaintextStream),
-                PGPLiteralData.CONSOLE, CompressionAlgorithmTags.ZIP);
+        byte[] plaintextData;
+        InputStream plaintextStream = null;
+        try {
+            plaintextStream = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class,
graph);
+            plaintextData = IOUtils.toByteArray(plaintextStream);
+        } finally {
+            IOUtils.closeQuietly(plaintextStream);
+        }
+        byte[] compressedData = PGPDataFormatUtil.compress(plaintextData, PGPLiteralData.CONSOLE,
CompressionAlgorithmTags.ZIP);
 
         if (armored) {
             outputStream = new ArmoredOutputStream(outputStream);
@@ -96,8 +101,14 @@ public class PGPDataFormat implements Da
             throw new IllegalArgumentException("Private key is null, cannot proceed");
         }
 
-        InputStream in = new ByteArrayInputStream(IOUtils.toByteArray(encryptedStream));
-        in = PGPUtil.getDecoderStream(in);
+        InputStream in;
+        try {
+            byte[] encryptedData = IOUtils.toByteArray(encryptedStream);
+            InputStream byteStream = new ByteArrayInputStream(encryptedData);
+            in = PGPUtil.getDecoderStream(byteStream);
+        } finally {
+            IOUtils.closeQuietly(encryptedStream);
+        }
 
         PGPObjectFactory pgpF = new PGPObjectFactory(in);
         PGPEncryptedDataList enc;



Mime
View raw message