Updated Branches:
  refs/heads/camel-2.10.x 9d31ac48c -> db91e7c9f

Polished the marshal method to instantiate the CipherOutputStream object
only in case plaintextStream is not null.


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

Branch: refs/heads/camel-2.10.x
Commit: db91e7c9f18b895f4c23395b3ef46aa2e035e6d0
Parents: 9d31ac4
Author: Babak Vahdat <bvah...@apache.org>
Authored: Sat May 11 23:34:22 2013 +0200
Committer: Babak Vahdat <bvah...@apache.org>
Committed: Sat May 11 23:38:07 2013 +0200

----------------------------------------------------------------------
 .../camel/converter/crypto/CryptoDataFormat.java   |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/db91e7c9/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java
----------------------------------------------------------------------
diff --git 
a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java
 
b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java
index f469980..2b734ad 100644
--- 
a/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java
+++ 
b/components/camel-crypto/src/main/java/org/apache/camel/converter/crypto/CryptoDataFormat.java
@@ -120,14 +120,15 @@ public class CryptoDataFormat implements DataFormat {
         byte[] iv = getInitializationVector(exchange);
         Key key = getKey(exchange);
 
-        CipherOutputStream cipherStream = new CipherOutputStream(outputStream, 
initializeCipher(ENCRYPT_MODE, key, iv));
         InputStream plaintextStream = 
ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph);
         HMACAccumulator hmac = getMessageAuthenticationCode(key);
         if (plaintextStream != null) {
             inlineInitVector(outputStream, iv);
             byte[] buffer = new byte[bufferSize];
             int read;
+            CipherOutputStream cipherStream = null;
             try {
+                cipherStream = new CipherOutputStream(outputStream, 
initializeCipher(ENCRYPT_MODE, key, iv));
                 while ((read = plaintextStream.read(buffer)) > 0) {
                     cipherStream.write(buffer, 0, read);
                     cipherStream.flush();

Reply via email to