01: package com.bostechcorp.cbesb.common.util;
02:
03: import java.nio.charset.Charset;
04: import java.util.Arrays;
05: import java.util.Collection;
06: import java.util.Collections;
07: import java.util.Iterator;
08: import java.util.List;
09: import java.util.Set;
10: import java.util.SortedMap;
11:
12: public class SystemCharacterEncoding {
13:
14: static public String[] getSupportedCharacterSets() {
15: SortedMap<String, Charset> characterSets = Charset
16: .availableCharsets();
17: Set<String> names = characterSets.keySet();
18: int numSets = names.size();
19: String[] result = new String[numSets + 1];
20: int index = 0;
21: for (Iterator<String> iter = names.iterator(); iter.hasNext();) {
22: String charSetName = iter.next();
23: Charset cs = characterSets.get(charSetName);
24: result[index++] = cs.displayName();
25: }
26: //adding also SYSTEM_DEFAULT
27: result[numSets] = "SYSTEM_DEFAULT";
28:
29: return result;
30: // return sort(result);
31: }
32:
33: static public String[] sort(String[] input) {
34: List<String> list = Arrays.asList(input);
35: Collections.sort(list);
36: return (String[]) list.toArray();
37: }
38:
39: static public void main(String[] argsv) {
40:
41: String[] charSets = getSupportedCharacterSets();
42:
43: for (int i = 0; i < charSets.length; i++) {
44: System.out.println("chars: " + charSets[i]);
45: }
46: }
47:
48: }
|