1
16
17 package com.google.zxing.common;
18
19 import com.google.zxing.FormatException;
20
21 import java.nio.charset.Charset;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26
32 public enum CharacterSetECI {
33
34
35 Cp437(new int[]{0,2}),
36 ISO8859_1(new int[]{1,3}, "ISO-8859-1"),
37 ISO8859_2(4, "ISO-8859-2"),
38 ISO8859_3(5, "ISO-8859-3"),
39 ISO8859_4(6, "ISO-8859-4"),
40 ISO8859_5(7, "ISO-8859-5"),
41
42 ISO8859_7(9, "ISO-8859-7"),
43
44 ISO8859_9(11, "ISO-8859-9"),
45
46
47 ISO8859_13(15, "ISO-8859-13"),
48
49 ISO8859_15(17, "ISO-8859-15"),
50 ISO8859_16(18, "ISO-8859-16"),
51 SJIS(20, "Shift_JIS"),
52 Cp1250(21, "windows-1250"),
53 Cp1251(22, "windows-1251"),
54 Cp1252(23, "windows-1252"),
55 Cp1256(24, "windows-1256"),
56 UnicodeBigUnmarked(25, "UTF-16BE", "UnicodeBig"),
57 UTF8(26, "UTF-8"),
58 ASCII(new int[] {27, 170}, "US-ASCII"),
59 Big5(28),
60 GB18030(29, "GB2312", "EUC_CN", "GBK"),
61 EUC_KR(30, "EUC-KR");
62
63 private static final Map<Integer,CharacterSetECI> VALUE_TO_ECI = new HashMap<>();
64 private static final Map<String,CharacterSetECI> NAME_TO_ECI = new HashMap<>();
65 static {
66 for (CharacterSetECI eci : values()) {
67 for (int value : eci.values) {
68 VALUE_TO_ECI.put(value, eci);
69 }
70 NAME_TO_ECI.put(eci.name(), eci);
71 for (String name : eci.otherEncodingNames) {
72 NAME_TO_ECI.put(name, eci);
73 }
74 }
75 }
76
77 private final int[] values;
78 private final String[] otherEncodingNames;
79
80 CharacterSetECI(int value) {
81 this(new int[] {value});
82 }
83
84 CharacterSetECI(int value, String... otherEncodingNames) {
85 this.values = new int[] {value};
86 this.otherEncodingNames = otherEncodingNames;
87 }
88
89 CharacterSetECI(int[] values, String... otherEncodingNames) {
90 this.values = values;
91 this.otherEncodingNames = otherEncodingNames;
92 }
93
94 public int getValue() {
95 return values[0];
96 }
97
98 public Charset getCharset() {
99 return Charset.forName(name());
100 }
101
102
107 public static CharacterSetECI getCharacterSetECI(Charset charset) {
108 return NAME_TO_ECI.get(charset.name());
109 }
110
111
117 public static CharacterSetECI getCharacterSetECIByValue(int value) throws FormatException {
118 if (value < 0 || value >= 900) {
119 throw FormatException.getFormatInstance();
120 }
121 return VALUE_TO_ECI.get(value);
122 }
123
124
129 public static CharacterSetECI getCharacterSetECIByName(String name) {
130 return NAME_TO_ECI.get(name);
131 }
132
133 }
134