Enable supported ECI charsets dynamically (#1625)

* Enable supported ECI charsets dynamically

* Remove use of Java 9+ API

* Remove property-based override for dynamic ECI charsets
This commit is contained in:
Daniel Gredler 2023-05-22 18:53:35 -04:00 committed by GitHub
parent c062955c84
commit b892c401c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View file

@ -38,14 +38,14 @@ public enum CharacterSetECI {
ISO8859_3(5, "ISO-8859-3"), ISO8859_3(5, "ISO-8859-3"),
ISO8859_4(6, "ISO-8859-4"), ISO8859_4(6, "ISO-8859-4"),
ISO8859_5(7, "ISO-8859-5"), ISO8859_5(7, "ISO-8859-5"),
// ISO8859_6(8, "ISO-8859-6"), ISO8859_6(8, "ISO-8859-6"),
ISO8859_7(9, "ISO-8859-7"), ISO8859_7(9, "ISO-8859-7"),
// ISO8859_8(10, "ISO-8859-8"), ISO8859_8(10, "ISO-8859-8"),
ISO8859_9(11, "ISO-8859-9"), ISO8859_9(11, "ISO-8859-9"),
// ISO8859_10(12, "ISO-8859-10"), ISO8859_10(12, "ISO-8859-10"),
// ISO8859_11(13, "ISO-8859-11"), ISO8859_11(13, "ISO-8859-11"),
ISO8859_13(15, "ISO-8859-13"), ISO8859_13(15, "ISO-8859-13"),
// ISO8859_14(16, "ISO-8859-14"), ISO8859_14(16, "ISO-8859-14"),
ISO8859_15(17, "ISO-8859-15"), ISO8859_15(17, "ISO-8859-15"),
ISO8859_16(18, "ISO-8859-16"), ISO8859_16(18, "ISO-8859-16"),
SJIS(20, "Shift_JIS"), SJIS(20, "Shift_JIS"),
@ -60,10 +60,12 @@ public enum CharacterSetECI {
GB18030(29, "GB2312", "EUC_CN", "GBK"), GB18030(29, "GB2312", "EUC_CN", "GBK"),
EUC_KR(30, "EUC-KR"); EUC_KR(30, "EUC-KR");
// only character sets supported by the current JVM are registered here
private static final Map<Integer,CharacterSetECI> VALUE_TO_ECI = new HashMap<>(); private static final Map<Integer,CharacterSetECI> VALUE_TO_ECI = new HashMap<>();
private static final Map<String,CharacterSetECI> NAME_TO_ECI = new HashMap<>(); private static final Map<String,CharacterSetECI> NAME_TO_ECI = new HashMap<>();
static { static {
for (CharacterSetECI eci : values()) { for (CharacterSetECI eci : values()) {
if (Charset.isSupported(eci.name())) {
for (int value : eci.values) { for (int value : eci.values) {
VALUE_TO_ECI.put(value, eci); VALUE_TO_ECI.put(value, eci);
} }
@ -73,6 +75,7 @@ public enum CharacterSetECI {
} }
} }
} }
}
private final int[] values; private final int[] values;
private final String[] otherEncodingNames; private final String[] otherEncodingNames;

View file

@ -500,7 +500,7 @@ public final class HighLevelEncodeTestCase extends Assert {
"\u062C\u064E\u0651\u0627\u0635 (\u02BE\u0101\u1E63) \"pear\", suggested to have originated from Hebrew " + "\u062C\u064E\u0651\u0627\u0635 (\u02BE\u0101\u1E63) \"pear\", suggested to have originated from Hebrew " +
"\u05D0\u05B7\u05D2\u05B8\u05BC\u05E1 (ag\u00E1s)")); "\u05D0\u05B7\u05D2\u05B8\u05BC\u05E1 (ag\u00E1s)"));
assertEquals("239 209 151 206 214 92 122 140 35 158 144 162 52 205 55 171 137 23 67 206 218 175 147 113 15 254" + assertEquals("239 209 151 206 214 92 122 140 35 158 144 162 52 205 55 171 137 23 67 206 218 175 147 113 15 254" +
" 116 33 241 25 231 186 14 212 64 253 151 252 159 33 41 241 27 231 83 171 53 209 35 25 134 6 42 33 35 239 184" + " 116 33 241 9 231 186 14 206 64 248 144 252 159 33 41 241 27 231 83 171 53 209 35 25 134 6 42 33 35 239 184" +
" 31 193 234 7 252 205 101 127 241 209 34 24 5 22 23 221 148 179 239 128 140 92 187 106 204 198 59 19 25 114" + " 31 193 234 7 252 205 101 127 241 209 34 24 5 22 23 221 148 179 239 128 140 92 187 106 204 198 59 19 25 114" +
" 248 118 36 254 231 106 196 19 239 101 27 107 69 189 112 236 156 252 16 174 125 24 10 125 116 42 129", " 248 118 36 254 231 106 196 19 239 101 27 107 69 189 112 236 156 252 16 174 125 24 10 125 116 42 129",
visualized); visualized);