Saturday, August 19, 2006
java.io.UnsupportedEncodingException in JavaMail API
Today I discovered that java has a limited way of handling encodings in java mail API and I guess that goes for working with text in general.
my problem was that during call to POP3Message.getContent() or call to Part.getContent() java.io.UnsupportedEncodingException was thrown.
According to JavaMail FAQ answer you should catch UnsupportedEncodingException and handle it by "choose a charset in some heruistic manner".
One of the encodings I had a problem with was "x-mac-cyrrilic". It actually was located in $JRE/lib/charsets.jar as "x-MacCyrillic". I discovered it looking at supproted encodings list located at http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html for JDK15.
I wonder if all encodings are there and what to do if there is a need to handle message with encodings that is not supported.
For nio there is a java.nio.charset.spi.CharsetProvider class that could be used.
my problem was that during call to POP3Message.getContent() or call to Part.getContent() java.io.UnsupportedEncodingException was thrown.
According to JavaMail FAQ answer you should catch UnsupportedEncodingException and handle it by "choose a charset in some heruistic manner".
One of the encodings I had a problem with was "x-mac-cyrrilic". It actually was located in $JRE/lib/charsets.jar as "x-MacCyrillic". I discovered it looking at supproted encodings list located at http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html for JDK15.
I wonder if all encodings are there and what to do if there is a need to handle message with encodings that is not supported.
For nio there is a java.nio.charset.spi.CharsetProvider class that could be used.