File: EncodingName.java

package info (click to toggle)
libxt-java 0.19991105-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,908 kB
  • ctags: 2,762
  • sloc: java: 12,823; makefile: 52; xml: 46
file content (69 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.jclark.xsl.sax;

public abstract class EncodingName {
  private static String[][] encodingMap = new String[][] {
    // IANA name, Java name
    { "US-ASCII", "ASCII" },
    { "ISO-8859-1", "ISO8859_1" },
    { "ISO-8859-2", "ISO8859_2" },
    { "ISO-8859-3", "ISO8859_3" },
    { "ISO-8859-4", "ISO8859_4" },
    { "ISO-8859-5", "ISO8859_5" },
    { "ISO-8859-6", "ISO8859_6" },
    { "ISO-8859-7", "ISO8859_7" },
    { "ISO-8859-8", "ISO8859_8" },
    { "ISO-8859-9", "ISO8859_9" },
    { "Big5", "Big5" },
    { "windows-1250", "Cp1250" },
    { "windows-1251", "Cp1251" },
    { "windows-1252", "Cp1252" },
    { "windows-1253", "Cp1253" },
    { "windows-1254", "Cp1254" },
    { "windows-1255", "Cp1255" },
    { "windows-1256", "Cp1256" },
    { "windows-1257", "Cp1257" },
    { "windows-1258", "Cp1258" },
    { "EUC-JP", "EUC_JP" },
    { "EUC-KR", "EUC_KR" },
    { "ISO-2022-CN", "ISO2022CN" },
    { "ISO-2022-JP", "ISO2022JP" },
    { "ISO-2022-KR", "ISO2022KR" },
    { "KOI8-R", "KOI8_R" },
    { "TIS-620", "MS874" },
    { "Shift_JIS", "SJIS" },
    { "UTF-8", "UTF8" },
    { "UTF-16", "Unicode" },
    { "UTF-16LE", "UnicodeLittle" },
    { "UTF-16BE", "UnicodeBig" },
  };

  static {
    // Workaround for some VMs (eg Microsoft's)
    // that use 8859_1 rather than ISO8859_1.
    try {
      "".getBytes("ISO8859_1");
    }
    catch (java.io.UnsupportedEncodingException e) {
      encodingMap[1][1] = "8859_1";
    }
  }

  public static String toIana(String encoding) {
    if (encoding == null)
      return null;
    for (int i = 0; i < encodingMap.length; i++)
      if (encoding.equalsIgnoreCase(encodingMap[i][1]))
	return encodingMap[i][0];
    return encoding;
  }

  public static String toJava(String encoding) {
    if (encoding == null)
      return null;
    for (int i = 0; i < encodingMap.length; i++)
      if (encoding.equalsIgnoreCase(encodingMap[i][0])
	  || encoding.equalsIgnoreCase(encodingMap[i][1]))
	return encodingMap[i][1];
    return encoding;
  }
}