Updated Branches:
  refs/heads/master 7340ce929 -> 2eea8f633

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/2eea8f63
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2eea8f63
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2eea8f63

Branch: refs/heads/master
Commit: 2eea8f633aba1ec9d5e5998ea8c0c58f32313868
Parents: 7340ce9
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:34:22 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/2eea8f63/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