Sidebar

How can I receive data from 2 sources using different encodings?

0 votes
792 views
asked Apr 22, 2020 by brandon-w-8204 (33,330 points)
I have a channel that receives data from 2 sources. One is UTF-8 and one is Windows 1252. How can I handle both encodings in the same channel?

1 Answer

0 votes
 
Best answer

Set the channel encoding to UTF-8:

You can use a preprocess script that will convert Windows-1252 to UTF-8. 

if (java.util.Arrays.equals(bytesIn, new java.lang.String(bytesIn, "UTF-8").getBytes("UTF-8"))) {
   // UTF-8 is probably what we have...
   bytesOut = bytesIn;
} else {
   // Try to convert between Windows-1252 to UTF-8.
   bytesOut = new java.lang.String(bytesIn, "Windows-1252").getBytes("UTF-8");
}

answered Apr 22, 2020 by brandon-w-8204 (33,330 points)
selected Apr 22, 2020 by mike-r-7535
...