This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch var-headers in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6108ed401c1f2ff84fda9bf9d079e8770b8ca767 Author: Claus Ibsen <[email protected]> AuthorDate: Tue Jan 30 10:50:52 2024 +0100 CAMEL-19749: variables - Should also copy message headers into variable when using EIP variables --- .../camel/converter/stream/CachedOutputStream.java | 38 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/core/camel-support/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java b/core/camel-support/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java index 865f0f2a240..49a8c9d7f0e 100644 --- a/core/camel-support/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java +++ b/core/camel-support/src/main/java/org/apache/camel/converter/stream/CachedOutputStream.java @@ -25,6 +25,7 @@ import org.apache.camel.Exchange; import org.apache.camel.StreamCache; import org.apache.camel.converter.stream.FileInputStreamCache.TempFileManager; import org.apache.camel.spi.StreamCachingStrategy; +import org.apache.camel.util.IOHelper; /** * This output stream will store the content into a File if the stream context size is exceed the THRESHOLD value. The @@ -165,9 +166,10 @@ public class CachedOutputStream extends OutputStream { } // This class will close the CachedOutputStream when it is closed - private static class WrappedInputStream extends InputStream { + private static class WrappedInputStream extends InputStream implements StreamCache { private final CachedOutputStream cachedOutputStream; private final InputStream inputStream; + private long pos; WrappedInputStream(CachedOutputStream cos, InputStream is) { cachedOutputStream = cos; @@ -176,6 +178,7 @@ public class CachedOutputStream extends OutputStream { @Override public int read() throws IOException { + pos++; return inputStream.read(); } @@ -185,8 +188,37 @@ public class CachedOutputStream extends OutputStream { } @Override - public synchronized void reset() throws IOException { - inputStream.reset(); + public synchronized void reset() { + try { + inputStream.reset(); + } catch (IOException e) { + // ignore + } + } + + @Override + public void writeTo(OutputStream os) throws IOException { + IOHelper.copy(this, os); + } + + @Override + public StreamCache copy(Exchange exchange) throws IOException { + return cachedOutputStream.newStreamCache(); + } + + @Override + public boolean inMemory() { + return cachedOutputStream.inMemory; + } + + @Override + public long length() { + return cachedOutputStream.totalLength; + } + + @Override + public long position() { + return pos; } @Override
