1 /* 2 * Copyright (C) 2007 Esmertec AG. 3 * Copyright (C) 2007 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package com.android.messaging.mmslib.pdu; 19 20 import androidx.collection.SimpleArrayMap; 21 import android.util.SparseArray; 22 23 import java.io.UnsupportedEncodingException; 24 25 public class CharacterSets { 26 /** 27 * IANA assigned MIB enum numbers. 28 * 29 * From wap-230-wsp-20010705-a.pdf 30 * Any-charset = <Octet 128> 31 * Equivalent to the special RFC2616 charset value "*" 32 * 33 * Link to all the charsets: http://www.iana.org/assignments/character-sets/character-sets.xhtml 34 * Use Charset.availableCharsets() to see if a potential charset is supported in java: 35 * private void dumpCharsets() { 36 * logvv("dumpCharsets"); 37 * SortedMap<String, Charset> charsets = Charset.availableCharsets(); 38 * for (Entry<String, Charset> entry : charsets.entrySet()) { 39 * String key = entry.getKey(); 40 * Charset value = entry.getValue(); 41 * logvv("charset key: " + key + " value: " + value); 42 * } 43 * } 44 * 45 * As of March 21, 2014, here is the list from dumpCharsets: 46 * Adobe-Standard-Encoding value: java.nio.charset.CharsetICU[Adobe-Standard-Encoding] 47 * Big5 value: java.nio.charset.CharsetICU[Big5] 48 * Big5-HKSCS value: java.nio.charset.CharsetICU[Big5-HKSCS] 49 * BOCU-1 value: java.nio.charset.CharsetICU[BOCU-1] 50 * CESU-8 value: java.nio.charset.CharsetICU[CESU-8] 51 * cp1363 value: java.nio.charset.CharsetICU[cp1363] 52 * cp851 value: java.nio.charset.CharsetICU[cp851] 53 * cp864 value: java.nio.charset.CharsetICU[cp864] 54 * EUC-JP value: java.nio.charset.CharsetICU[EUC-JP] 55 * EUC-KR value: java.nio.charset.CharsetICU[EUC-KR] 56 * GB18030 value: java.nio.charset.CharsetICU[GB18030] 57 * GBK value: java.nio.charset.CharsetICU[GBK] 58 * hp-roman8 value: java.nio.charset.CharsetICU[hp-roman8] 59 * HZ-GB-2312 value: java.nio.charset.CharsetICU[HZ-GB-2312] 60 * IBM-Thai value: java.nio.charset.CharsetICU[IBM-Thai] 61 * IBM00858 value: java.nio.charset.CharsetICU[IBM00858] 62 * IBM01140 value: java.nio.charset.CharsetICU[IBM01140] 63 * IBM01141 value: java.nio.charset.CharsetICU[IBM01141] 64 * IBM01142 value: java.nio.charset.CharsetICU[IBM01142] 65 * IBM01143 value: java.nio.charset.CharsetICU[IBM01143] 66 * IBM01144 value: java.nio.charset.CharsetICU[IBM01144] 67 * IBM01145 value: java.nio.charset.CharsetICU[IBM01145] 68 * IBM01146 value: java.nio.charset.CharsetICU[IBM01146] 69 * IBM01147 value: java.nio.charset.CharsetICU[IBM01147] 70 * IBM01148 value: java.nio.charset.CharsetICU[IBM01148] 71 * IBM01149 value: java.nio.charset.CharsetICU[IBM01149] 72 * IBM037 value: java.nio.charset.CharsetICU[IBM037] 73 * IBM1026 value: java.nio.charset.CharsetICU[IBM1026] 74 * IBM1047 value: java.nio.charset.CharsetICU[IBM1047] 75 * IBM273 value: java.nio.charset.CharsetICU[IBM273] 76 * IBM277 value: java.nio.charset.CharsetICU[IBM277] 77 * IBM278 value: java.nio.charset.CharsetICU[IBM278] 78 * IBM280 value: java.nio.charset.CharsetICU[IBM280] 79 * IBM284 value: java.nio.charset.CharsetICU[IBM284] 80 * IBM285 value: java.nio.charset.CharsetICU[IBM285] 81 * IBM290 value: java.nio.charset.CharsetICU[IBM290] 82 * IBM297 value: java.nio.charset.CharsetICU[IBM297] 83 * IBM420 value: java.nio.charset.CharsetICU[IBM420] 84 * IBM424 value: java.nio.charset.CharsetICU[IBM424] 85 * IBM437 value: java.nio.charset.CharsetICU[IBM437] 86 * IBM500 value: java.nio.charset.CharsetICU[IBM500] 87 * IBM775 value: java.nio.charset.CharsetICU[IBM775] 88 * IBM850 value: java.nio.charset.CharsetICU[IBM850] 89 * IBM852 value: java.nio.charset.CharsetICU[IBM852] 90 * IBM855 value: java.nio.charset.CharsetICU[IBM855] 91 * IBM857 value: java.nio.charset.CharsetICU[IBM857] 92 * IBM860 value: java.nio.charset.CharsetICU[IBM860] 93 * IBM861 value: java.nio.charset.CharsetICU[IBM861] 94 * IBM862 value: java.nio.charset.CharsetICU[IBM862] 95 * IBM863 value: java.nio.charset.CharsetICU[IBM863] 96 * IBM865 value: java.nio.charset.CharsetICU[IBM865] 97 * IBM866 value: java.nio.charset.CharsetICU[IBM866] 98 * IBM868 value: java.nio.charset.CharsetICU[IBM868] 99 * IBM869 value: java.nio.charset.CharsetICU[IBM869] 100 * IBM870 value: java.nio.charset.CharsetICU[IBM870] 101 * IBM871 value: java.nio.charset.CharsetICU[IBM871] 102 * IBM918 value: java.nio.charset.CharsetICU[IBM918] 103 * ISO-2022-CN value: java.nio.charset.CharsetICU[ISO-2022-CN] 104 * ISO-2022-CN-EXT value: java.nio.charset.CharsetICU[ISO-2022-CN-EXT] 105 * ISO-2022-JP value: java.nio.charset.CharsetICU[ISO-2022-JP] 106 * ISO-2022-JP-1 value: java.nio.charset.CharsetICU[ISO-2022-JP-1] 107 * ISO-2022-JP-2 value: java.nio.charset.CharsetICU[ISO-2022-JP-2] 108 * ISO-2022-KR value: java.nio.charset.CharsetICU[ISO-2022-KR] 109 * ISO-8859-1 value: java.nio.charset.CharsetICU[ISO-8859-1] 110 * ISO-8859-10 value: java.nio.charset.CharsetICU[ISO-8859-10] 111 * ISO-8859-13 value: java.nio.charset.CharsetICU[ISO-8859-13] 112 * ISO-8859-14 value: java.nio.charset.CharsetICU[ISO-8859-14] 113 * ISO-8859-15 value: java.nio.charset.CharsetICU[ISO-8859-15] 114 * ISO-8859-2 value: java.nio.charset.CharsetICU[ISO-8859-2] 115 * ISO-8859-3 value: java.nio.charset.CharsetICU[ISO-8859-3] 116 * ISO-8859-4 value: java.nio.charset.CharsetICU[ISO-8859-4] 117 * ISO-8859-5 value: java.nio.charset.CharsetICU[ISO-8859-5] 118 * ISO-8859-6 value: java.nio.charset.CharsetICU[ISO-8859-6] 119 * ISO-8859-7 value: java.nio.charset.CharsetICU[ISO-8859-7] 120 * ISO-8859-8 value: java.nio.charset.CharsetICU[ISO-8859-8] 121 * ISO-8859-9 value: java.nio.charset.CharsetICU[ISO-8859-9] 122 * KOI8-R value: java.nio.charset.CharsetICU[KOI8-R] 123 * KOI8-U value: java.nio.charset.CharsetICU[KOI8-U] 124 * macintosh value: java.nio.charset.CharsetICU[macintosh] 125 * SCSU value: java.nio.charset.CharsetICU[SCSU] 126 * Shift_JIS value: java.nio.charset.CharsetICU[Shift_JIS] 127 * TIS-620 value: java.nio.charset.CharsetICU[TIS-620] 128 * US-ASCII value: java.nio.charset.CharsetICU[US-ASCII] 129 * UTF-16 value: java.nio.charset.CharsetICU[UTF-16] 130 * UTF-16BE value: java.nio.charset.CharsetICU[UTF-16BE] 131 * UTF-16LE value: java.nio.charset.CharsetICU[UTF-16LE] 132 * UTF-32 value: java.nio.charset.CharsetICU[UTF-32] 133 * UTF-32BE value: java.nio.charset.CharsetICU[UTF-32BE] 134 * UTF-32LE value: java.nio.charset.CharsetICU[UTF-32LE] 135 * UTF-7 value: java.nio.charset.CharsetICU[UTF-7] 136 * UTF-8 value: java.nio.charset.CharsetICU[UTF-8] 137 * windows-1250 value: java.nio.charset.CharsetICU[windows-1250] 138 * windows-1251 value: java.nio.charset.CharsetICU[windows-1251] 139 * windows-1252 value: java.nio.charset.CharsetICU[windows-1252] 140 * windows-1253 value: java.nio.charset.CharsetICU[windows-1253] 141 * windows-1254 value: java.nio.charset.CharsetICU[windows-1254] 142 * windows-1255 value: java.nio.charset.CharsetICU[windows-1255] 143 * windows-1256 value: java.nio.charset.CharsetICU[windows-1256] 144 * windows-1257 value: java.nio.charset.CharsetICU[windows-1257] 145 * windows-1258 value: java.nio.charset.CharsetICU[windows-1258] 146 * x-compound-text value: java.nio.charset.CharsetICU[x-compound-text] 147 * x-ebcdic-xml-us value: java.nio.charset.CharsetICU[x-ebcdic-xml-us] 148 * x-gsm-03.38-2000 value: java.nio.charset.CharsetICU[x-gsm-03.38-2000] 149 * x-ibm-1047-s390 value: java.nio.charset.CharsetICU[x-ibm-1047-s390] 150 * x-ibm-1125_P100-1997 value: java.nio.charset.CharsetICU[x-ibm-1125_P100-1997] 151 * x-ibm-1129_P100-1997 value: java.nio.charset.CharsetICU[x-ibm-1129_P100-1997] 152 * x-ibm-1130_P100-1997 value: java.nio.charset.CharsetICU[x-ibm-1130_P100-1997] 153 * x-ibm-1131_P100-1997 value: java.nio.charset.CharsetICU[x-ibm-1131_P100-1997] 154 * x-ibm-1132_P100-1998 value: java.nio.charset.CharsetICU[x-ibm-1132_P100-1998] 155 * x-ibm-1133_P100-1997 value: java.nio.charset.CharsetICU[x-ibm-1133_P100-1997] 156 * x-ibm-1137_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-1137_P100-1999] 157 * x-ibm-1140-s390 value: java.nio.charset.CharsetICU[x-ibm-1140-s390] 158 * x-ibm-1141-s390 value: java.nio.charset.CharsetICU[x-ibm-1141-s390] 159 * x-ibm-1142-s390 value: java.nio.charset.CharsetICU[x-ibm-1142-s390] 160 * x-ibm-1143-s390 value: java.nio.charset.CharsetICU[x-ibm-1143-s390] 161 * x-ibm-1144-s390 value: java.nio.charset.CharsetICU[x-ibm-1144-s390] 162 * x-ibm-1145-s390 value: java.nio.charset.CharsetICU[x-ibm-1145-s390] 163 * x-ibm-1146-s390 value: java.nio.charset.CharsetICU[x-ibm-1146-s390] 164 * x-ibm-1147-s390 value: java.nio.charset.CharsetICU[x-ibm-1147-s390] 165 * x-ibm-1148-s390 value: java.nio.charset.CharsetICU[x-ibm-1148-s390] 166 * x-ibm-1149-s390 value: java.nio.charset.CharsetICU[x-ibm-1149-s390] 167 * x-ibm-1153-s390 value: java.nio.charset.CharsetICU[x-ibm-1153-s390] 168 * x-ibm-1154_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-1154_P100-1999] 169 * x-ibm-1155_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-1155_P100-1999] 170 * x-ibm-1156_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-1156_P100-1999] 171 * x-ibm-1157_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-1157_P100-1999] 172 * x-ibm-1158_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-1158_P100-1999] 173 * x-ibm-1160_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-1160_P100-1999] 174 * x-ibm-1162_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-1162_P100-1999] 175 * x-ibm-1164_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-1164_P100-1999] 176 * x-ibm-1250_P100-1995 value: java.nio.charset.CharsetICU[x-ibm-1250_P100-1995] 177 * x-ibm-1251_P100-1995 value: java.nio.charset.CharsetICU[x-ibm-1251_P100-1995] 178 * x-ibm-1252_P100-2000 value: java.nio.charset.CharsetICU[x-ibm-1252_P100-2000] 179 * x-ibm-1253_P100-1995 value: java.nio.charset.CharsetICU[x-ibm-1253_P100-1995] 180 * x-ibm-1254_P100-1995 value: java.nio.charset.CharsetICU[x-ibm-1254_P100-1995] 181 * x-ibm-1255_P100-1995 value: java.nio.charset.CharsetICU[x-ibm-1255_P100-1995] 182 * x-ibm-1256_P110-1997 value: java.nio.charset.CharsetICU[x-ibm-1256_P110-1997] 183 * x-ibm-1257_P100-1995 value: java.nio.charset.CharsetICU[x-ibm-1257_P100-1995] 184 * x-ibm-1258_P100-1997 value: java.nio.charset.CharsetICU[x-ibm-1258_P100-1997] 185 * x-ibm-12712-s390 value: java.nio.charset.CharsetICU[x-ibm-12712-s390] 186 * x-ibm-12712_P100-1998 value: java.nio.charset.CharsetICU[x-ibm-12712_P100-1998] 187 * x-ibm-1373_P100-2002 value: java.nio.charset.CharsetICU[x-ibm-1373_P100-2002] 188 * x-ibm-1383_P110-1999 value: java.nio.charset.CharsetICU[x-ibm-1383_P110-1999] 189 * x-ibm-1386_P100-2001 value: java.nio.charset.CharsetICU[x-ibm-1386_P100-2001] 190 * x-ibm-16684_P110-2003 value: java.nio.charset.CharsetICU[x-ibm-16684_P110-2003] 191 * x-ibm-16804-s390 value: java.nio.charset.CharsetICU[x-ibm-16804-s390] 192 * x-ibm-16804_X110-1999 value: java.nio.charset.CharsetICU[x-ibm-16804_X110-1999] 193 * x-ibm-25546 value: java.nio.charset.CharsetICU[x-ibm-25546] 194 * x-ibm-33722_P12A_P12A-2009_U2 value: 195 * java.nio.charset.CharsetICU[x-ibm-33722_P12A_P12A-2009_U2] 196 * x-ibm-37-s390 value: java.nio.charset.CharsetICU[x-ibm-37-s390] 197 * x-ibm-4517_P100-2005 value: java.nio.charset.CharsetICU[x-ibm-4517_P100-2005] 198 * x-ibm-4899_P100-1998 value: java.nio.charset.CharsetICU[x-ibm-4899_P100-1998] 199 * x-ibm-4909_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-4909_P100-1999] 200 * x-ibm-4971_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-4971_P100-1999] 201 * x-ibm-5123_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-5123_P100-1999] 202 * x-ibm-5351_P100-1998 value: java.nio.charset.CharsetICU[x-ibm-5351_P100-1998] 203 * x-ibm-5352_P100-1998 value: java.nio.charset.CharsetICU[x-ibm-5352_P100-1998] 204 * x-ibm-5353_P100-1998 value: java.nio.charset.CharsetICU[x-ibm-5353_P100-1998] 205 * x-ibm-5478_P100-1995 value: java.nio.charset.CharsetICU[x-ibm-5478_P100-1995] 206 * x-ibm-803_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-803_P100-1999] 207 * x-ibm-813_P100-1995 value: java.nio.charset.CharsetICU[x-ibm-813_P100-1995] 208 * x-ibm-8482_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-8482_P100-1999] 209 * x-ibm-901_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-901_P100-1999] 210 * x-ibm-902_P100-1999 value: java.nio.charset.CharsetICU[x-ibm-902_P100-1999] 211 * x-ibm-9067_X100-2005 value: java.nio.charset.CharsetICU[x-ibm-9067_X100-2005] 212 * x-ibm-916_P100-1995 value: java.nio.charset.CharsetICU[x-ibm-916_P100-1995] 213 * x-IBM1006 value: java.nio.charset.CharsetICU[x-IBM1006] 214 * x-IBM1025 value: java.nio.charset.CharsetICU[x-IBM1025] 215 * x-IBM1097 value: java.nio.charset.CharsetICU[x-IBM1097] 216 * x-IBM1098 value: java.nio.charset.CharsetICU[x-IBM1098] 217 * x-IBM1112 value: java.nio.charset.CharsetICU[x-IBM1112] 218 * x-IBM1122 value: java.nio.charset.CharsetICU[x-IBM1122] 219 * x-IBM1123 value: java.nio.charset.CharsetICU[x-IBM1123] 220 * x-IBM1124 value: java.nio.charset.CharsetICU[x-IBM1124] 221 * x-IBM1153 value: java.nio.charset.CharsetICU[x-IBM1153] 222 * x-IBM1363 value: java.nio.charset.CharsetICU[x-IBM1363] 223 * x-IBM1364 value: java.nio.charset.CharsetICU[x-IBM1364] 224 * x-IBM1371 value: java.nio.charset.CharsetICU[x-IBM1371] 225 * x-IBM1388 value: java.nio.charset.CharsetICU[x-IBM1388] 226 * x-IBM1390 value: java.nio.charset.CharsetICU[x-IBM1390] 227 * x-IBM1399 value: java.nio.charset.CharsetICU[x-IBM1399] 228 * x-IBM33722 value: java.nio.charset.CharsetICU[x-IBM33722] 229 * x-IBM720 value: java.nio.charset.CharsetICU[x-IBM720] 230 * x-IBM737 value: java.nio.charset.CharsetICU[x-IBM737] 231 * x-IBM856 value: java.nio.charset.CharsetICU[x-IBM856] 232 * x-IBM867 value: java.nio.charset.CharsetICU[x-IBM867] 233 * x-IBM875 value: java.nio.charset.CharsetICU[x-IBM875] 234 * x-IBM922 value: java.nio.charset.CharsetICU[x-IBM922] 235 * x-IBM930 value: java.nio.charset.CharsetICU[x-IBM930] 236 * x-IBM933 value: java.nio.charset.CharsetICU[x-IBM933] 237 * x-IBM935 value: java.nio.charset.CharsetICU[x-IBM935] 238 * x-IBM937 value: java.nio.charset.CharsetICU[x-IBM937] 239 * x-IBM939 value: java.nio.charset.CharsetICU[x-IBM939] 240 * x-IBM942 value: java.nio.charset.CharsetICU[x-IBM942] 241 * x-IBM943 value: java.nio.charset.CharsetICU[x-IBM943] 242 * x-IBM949 value: java.nio.charset.CharsetICU[x-IBM949] 243 * x-IBM949C value: java.nio.charset.CharsetICU[x-IBM949C] 244 * x-IBM950 value: java.nio.charset.CharsetICU[x-IBM950] 245 * x-IBM954 value: java.nio.charset.CharsetICU[x-IBM954] 246 * x-IBM964 value: java.nio.charset.CharsetICU[x-IBM964] 247 * x-IBM970 value: java.nio.charset.CharsetICU[x-IBM970] 248 * x-IBM971 value: java.nio.charset.CharsetICU[x-IBM971] 249 * x-IMAP-mailbox-name value: java.nio.charset.CharsetICU[x-IMAP-mailbox-name] 250 * x-iscii-be value: java.nio.charset.CharsetICU[x-iscii-be] 251 * x-iscii-gu value: java.nio.charset.CharsetICU[x-iscii-gu] 252 * x-iscii-ka value: java.nio.charset.CharsetICU[x-iscii-ka] 253 * x-iscii-ma value: java.nio.charset.CharsetICU[x-iscii-ma] 254 * x-iscii-or value: java.nio.charset.CharsetICU[x-iscii-or] 255 * x-iscii-pa value: java.nio.charset.CharsetICU[x-iscii-pa] 256 * x-iscii-ta value: java.nio.charset.CharsetICU[x-iscii-ta] 257 * x-iscii-te value: java.nio.charset.CharsetICU[x-iscii-te] 258 * x-ISCII91 value: java.nio.charset.CharsetICU[x-ISCII91] 259 * x-ISO-2022-CN-CNS value: java.nio.charset.CharsetICU[x-ISO-2022-CN-CNS] 260 * x-iso-8859-11 value: java.nio.charset.CharsetICU[x-iso-8859-11] 261 * x-JavaUnicode value: java.nio.charset.CharsetICU[x-JavaUnicode] 262 * x-JavaUnicode2 value: java.nio.charset.CharsetICU[x-JavaUnicode2] 263 * x-JIS7 value: java.nio.charset.CharsetICU[x-JIS7] 264 * x-JIS8 value: java.nio.charset.CharsetICU[x-JIS8] 265 * x-LMBCS-1 value: java.nio.charset.CharsetICU[x-LMBCS-1] 266 * x-mac-centraleurroman value: java.nio.charset.CharsetICU[x-mac-centraleurroman] 267 * x-mac-cyrillic value: java.nio.charset.CharsetICU[x-mac-cyrillic] 268 * x-mac-greek value: java.nio.charset.CharsetICU[x-mac-greek] 269 * x-mac-turkish value: java.nio.charset.CharsetICU[x-mac-turkish] 270 * x-MS950-HKSCS value: java.nio.charset.CharsetICU[x-MS950-HKSCS] 271 * x-UnicodeBig value: java.nio.charset.CharsetICU[x-UnicodeBig] 272 * x-UTF-16LE-BOM value: java.nio.charset.CharsetICU[x-UTF-16LE-BOM] 273 * x-UTF16_OppositeEndian value: java.nio.charset.CharsetICU[x-UTF16_OppositeEndian] 274 * x-UTF16_PlatformEndian value: java.nio.charset.CharsetICU[x-UTF16_PlatformEndian] 275 * x-UTF32_OppositeEndian value: java.nio.charset.CharsetICU[x-UTF32_OppositeEndian] 276 * x-UTF32_PlatformEndian value: java.nio.charset.CharsetICU[x-UTF32_PlatformEndian] 277 * 278 */ 279 public static final int ANY_CHARSET = 0x00; 280 public static final int US_ASCII = 0x03; 281 public static final int ISO_8859_1 = 0x04; 282 public static final int ISO_8859_2 = 0x05; 283 public static final int ISO_8859_3 = 0x06; 284 public static final int ISO_8859_4 = 0x07; 285 public static final int ISO_8859_5 = 0x08; 286 public static final int ISO_8859_6 = 0x09; 287 public static final int ISO_8859_7 = 0x0A; 288 public static final int ISO_8859_8 = 0x0B; 289 public static final int ISO_8859_9 = 0x0C; 290 public static final int SHIFT_JIS = 0x11; 291 public static final int EUC_JP = 0x12; 292 public static final int EUC_KR = 0x26; 293 public static final int ISO_2022_JP = 0x27; 294 public static final int ISO_2022_JP_2 = 0x28; 295 public static final int UTF_8 = 0x6A; 296 public static final int GBK = 0x71; 297 public static final int GB18030 = 0x72; 298 public static final int GB2312 = 0x07E9; 299 public static final int BIG5 = 0x07EA; 300 public static final int UCS2 = 0x03E8; 301 public static final int UTF_16 = 0x03F7; 302 public static final int HZ_GB_2312 = 0x0825; 303 304 /** 305 * If the encoding of given data is unsupported, use UTF_8 to decode it. 306 */ 307 public static final int DEFAULT_CHARSET = UTF_8; 308 309 /** 310 * Array of MIB enum numbers. 311 */ 312 private static final int[] MIBENUM_NUMBERS = { 313 ANY_CHARSET, 314 US_ASCII, 315 ISO_8859_1, 316 ISO_8859_2, 317 ISO_8859_3, 318 ISO_8859_4, 319 ISO_8859_5, 320 ISO_8859_6, 321 ISO_8859_7, 322 ISO_8859_8, 323 ISO_8859_9, 324 SHIFT_JIS, 325 EUC_JP, 326 EUC_KR, 327 ISO_2022_JP, 328 ISO_2022_JP_2, 329 UTF_8, 330 GBK, 331 GB18030, 332 GB2312, 333 BIG5, 334 UCS2, 335 UTF_16, 336 HZ_GB_2312, 337 }; 338 339 /** 340 * The Well-known-charset Mime name. 341 */ 342 public static final String MIMENAME_ANY_CHARSET = "*"; 343 public static final String MIMENAME_US_ASCII = "us-ascii"; 344 public static final String MIMENAME_ISO_8859_1 = "iso-8859-1"; 345 public static final String MIMENAME_ISO_8859_2 = "iso-8859-2"; 346 public static final String MIMENAME_ISO_8859_3 = "iso-8859-3"; 347 public static final String MIMENAME_ISO_8859_4 = "iso-8859-4"; 348 public static final String MIMENAME_ISO_8859_5 = "iso-8859-5"; 349 public static final String MIMENAME_ISO_8859_6 = "iso-8859-6"; 350 public static final String MIMENAME_ISO_8859_7 = "iso-8859-7"; 351 public static final String MIMENAME_ISO_8859_8 = "iso-8859-8"; 352 public static final String MIMENAME_ISO_8859_9 = "iso-8859-9"; 353 public static final String MIMENAME_SHIFT_JIS = "shift_JIS"; 354 public static final String MIMENAME_EUC_JP = "euc-jp"; 355 public static final String MIMENAME_EUC_KR = "euc-kr"; 356 public static final String MIMENAME_ISO_2022_JP = "iso-2022-jp"; 357 public static final String MIMENAME_ISO_2022_JP_2 = "iso-2022-jp-2"; 358 public static final String MIMENAME_UTF_8 = "utf-8"; 359 public static final String MIMENAME_GBK = "gbk"; 360 public static final String MIMENAME_GB18030 = "gb18030"; 361 public static final String MIMENAME_GB2312 = "gb2312"; 362 public static final String MIMENAME_BIG5 = "big5"; 363 public static final String MIMENAME_UCS2 = "iso-10646-ucs-2"; 364 public static final String MIMENAME_UTF_16 = "utf-16"; 365 public static final String MIMENAME_HZ_GB_2312 = "hz-gb-2312"; 366 367 public static final String DEFAULT_CHARSET_NAME = MIMENAME_UTF_8; 368 369 /** 370 * Array of the names of character sets. 371 */ 372 private static final String[] MIME_NAMES = { 373 MIMENAME_ANY_CHARSET, 374 MIMENAME_US_ASCII, 375 MIMENAME_ISO_8859_1, 376 MIMENAME_ISO_8859_2, 377 MIMENAME_ISO_8859_3, 378 MIMENAME_ISO_8859_4, 379 MIMENAME_ISO_8859_5, 380 MIMENAME_ISO_8859_6, 381 MIMENAME_ISO_8859_7, 382 MIMENAME_ISO_8859_8, 383 MIMENAME_ISO_8859_9, 384 MIMENAME_SHIFT_JIS, 385 MIMENAME_EUC_JP, 386 MIMENAME_EUC_KR, 387 MIMENAME_ISO_2022_JP, 388 MIMENAME_ISO_2022_JP_2, 389 MIMENAME_UTF_8, 390 MIMENAME_GBK, 391 MIMENAME_GB18030, 392 MIMENAME_GB2312, 393 MIMENAME_BIG5, 394 MIMENAME_UCS2, 395 MIMENAME_UTF_16, 396 MIMENAME_HZ_GB_2312, 397 }; 398 399 private static final SparseArray<String> MIBENUM_TO_NAME_MAP; 400 401 private static final SimpleArrayMap<String, Integer> NAME_TO_MIBENUM_MAP; 402 403 static { 404 // Create the HashMaps. 405 MIBENUM_TO_NAME_MAP = new SparseArray<String>(); 406 NAME_TO_MIBENUM_MAP = new SimpleArrayMap<String, Integer>(); assert(MIBENUM_NUMBERS.length == MIME_NAMES.length)407 assert (MIBENUM_NUMBERS.length == MIME_NAMES.length); 408 final int count = MIBENUM_NUMBERS.length - 1; 409 for (int i = 0; i <= count; i++) { MIBENUM_TO_NAME_MAP.put(MIBENUM_NUMBERS[i], MIME_NAMES[i])410 MIBENUM_TO_NAME_MAP.put(MIBENUM_NUMBERS[i], MIME_NAMES[i]); NAME_TO_MIBENUM_MAP.put(MIME_NAMES[i], MIBENUM_NUMBERS[i])411 NAME_TO_MIBENUM_MAP.put(MIME_NAMES[i], MIBENUM_NUMBERS[i]); 412 } 413 } 414 CharacterSets()415 private CharacterSets() { 416 } // Non-instantiatable 417 418 /** 419 * Map an MIBEnum number to the name of the charset which this number 420 * is assigned to by IANA. 421 * 422 * @param mibEnumValue An IANA assigned MIBEnum number. 423 * @return The name string of the charset. 424 */ getMimeName(final int mibEnumValue)425 public static String getMimeName(final int mibEnumValue) 426 throws UnsupportedEncodingException { 427 final String name = MIBENUM_TO_NAME_MAP.get(mibEnumValue); 428 if (name == null) { 429 throw new UnsupportedEncodingException(); 430 } 431 return name; 432 } 433 434 /** 435 * Map a well-known charset name to its assigned MIBEnum number. 436 * 437 * @param mimeName The charset name. 438 * @return The MIBEnum number assigned by IANA for this charset. 439 */ getMibEnumValue(final String mimeName)440 public static int getMibEnumValue(final String mimeName) 441 throws UnsupportedEncodingException { 442 if (null == mimeName) { 443 return -1; 444 } 445 446 final Integer mibEnumValue = NAME_TO_MIBENUM_MAP.get(mimeName); 447 if (mibEnumValue == null) { 448 throw new UnsupportedEncodingException(); 449 } 450 return mibEnumValue; 451 } 452 } 453