You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Christian Schneider <ch...@die-schneider.net> on 2009/04/29 08:15:26 UTC

Convert File to String with encoding

Hi,

I am having the problem that I need to read a file with the FileEndpoint 
and process it as a String in my own processor.
I use the convertBody(String.class) to make a string out of the file 
contents. Unfortunately there is no way to set the encoding to use.
In my case the File content is xml so the encoding could even be read 
from the xml header.

Is there any functionality to support this?

Greetings

Christian


Re: Convert File to String with encoding

Posted by Christian Schneider <ch...@die-schneider.net>.
Hi Claus,

I have added an issue:
https://issues.apache.org/activemq/browse/CAMEL-1573

When I debugged into the code I found the place where the file is 
actually read. There it seems it is converted to a string without 
encoding in place. Is this a bug?
I cannot remember the place in the code at the moment I will try to find 
it again.

Greetings

Christian

Claus Ibsen schrieb:
> Hi
>
> You can set a property on the Exchange with the encoding. Then the
> type converters (most of them) will use this when converting from byte
> based.
>
> There should be a constant for the key in Exchange.CHARSET_NAME
>
> And there should be a setProperty DSL you can do before the convert body to.
>
> But it might be a good idea to support a 2nd parameter to convert body
> to so we can provide encoding.
> Do you mind creating a ticket for that?
>
>
> Reading the encoding in the XML file, well then you need to convert it
> to some XML types so it uses XML factories, that well parses XML files
> :)
>
>
> On Wed, Apr 29, 2009 at 8:15 AM, Christian Schneider
> <ch...@die-schneider.net> wrote:
>   


-- 

Christian Schneider
---
http://www.liquid-reality.de


Re: Convert File to String with encoding

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can set a property on the Exchange with the encoding. Then the
type converters (most of them) will use this when converting from byte
based.

There should be a constant for the key in Exchange.CHARSET_NAME

And there should be a setProperty DSL you can do before the convert body to.

But it might be a good idea to support a 2nd parameter to convert body
to so we can provide encoding.
Do you mind creating a ticket for that?


Reading the encoding in the XML file, well then you need to convert it
to some XML types so it uses XML factories, that well parses XML files
:)


On Wed, Apr 29, 2009 at 8:15 AM, Christian Schneider
<ch...@die-schneider.net> wrote:
> Hi,
>
> I am having the problem that I need to read a file with the FileEndpoint and
> process it as a String in my own processor.
> I use the convertBody(String.class) to make a string out of the file
> contents. Unfortunately there is no way to set the encoding to use.
> In my case the File content is xml so the encoding could even be read from
> the xml header.
>
> Is there any functionality to support this?
>
> Greetings
>
> Christian
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Apache Camel Reference Card:
http://refcardz.dzone.com/refcardz/enterprise-integration