You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/12/18 04:21:16 UTC

git commit: CAMEL-7055 fixed the test error

Updated Branches:
  refs/heads/master 9d00d4cc7 -> 191768f01


CAMEL-7055 fixed the test error


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

Branch: refs/heads/master
Commit: 191768f0142b8bb707e3ebe27407563f5029c3a0
Parents: 9d00d4c
Author: Willem Jiang <wi...@gmail.com>
Authored: Wed Dec 18 11:05:14 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Dec 18 11:05:14 2013 +0800

----------------------------------------------------------------------
 .../converter/stream/CachedOutputStream.java    | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/191768f0/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java b/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
index 0e3540c..f08d52d 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java
@@ -66,12 +66,14 @@ public class CachedOutputStream extends OutputStream {
     private File tempFile;
     private FileInputStreamCache fileInputStreamCache;
     private CipherPair ciphers;
+    private final boolean closedOnCompletion;
 
     public CachedOutputStream(Exchange exchange) {
         this(exchange, true);
     }
 
     public CachedOutputStream(Exchange exchange, final boolean closedOnCompletion) {
+        this.closedOnCompletion = closedOnCompletion;
         this.strategy = exchange.getContext().getStreamCachingStrategy();
         currentStream = new CachedByteArrayOutputStream(strategy.getBufferSize());
         
@@ -85,15 +87,15 @@ public class CachedOutputStream extends OutputStream {
                     }
                     if (closedOnCompletion) {
                         close();
+                        try {
+                            cleanUpTempFile();
+                        } catch (Exception e) {
+                            LOG.warn("Error deleting temporary cache file: " + tempFile + ". This exception will be ignored.", e);
+                        }
                     }
                 } catch (Exception e) {
                     LOG.warn("Error closing streams. This exception will be ignored.", e);
                 }
-                try {
-                    cleanUpTempFile();
-                } catch (Exception e) {
-                    LOG.warn("Error deleting temporary cache file: " + tempFile + ". This exception will be ignored.", e);
-                }
             }
     
             @Override
@@ -109,6 +111,14 @@ public class CachedOutputStream extends OutputStream {
 
     public void close() throws IOException {
         currentStream.close();
+        // need to clean up the temp file this time
+        if (!closedOnCompletion) {
+            try {
+                cleanUpTempFile();
+            } catch (Exception e) {
+                LOG.warn("Error deleting temporary cache file: " + tempFile + ". This exception will be ignored.", e);
+            }
+        }
     }
 
     public boolean equals(Object obj) {