Search code examples
javacharacter-encodingjakarta-mailutf-7

Loading a Java Charset manually


I'm doing some work using the JavaMail API, and I've run across encodings which Java doesn't support natively (by design), such as UTF7/unicode-1-1-utf-7. For that encoding in particular I found the JUTF7 implementation of a Java Charset and CharsetProvider for UTF7. However, having added the jutf7.jar to my classpath I still get UnsupportedEncodingExceptions, and unicode-1-1-utf-7 is definitely one of JUTF7's aliases.

Is there a way to manually load the Charset or ensure that the Charset is being loaded so that I can rule that out as a cause?


Solution

  • There's a bit more to using a new Charset, apart from putting the necessary classes into the classpath. To quote the Javadocs:

    A charset provider identifies itself with a provider-configuration file named java.nio.charset.spi.CharsetProvider in the resource directory META-INF/services. The file should contain a list of fully-qualified concrete charset-provider class names, one per line. [...]

    ( http://download.oracle.com/javase/6/docs/api/java/nio/charset/spi/CharsetProvider.html )

    Is this special file present in the JAR?