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:40 UTC
[1/3] git commit: CAMEL-7056: Use streaming support in base64. Thanks
to Stephan Siano for the patch.
Updated Branches:
refs/heads/camel-2.12.x 954c068b9 -> 66cbc0d36
refs/heads/master 96a991760 -> 15e1077d2
CAMEL-7056: Use streaming support in base64. Thanks to Stephan Siano 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/dc081927
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/dc081927
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/dc081927
Branch: refs/heads/master
Commit: dc081927c8c2b56ad00dba67e639a675ab44c446
Parents: 96a9917
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Dec 14 10:21:08 2013 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Dec 14 10:21:08 2013 +0100
----------------------------------------------------------------------
.../dataformat/base64/Base64DataFormat.java | 39 ++++++++++++--------
1 file changed, 24 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/dc081927/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java b/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java
index 70282b3..fc30303 100644
--- a/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java
+++ b/components/camel-base64/src/main/java/org/apache/camel/dataformat/base64/Base64DataFormat.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.dataformat.base64;
-import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
@@ -25,6 +24,8 @@ import org.apache.camel.spi.DataFormat;
import org.apache.camel.util.ExchangeHelper;
import org.apache.camel.util.IOHelper;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Base64InputStream;
+import org.apache.commons.codec.binary.Base64OutputStream;
public class Base64DataFormat implements DataFormat {
@@ -34,29 +35,37 @@ public class Base64DataFormat implements DataFormat {
@Override
public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
+ if (urlSafe) {
+ marshalUrlSafe(exchange, graph, stream);
+ } else {
+ marshalStreaming(exchange, graph, stream);
+ }
+ }
+
+ private void marshalStreaming(Exchange exchange, Object graph, OutputStream stream) throws Exception {
+ InputStream decoded = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph);
+
+ Base64OutputStream base64Output = new Base64OutputStream(stream, true, lineLength, lineSeparator);
+ try {
+ IOHelper.copy(decoded, base64Output);
+ } finally {
+ IOHelper.close(decoded, base64Output);
+ }
+ }
+
+ private void marshalUrlSafe(Exchange exchange, Object graph, OutputStream stream) throws Exception {
byte[] decoded = ExchangeHelper.convertToMandatoryType(exchange, byte[].class, graph);
- Base64 codec = createCodec();
+ Base64 codec = new Base64(lineLength, lineSeparator, true);
byte[] encoded = codec.encode(decoded);
stream.write(encoded);
+ stream.flush();
}
@Override
public Object unmarshal(Exchange exchange, InputStream input) throws Exception {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- IOHelper.copyAndCloseInput(input, baos);
- byte[] encoded = baos.toByteArray();
- baos.close();
-
- Base64 codec = createCodec();
- byte[] decoded = codec.decode(encoded);
-
- return decoded;
- }
-
- private Base64 createCodec() {
- return new Base64(lineLength, lineSeparator, urlSafe);
+ return new Base64InputStream(input, false, lineLength, lineSeparator);
}
public int getLineLength() {
[2/3] git commit: CAMEL-7055: Fixed stream caching to clean temp file
when UoW done. Thanks to Franz Forsthofer for the patch.
Posted by da...@apache.org.
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/15e1077d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/15e1077d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/15e1077d
Branch: refs/heads/master
Commit: 15e1077d2e11385b7cd763c3fc40e4b4282b21ea
Parents: dc08192
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:02 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/15e1077d/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/15e1077d/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;
+ }
+
+}
[3/3] git commit: CAMEL-7055: Fixed stream caching to clean temp file
when UoW done. Thanks to Franz Forsthofer for the patch.
Posted by da...@apache.org.
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;
+ }
+
+}