[ 
https://issues.apache.org/jira/browse/CAMEL-25995?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18130929#comment-18130929
 ] 

Claus Ibsen commented on CAMEL-25995:
-------------------------------------

Fix in PR https://github.com/apache/camel/pull/28355 (one PR for the 16 data 
format tickets CAMEL-25995 to CAMEL-26011, except CAMEL-26000). The PR 
description lists the change per ticket.

_Claude Code on behalf of davsclaus_

> camel-base64 - unmarshal of a file fails with Stream closed, as the input 
> stream is closed before the decoded stream is read
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25995
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25995
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-base64
>    Affects Versions: 4.18.0, 4.22.0, 4.23.0
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 4.24.0
>
>
> The base64 data format decodes while the body is read: {{unmarshal}} returns 
> a {{Base64InputStream}} over the input stream ({{Base64DataFormat}}, main 
> 50d17f9c2614, line 77). Since CAMEL-21293 (4.9.0) that input stream is closed 
> as soon as {{unmarshal}} returns:
> * {{DataFormat.unmarshal(Exchange, Object)}} closes the stream it converted 
> the body to (camel-api {{DataFormat}}, line 106);
> * {{UnmarshalProcessor}} closes an {{InputStream}} body (line 129).
> Only an {{Iterator}} result is left open. The first read of the decoded 
> stream then fails with {{java.io.IOException: Stream closed}}.
> A body in memory still works, as closing a {{ByteArrayInputStream}} or a 
> stream cache does nothing. A file does not, so {{from: file}} followed by 
> {{unmarshal: base64}}, a common way to decode Base64 files, fails.
> Checked on 4.24.0-SNAPSHOT with {{camel run}}, with a file holding 
> {{SGVsbG8gQ2FtZWwgZnJvbSBhIGZpbGU=}}:
> * {{from: file:b64in?noop=true}}, then {{unmarshal: base64}}: 
> {{StreamCacheException}} from {{Base64InputStream}} to {{StreamCache}}, due 
> to {{java.io.IOException: Stream closed}} (stream caching reads the decoded 
> stream before the next step);
> * a {{java.io.File}} body: the same;
> * the same content as a {{byte[]}}: "Hello Camel from a file".
> *Proposed change*: decode in {{unmarshal}} into the stream cache (an 
> {{OutputStreamBuilder}}, as marshal does) and return it, so the input stream 
> can be closed.
> _Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to