Hello Souciance, and thx for your reply. I stepped through the code and it really looked like I need to register my own Converter which can then make the conversion the way I want it, i.e. without relying on the system's default encoding to make any sense.
If you are interested, this is how the Converter looks: https://github.com/metasfresh/metasfresh/blob/master/de.metas.edi.esb.camel/src/main/java/de/metas/edi/esb/route/exports/ReaderTypeConverter.java It can convert byte[] and ByteArrayInputStream. I found the info i needed at https://camel.apache.org/type-converter.html (mostly in section "Encoding support for byte[] and String Conversion"). However, I'm still not 100% sure I didn't miss something..I would have expected that this stuff was "somehow" already there, and i would just have had to set the Exchange.CHARSET_NAME.. Probably I'm just spoiled by camel ;-). Best regards Tobias -----Original Message----- From: souciance [mailto:souciance.eqdam.ras...@gmail.com] Sent: Donnerstag, 2. Juni 2016 10:33 To: users@camel.apache.org Subject: Re: Q about how to help the file2 component to do a better job Not sure if this helps but I had to go from a file with stream to third party library which wanted a Reader and I used this: //enforce UTF-8 encoding where stream is an InputStream stream = new ByteArrayInputStream(exchange.getIn().getBody().toString(). getBytes("UTF-8")); Then go from the stream to Reader.. On Thu, Jun 2, 2016 at 10:19 AM, Tobias Schöneberg [via Camel] < ml-node+s465427n5783381...@n5.nabble.com> wrote: > Hi, > > we are using servicemix and I had a problem which was related to the > time when that servicemix's JVM started. > Aparently, it started before the operating system's locale was set to > something UTF-8ish. > I solved it (fingers crossed) by making sure that the system property > "file.encoding" is explicitly set to "UTF-8" > > This is the related background/documentation, i hope it sufficiently > explains what the problem was about: > > # If the camel file component needs to write an InputStream to a file > # and has to use a given encoding # and doesn't have enough info to > do anything sophisticated, # then it creates a reader for the task, > using "new InputStreamReader(is)". > # This reader uses the "default charset" to interpret the stream. > # Depending on when the JVM was started, the default charset might be > ANSI_X3.4-1968 a.k.a. US-Ascii. > # Now, when we create EDI files, the smooks' SmooksDataFormat creates > a String and then writes it out as a UTF-8 encoded byte stream. > # When this stream is read as US-Ascii, then all its nice Umlauts are > turned into "??"s. > # To prevent this, we explicitly set the default encoding to UTF-8 for > the servicemix-JVM. > > .. and this is the code from FileOperations.storeFile() > (camel-2.16.1), which creates the InputStreamReader from the the > exchange's body > > <code> > if (charset != null) { > // charset configured so we must use a reader so we can write with > encoding > Reader in = > exchange.getContext().getTypeConverter().tryConvertTo(Reader.class, > exchange, exchange.getIn().getBody()); > if (in == null) { > // okay no direct reader conversion, so use an input stream > (which a lot can be converted as) > InputStream is = > exchange.getIn().getMandatoryBody(InputStream.class); > in = new InputStreamReader(is); > } > // buffer the reader > in = IOHelper.buffered(in); > writeFileByReaderWithCharset(in, file, charset); } else { </code> > > Now to my question: > Could you point me to a best practice in my route (i'm specifying it > via > java-fluent) to tell camel "something", so that the tryConvertTo() > method succeeds in creating an UTF-8-based reader? > E.g. by setting some propery or something? > > It would relief us from worrying about that system property on the > systems we deploy this component to. > > Best regards > Tobi > > > > ------------------------------ > If you reply to this email, your message will be added to the > discussion > below: > > http://camel.465427.n5.nabble.com/Q-about-how-to-help-the-file2-compon > ent-to-do-a-better-job-tp5783381.html > To start a new topic under Camel - Users, email > ml-node+s465427n465428...@n5.nabble.com > To unsubscribe from Camel - Users, click here > <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsu > bscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpb > C5jb218NDY1NDI4fDE1MzI5MTE2NTY=> > . > NAML > <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macr > o_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namesp > aces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.vi > ew.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble% > 3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%2 > 1nabble%3Aemail.naml> > -- View this message in context: http://camel.465427.n5.nabble.com/Q-about-how-to-help-the-file2-component-to-do-a-better-job-tp5783381p5783382.html Sent from the Camel - Users mailing list archive at Nabble.com.