📄 charsets.java
字号:
/*
* @(#)Charsets.java
*
* Copyright (C) 2005 Sergey Bredikhin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*/
package olivax.webmail;
import java.util.Comparator;
import java.util.Hashtable;
public class Charsets {
public static final String Global[][] = { { "UTF-8", "utf-8" },
{ "UTF-16", "utf-16" }, { "US-ASCII", "us-ascii" } };
public static final String WestEuropean[][] = {
{ "Western (Windows-1252)", "windows-1252" },
{ "Western (ISO-8859-1)", "iso-8859-1" },
{ "Western (ISO-8859-15)", "iso-8859-15" },
{ "Greek (ISO-8859-7)", "iso-8859-7" },
{ "Greek (Windows-1253)", "windows-1253" },
{ "South European (ISO-8859-3)", "iso-8859-3" } };
public static final String EastEuropean[][] = {
{ "Baltic (ISO-8859-4)", "iso-8859-4" },
{ "Baltic (ISO-8859-13)", "iso-8859-13" },
{ "Baltic (Windows-1257)", "windows-1257" },
{ "Central European (ISO-8859-2)", "iso-8859-2" },
{ "Cyrillic (ISO-8859-5)", "iso-8859-5" },
{ "Cyrillic (KOI8-R)", "koi8-r" },
{ "Cyrillic (Windows-1251)", "windows-1251" } };
public static final String EastAsian[][] = {
{ "Chinese (EUC-CN)", "EUC-CN" },
{ "Chinese Simplified (GBK)", "GBK" },
{ "Chinese Simplified (GB18030)", "GB18030" },
{ "Chinese Traditional (Big5)", "Big5" },
{ "Chinese Traditional (Big5-HKSCS)", "Big5-HKSCS" },
{ "Taiwanese (EUC-TW)", "EUC-TW" },
{ "Japanese (EUC-JP)", "EUC-JP" },
{ "Japanese (Shift_JIS)", "Shift_JIS" },
{ "Japanese (ISO-2022-JP)", "ISO-2022-JP" },
{ "Windows (31J)", "31J" }, { "Korean (EUC-KR)", "EUC-KR" },
{ "Korean (JOHAB)", "JOHAB" },
{ "Korean (ISO-2022-KR)", "ISO-2022-KR" } };
public static final String SeAndSwAsian[][] = {
{ "Thai (TIS-620)", "TIS-620" },
{ "Turkish (ISO-8859-9)", "ISO-8859-9" },
{ "Turkish (Windows-1254)", "windows-1254" },
{ "Vietnamese (Windows-1258)", "windows-1258" } };
private static void populateFromArray(Hashtable ht,
String[][] array, boolean reverse) {
for (int i = 0; i < array.length; i++) {
if(reverse) {
ht.put(array[i][1], array[i][0]);
} else {
ht.put(array[i][0], array[i][1]);
}
}
}
private static Hashtable getHashtable(boolean reverse) {
Hashtable result = new Hashtable(Global.length + WestEuropean.length
+ EastEuropean.length + EastAsian.length + SeAndSwAsian.length);
populateFromArray(result, Global, reverse);
populateFromArray(result, WestEuropean, reverse);
populateFromArray(result, EastEuropean, reverse);
populateFromArray(result, EastAsian, reverse);
populateFromArray(result, SeAndSwAsian, reverse);
return result;
}
private static final Hashtable htCharsets = getHashtable(false);
private static final Hashtable htRevCharsets = getHashtable(true);
public static String getCpForName(String name) {
return (String)htCharsets.get(name);
}
public static String getNameForCp(String cp) {
String name = (String)htRevCharsets.get(cp);
if(name == null)
name = cp;
return name;
}
public static String[] getCpArray() {
String cps[] = new String[Global.length + WestEuropean.length
+ EastEuropean.length + EastAsian.length + SeAndSwAsian.length];
System.arraycopy(getCpArray(Global), 0, cps, 0, Global.length);
System.arraycopy(getCpArray(WestEuropean), 0, cps, Global.length,
WestEuropean.length);
System.arraycopy(getCpArray(EastEuropean), 0, cps, Global.length
+ WestEuropean.length, EastEuropean.length);
System.arraycopy(getCpArray(EastAsian), 0, cps, Global.length
+ WestEuropean.length + EastEuropean.length, EastAsian.length);
System.arraycopy(getCpArray(SeAndSwAsian), 0, cps, Global.length
+ WestEuropean.length + EastEuropean.length + EastAsian.length,
SeAndSwAsian.length);
return cps;
}
private static String[] getCpArray(String[][] cps) {
String[] res = new String[cps.length];
for(int i = 0; i < cps.length; i++) {
res[i] = cps[i][1];
}
return res;
}
public static String[] getCpArraySorted() {
String[] result = getCpArray();
java.util.Arrays.sort(result, new Comparator() {
public int compare(Object a, Object b) {
String o1 = (String) a;
String o2 = (String) b;
return o1.compareToIgnoreCase(o2);
}
});
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -