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-component-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=unsubscribe_by_code&node=465428&code=c291Y2lhbmNlLmVxZGFtLnJhc2h0aUBnbWFpbC5jb218NDY1NDI4fDE1MzI5MTE2NTY=> > . > NAML > <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%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.