Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Encodings supported by Java?

Thread view: 
Casper - 29 Jun 2005 09:48 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.