National codepage ASCII extensions are suppose to be supported by the
"java.io" and the "java.lang" packages contained in charsets.jar. Oddly
enough, the "java.nio" which holds the nationalization Charset class,
does not seem to know any of these specific codepages:
Charset.isSupported("Cp850"); // the outcome is false.
According to http://www.rgagnon.com/javadetails/encoding.html, a suite
of language specific locales are supported (incl. Cp850). And oddly
enough, I can actually use the Cp850 encoding in the "java.io" API
without a problem:
...new InputStreamReader(BufferedInputStream(new
FileInputStream("a.txt")), "Cp850");
It seems confusing and messy if charsets are not all encapsulated by the
same object (Charset). Does this mean I have no way of testing whether a
charset is supported, except through some really crude trial-n-error
mis-use of an InputStream?
How should I go about encapsulating charset support for my application,
if only some are contained within Charset and the rest are hidden away
somewhere as string identifiers in the "java.io" package?
Regards,
Casper
Casper - 29 Jun 2005 11:47 GMT
Well it turns out, I can test whether the characterset/encoding is
supported by using the sun.io.CharacterEncoding class:
sun.io.CharacterEncoding ce = new sun.io.CharacterEncoding();
System.out.println( ce.aliasName("Cp168")); // null: doesn't exist
System.out.println( ce.aliasName("US-ASCII")); // "ASCII"
System.out.println( ce.aliasName("Cp865")); // "Cp865"
Not sure how safe/correct that is. My biggest problem still persists
though. How do I encapsulate all encodings, it seems there is no way to
enumerate the codepages through sun.io or any other package.
Regards,
Casper