Camel file component with charset throw UnmappableCharacterException while writing a file with special characters

Solution Verified - Updated -

Issue

  • Create following route with jboss.fuse.bom.version 7.6.0.fuse-760027-redhat-00001 or of Red Hat Fuse 7.7.
   <camelContext id="_context1" xmlns="http://camel.apache.org/schema/blueprint">
        <route>
<from id="_from14" uri="file:C:\Users\chand\Downloads\testfiletransfer\incoming/>
<to id="_to14" uri="file:C:\Users\chand\Downloads\testfiletransfer\outgoing?charset=windows-1252"/>
 <log id="_log14" loggingLevel="INFO" message="Processed file ${file:name}"/>
</route>
    </camelContext>
  • Run it in Red Hat Fuse 7.7 GA or as "Local Camel Context" from any IDE.
  • Place attached file TestFile.txt in incoming folder so that route can consume it. This file has special character. Content of TestFile.txt file is like
lasjdngå narpe 

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr,  sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
  • Check logs, we would observe exception
Caused by: java.nio.charset.UnmappableCharacterException: Input length = 1
    at java.nio.charset.CoderResult.throwException(Unknown Source) ~[?:1.8.0_251]
    at sun.nio.cs.StreamEncoder.implWrite(Unknown Source) ~[?:1.8.0_251]
    at sun.nio.cs.StreamEncoder.write(Unknown Source) ~[?:1.8.0_251]
    at java.io.OutputStreamWriter.write(Unknown Source) ~[?:1.8.0_251]
    at java.io.BufferedWriter.write(Unknown Source) ~[?:1.8.0_251]
    at org.apache.camel.util.IOHelper.copy(IOHelper.java:246) ~[!/:2.21.0.fuse-760027-redhat-00001]
    at org.apache.camel.component.file.FileOperations.writeFileByReaderWithCharset(FileOperations.java:464) ~[!/:2.21.0.fuse-760027-redhat-00001]
    at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:330) ~[!/:2.21.0.fuse-760027-redhat-00001]
    ... 19 more

Environment

  • Red Hat Fuse
    • 7.7

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In