camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1382417 - in /camel/branches/camel-2.10.x: ./ components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
Date Sun, 09 Sep 2012 07:42:26 GMT
Author: davsclaus
Date: Sun Sep  9 07:42:25 2012
New Revision: 1382417

URL: http://svn.apache.org/viewvc?rev=1382417&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/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1382416

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java?rev=1382417&r1=1382416&r2=1382417&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/PGPDataFormat.java
Sun Sep  9 07:42:25 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