KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thaiopensource > xml > util > EncodingMap


1 package com.thaiopensource.xml.util;
2
3 import java.io.UnsupportedEncodingException JavaDoc;
4
5 public abstract class EncodingMap {
6   private static final String JavaDoc[] aliases = {
7     "UTF-8", "UTF8",
8     "UTF-16", "Unicode",
9     "UTF-16BE", "UnicodeBigUnmarked",
10     "UTF-16LE", "UnicodeLittleUnmarked",
11     "US-ASCII", "ASCII",
12     "TIS-620", "TIS620"
13   };
14       
15   static public String JavaDoc getJavaName(String JavaDoc enc) {
16     try {
17       "x".getBytes(enc);
18     }
19     catch (UnsupportedEncodingException JavaDoc e) {
20       for (int i = 0; i < aliases.length; i += 2) {
21     if (enc.equalsIgnoreCase(aliases[i])) {
22       try {
23         "x".getBytes(aliases[i + 1]);
24         return aliases[i + 1];
25       }
26       catch (UnsupportedEncodingException JavaDoc e2) {}
27     }
28       }
29     }
30     return enc;
31   }
32
33   static public void main(String JavaDoc[] args) {
34     System.err.println(getJavaName(args[0]));
35   }
36 }
37   
38
Popular Tags