You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/12/14 11:06:42 UTC
[3/3] git commit: CAMEL-7055: Fixed stream caching to clean temp file
when UoW done. Thanks to Franz Forsthofer for the patch.
CAMEL-7055: Fixed stream caching to clean temp file when UoW done. Thanks to Franz Forsthofer for the patch.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/66cbc0d3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/66cbc0d3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/66cbc0d3
Branch: refs/heads/camel-2.12.x
Commit: 66cbc0d36eeb1bfdd9a45449fcb8b1697e6ecb97
Parents: 954c068
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Dec 14 11:09:02 2013 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Dec 14 11:09:20 2013 +0100
----------------------------------------------------------------------
.../converter/stream/CachedOutputStream.java | 42 +++++++++++---------
.../processor/DataFormatStreamingTest.java | 31 +++++++++++++++
2 files changed, 54 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/66cbc0d3/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 c5f3b49..0e3540c 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
@@ -71,31 +71,36 @@ public class CachedOutputStream extends OutputStream {
this(exchange, true);
}
- public CachedOutputStream(Exchange exchange, boolean closedOnCompletion) {
+ public CachedOutputStream(Exchange exchange, final boolean closedOnCompletion) {
this.strategy = exchange.getContext().getStreamCachingStrategy();
currentStream = new CachedByteArrayOutputStream(strategy.getBufferSize());
- if (closedOnCompletion) {
- // add on completion so we can cleanup after the exchange is done such as deleting temporary files
- exchange.addOnCompletion(new SynchronizationAdapter() {
- @Override
- public void onDone(Exchange exchange) {
- try {
- if (fileInputStreamCache != null) {
- fileInputStreamCache.close();
- }
+ // add on completion so we can cleanup after the exchange is done such as deleting temporary files
+ exchange.addOnCompletion(new SynchronizationAdapter() {
+ @Override
+ public void onDone(Exchange exchange) {
+ try {
+ if (fileInputStreamCache != null) {
+ fileInputStreamCache.close();
+ }
+ if (closedOnCompletion) {
close();
- } catch (Exception e) {
- LOG.warn("Error deleting temporary cache file: " + tempFile, e);
}
+ } catch (Exception e) {
+ LOG.warn("Error closing streams. This exception will be ignored.", e);
}
-
- @Override
- public String toString() {
- return "OnCompletion[CachedOutputStream]";
+ try {
+ cleanUpTempFile();
+ } catch (Exception e) {
+ LOG.warn("Error deleting temporary cache file: " + tempFile + ". This exception will be ignored.", e);
}
- });
- }
+ }
+
+ @Override
+ public String toString() {
+ return "OnCompletion[CachedOutputStream]";
+ }
+ });
}
public void flush() throws IOException {
@@ -104,7 +109,6 @@ public class CachedOutputStream extends OutputStream {
public void close() throws IOException {
currentStream.close();
- cleanUpTempFile();
}
public boolean equals(Object obj) {
http://git-wip-us.apache.org/repos/asf/camel/blob/66cbc0d3/camel-core/src/test/java/org/apache/camel/processor/DataFormatStreamingTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/DataFormatStreamingTest.java b/camel-core/src/test/java/org/apache/camel/processor/DataFormatStreamingTest.java
new file mode 100644
index 0000000..d1a0e0e
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/DataFormatStreamingTest.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import org.apache.camel.CamelContext;
+
+public class DataFormatStreamingTest extends DataFormatTest {
+
+ @Override
+ public CamelContext createCamelContext() throws Exception {
+ CamelContext cc = super.createCamelContext();
+ cc.setStreamCaching(Boolean.TRUE);
+ cc.getStreamCachingStrategy().setSpoolThreshold(1L);
+ return cc;
+ }
+
+}