1
1
/*
2
- * Copyright (c) 2002, 2013 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2002, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
25
25
26
26
package sun .nio .cs .ext ;
27
27
28
- import java .lang .ref .SoftReference ;
29
- import java .nio .charset .Charset ;
30
- import java .nio .charset .spi .CharsetProvider ;
31
28
import sun .nio .cs .AbstractCharsetProvider ;
32
29
import java .security .AccessController ;
30
+
33
31
import sun .security .action .GetPropertyAction ;
34
32
35
33
@@ -115,9 +113,11 @@ public ExtendedCharsets() {
115
113
"CP936"
116
114
});
117
115
116
+ // The definition of this charset may be overridden by the init method
117
+ // below, if the jdk.charset.GB18030 property is set
118
118
charset ("GB18030" , "GB18030" ,
119
119
new String [] {
120
- "gb18030-2000 "
120
+ "gb18030-2022 "
121
121
});
122
122
123
123
charset ("GB2312" , "EUC_CN" ,
@@ -1136,14 +1136,15 @@ public ExtendedCharsets() {
1136
1136
}
1137
1137
1138
1138
private boolean initialized = false ;
1139
+ private boolean isGB18030_2000 = false ;
1139
1140
1140
- // If the sun.nio.cs.map property is defined on the command line we won't
1141
- // see it in the system-properties table until after the charset subsystem
1142
- // has been initialized. We therefore delay the effect of this property
1143
- // until after the JRE has completely booted.
1141
+ // If the sun.nio.cs.map and/or jdk.charset.GB18030 properties are defined
1142
+ // on the command line we won't see them in the system-properties table until
1143
+ // after the charset subsystem has been initialized. We therefore delay
1144
+ // the effect of these property until after the JRE has completely booted.
1144
1145
//
1145
- // At the moment following values for this property are supported, property
1146
- // value string is case insensitive.
1146
+ // At the moment the following values for the sun.nio.cs.map property are
1147
+ // supported and the property value string is case insensitive.
1147
1148
//
1148
1149
// (1)"Windows-31J/Shift_JIS"
1149
1150
// In 1.4.1 we added a correct implementation of the Shift_JIS charset
@@ -1176,6 +1177,10 @@ public ExtendedCharsets() {
1176
1177
// where each charset named to the left of a slash is intended to replace
1177
1178
// (most) uses of the charset named to the right of the slash.
1178
1179
//
1180
+ // The jdk.charset.GB18030 property is simpler and accepts only the value
1181
+ // "2000". If this value is given, the older GB18030-2000 variant of the
1182
+ // character set replaces the default GB18030-2022 variant.
1183
+ //
1179
1184
protected void init () {
1180
1185
if (initialized )
1181
1186
return ;
@@ -1184,6 +1189,8 @@ protected void init() {
1184
1189
1185
1190
String map = AccessController .doPrivileged (
1186
1191
new GetPropertyAction ("sun.nio.cs.map" ));
1192
+ boolean isGB18030_2000 = "2000" .equals (AccessController .doPrivileged (
1193
+ new GetPropertyAction ("jdk.charset.GB18030" )));
1187
1194
boolean sjisIsMS932 = false ;
1188
1195
boolean iso2022jpIsMS50221 = false ;
1189
1196
boolean iso2022jpIsMS50220 = false ;
@@ -1202,6 +1209,16 @@ protected void init() {
1202
1209
}
1203
1210
}
1204
1211
}
1212
+ if (isGB18030_2000 ) {
1213
+ deleteCharset ("GB18030" ,
1214
+ new String [] {
1215
+ "gb18030-2022"
1216
+ });
1217
+ charset ("GB18030" , "GB18030" ,
1218
+ new String [] {
1219
+ "gb18030-2000"
1220
+ });
1221
+ }
1205
1222
if (sjisIsMS932 ) {
1206
1223
deleteCharset ("Shift_JIS" ,
1207
1224
new String [] {
@@ -1314,6 +1331,7 @@ protected void init() {
1314
1331
"x-compound-text"
1315
1332
});
1316
1333
}
1334
+ this .isGB18030_2000 = isGB18030_2000 ;
1317
1335
initialized = true ;
1318
1336
}
1319
1337
@@ -1322,4 +1340,14 @@ public static String[] aliasesFor(String charsetName) {
1322
1340
return null ;
1323
1341
return instance .aliases (charsetName );
1324
1342
}
1343
+
1344
+ static boolean IS_2000 () {
1345
+ if (instance == null ) {
1346
+ return false ;
1347
+ }
1348
+ if (!instance .initialized ) {
1349
+ instance .init ();
1350
+ }
1351
+ return instance .isGB18030_2000 ;
1352
+ }
1325
1353
}
0 commit comments