CharacterEncoding.java 42.4 KB
Newer Older
D
duke 已提交
1
/*
S
sherman 已提交
2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.  Oracle designates this
D
duke 已提交
8
 * particular file as subject to the "Classpath" exception as provided
9
 * by Oracle in the LICENSE file that accompanied this code.
D
duke 已提交
10 11 12 13 14 15 16 17 18 19 20
 *
 * This code 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
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
21 22 23
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
 */

package sun.io;

import java.util.Collections;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.security.action.GetPropertyAction;

/*
 * This class is public in sun.io, so other sun.* packages (such as
 * HotJava) can use it, without exposing it to java.*.
 * Translates IANA encoding name to the string which is the part of
 * converter class.
 */

/**
 * @deprecated Replaced by {@link java.nio.charset}.  THIS API WILL BE
 * REMOVED IN J2SE 1.6.
 */
@Deprecated
public class CharacterEncoding {

    private static boolean sjisIsMS932;

53
    private static Map<String,String> aliasTable;
D
duke 已提交
54 55 56
    private static volatile boolean installedAll;

    static {
57
        aliasTable = new HashMap<>(460, 1.0f);                    /* MDA */
D
duke 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

        aliasTable.put("us-ascii",              "ASCII");
        aliasTable.put("ascii",                 "ASCII");
        aliasTable.put("646",                   "ASCII");       // Solaris POSIX locale
        aliasTable.put("iso_646.irv:1983",      "ASCII");       // Linux POSIX locale
        aliasTable.put("ansi_x3.4-1968",        "ASCII");       // Caldera linux
        aliasTable.put("iso646-us",             "ASCII");
        aliasTable.put("default",               "ASCII");       // compatibility with obsolete "Default" converters
        aliasTable.put("ascii7",                "ASCII");       // compatibility with obsolete "Default" converters

        // Core encodings
        aliasTable.put("8859_1",                "ISO8859_1");
        aliasTable.put("iso8859_1",             "ISO8859_1");
        aliasTable.put("utf-8",                 "UTF8");
        aliasTable.put("utf8",                  "UTF8");
        aliasTable.put("utf-16le",              "UnicodeLittleUnmarked");

        // Standard encodings used on Solaris and Linux
        aliasTable.put("iso8859-1",             "ISO8859_1");
        aliasTable.put("iso8859-2",             "ISO8859_2");
        aliasTable.put("iso8859-4",             "ISO8859_4");
        aliasTable.put("iso8859-5",             "ISO8859_5");
        aliasTable.put("iso8859-6",             "ISO8859_6");
        aliasTable.put("iso8859-8",             "ISO8859_8");
        aliasTable.put("iso8859-9",             "ISO8859_9");
        aliasTable.put("iso8859-13",            "ISO8859_13");
        aliasTable.put("iso8859-15",            "ISO8859_15");
        aliasTable.put("5601",                  "EUC_KR");
        aliasTable.put("ansi-1251",             "Cp1251");
        aliasTable.put("big5",                  "Big5");
        aliasTable.put("big5hk",                "Big5_HKSCS");
        aliasTable.put("eucjp",                 "EUC_JP");
        aliasTable.put("cns11643",              "EUC_TW");
        aliasTable.put("gb2312",                "EUC_CN");
        aliasTable.put("gb18030",               "GB18030");
        aliasTable.put("gbk",                   "GBK");
        aliasTable.put("koi8-r",                "KOI8_R");
        aliasTable.put("tis620.2533",           "TIS620");

        // Windows encodings
        aliasTable.put("cp1250",                "Cp1250");
        aliasTable.put("cp1251",                "Cp1251");
        aliasTable.put("cp1252",                "Cp1252");
        aliasTable.put("cp1253",                "Cp1253");
        aliasTable.put("cp1254",                "Cp1254");
        aliasTable.put("cp1255",                "Cp1255");
        aliasTable.put("cp1256",                "Cp1256");
        aliasTable.put("cp1257",                "Cp1257");
        aliasTable.put("cp1258",                "Cp1258");
        aliasTable.put("ms874",                 "MS874");
        aliasTable.put("ms932",                 "MS932");
        aliasTable.put("ms949",                 "MS949");
        aliasTable.put("ms950",                 "MS950");
        aliasTable.put("ms1361",                "MS1361");
    }

    public static String aliasName(String name){

        if (name.startsWith("\1")) {
            // Emergency access to old converters
            name = name.substring(1);
        }
        // need to use Locale.US so we can load ISO converters in tr_TR locale
        String lower = name.toLowerCase(Locale.US);
122
        String val = aliasTable.get(lower);
D
duke 已提交
123 124 125

        if (val == null && !installedAll) {
            installAll();
126
            val = aliasTable.get(lower);
D
duke 已提交
127 128 129 130 131 132 133
        }
        return val;
    }

    private static synchronized void installAll() {
        if (!installedAll) {
            GetPropertyAction a = new GetPropertyAction("sun.nio.cs.map");
134
            String map = AccessController.doPrivileged(a);
D
duke 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
            if (map != null) {
                sjisIsMS932 = map.equalsIgnoreCase("Windows-31J/Shift_JIS");
            } else {
                sjisIsMS932 = false;
            }

            // MIBenum: 4
            aliasTable.put("8859_1",                "ISO8859_1");
            aliasTable.put("iso_8859-1:1987",       "ISO8859_1");
            aliasTable.put("iso-ir-100",            "ISO8859_1");
            aliasTable.put("iso_8859-1",            "ISO8859_1");
            aliasTable.put("iso-8859-1",            "ISO8859_1");
            aliasTable.put("iso8859-1",             "ISO8859_1");
            aliasTable.put("latin1",                "ISO8859_1");
            aliasTable.put("l1",                    "ISO8859_1");
            aliasTable.put("ibm819",                "ISO8859_1");
            aliasTable.put("ibm-819",               "ISO8859_1");
            aliasTable.put("cp819",                 "ISO8859_1");
            aliasTable.put("819",                   "ISO8859_1");
            aliasTable.put("csisolatin1",           "ISO8859_1");

            // MIBenum: 5
            aliasTable.put("8859_2",                "ISO8859_2");
            aliasTable.put("iso_8859-2:1987",       "ISO8859_2");
            aliasTable.put("iso-ir-101",            "ISO8859_2");
            aliasTable.put("iso_8859-2",            "ISO8859_2");
            aliasTable.put("iso-8859-2",            "ISO8859_2");
            aliasTable.put("iso8859-2",             "ISO8859_2");
            aliasTable.put("latin2",                "ISO8859_2");
            aliasTable.put("l2",                    "ISO8859_2");
            aliasTable.put("ibm912",                "ISO8859_2");
            aliasTable.put("ibm-912",               "ISO8859_2");
            aliasTable.put("cp912",                 "ISO8859_2");
            aliasTable.put("912",                   "ISO8859_2");
            aliasTable.put("csisolatin2",           "ISO8859_2");

            // MIBenum: 6
            aliasTable.put("8859_3",                "ISO8859_3");
            aliasTable.put("iso_8859-3:1988",       "ISO8859_3");
            aliasTable.put("iso-ir-109",            "ISO8859_3");
            aliasTable.put("iso_8859-3",            "ISO8859_3");
            aliasTable.put("iso-8859-3",            "ISO8859_3");
            aliasTable.put("iso8859-3",             "ISO8859_3");
            aliasTable.put("latin3",                "ISO8859_3");
            aliasTable.put("l3",                    "ISO8859_3");
            aliasTable.put("ibm913",                "ISO8859_3");
            aliasTable.put("ibm-913",               "ISO8859_3");
            aliasTable.put("cp913",                 "ISO8859_3");
            aliasTable.put("913",                   "ISO8859_3");
            aliasTable.put("csisolatin3",           "ISO8859_3");

            // MIBenum: 7
            aliasTable.put("8859_4",                "ISO8859_4");
            aliasTable.put("iso_8859-4:1988",       "ISO8859_4");
            aliasTable.put("iso-ir-110",            "ISO8859_4");
            aliasTable.put("iso_8859-4",            "ISO8859_4");
            aliasTable.put("iso-8859-4",            "ISO8859_4");
            aliasTable.put("iso8859-4",             "ISO8859_4");
            aliasTable.put("latin4",                "ISO8859_4");
            aliasTable.put("l4",                    "ISO8859_4");
            aliasTable.put("ibm914",                "ISO8859_4");
            aliasTable.put("ibm-914",               "ISO8859_4");
            aliasTable.put("cp914",                 "ISO8859_4");
            aliasTable.put("914",                   "ISO8859_4");
            aliasTable.put("csisolatin4",           "ISO8859_4");

            // MIBenum: 8
            aliasTable.put("8859_5",                "ISO8859_5");
            aliasTable.put("iso_8859-5:1988",       "ISO8859_5");
            aliasTable.put("iso-ir-144",            "ISO8859_5");
            aliasTable.put("iso_8859-5",            "ISO8859_5");
            aliasTable.put("iso-8859-5",            "ISO8859_5");
            aliasTable.put("iso8859-5",             "ISO8859_5");
            aliasTable.put("cyrillic",              "ISO8859_5");
            aliasTable.put("csisolatincyrillic",    "ISO8859_5");
            aliasTable.put("ibm915",                "ISO8859_5");
            aliasTable.put("ibm-915",               "ISO8859_5");
            aliasTable.put("cp915",                 "ISO8859_5");
            aliasTable.put("915",                   "ISO8859_5");

            // MIBenum: 9
            aliasTable.put("8859_6",                "ISO8859_6");
            aliasTable.put("iso_8859-6:1987",       "ISO8859_6");
            aliasTable.put("iso-ir-127",            "ISO8859_6");
            aliasTable.put("iso_8859-6",            "ISO8859_6");
            aliasTable.put("iso-8859-6",            "ISO8859_6");
            aliasTable.put("iso8859-6",             "ISO8859_6");
            aliasTable.put("ecma-114",              "ISO8859_6");
            aliasTable.put("asmo-708",              "ISO8859_6");
            aliasTable.put("arabic",                "ISO8859_6");
            aliasTable.put("csisolatinarabic",      "ISO8859_6");
            aliasTable.put("ibm1089",               "ISO8859_6");
            aliasTable.put("ibm-1089",              "ISO8859_6");
            aliasTable.put("cp1089",                "ISO8859_6");
            aliasTable.put("1089",                  "ISO8859_6");

            // MIBenum: 10
            aliasTable.put("8859_7",                "ISO8859_7");
            aliasTable.put("iso_8859-7:1987",       "ISO8859_7");
            aliasTable.put("iso-ir-126",            "ISO8859_7");
            aliasTable.put("iso_8859-7",            "ISO8859_7");
            aliasTable.put("iso-8859-7",            "ISO8859_7");
            aliasTable.put("iso8859-7",             "ISO8859_7");
            aliasTable.put("elot_928",              "ISO8859_7");
            aliasTable.put("ecma-118",              "ISO8859_7");
            aliasTable.put("greek",                 "ISO8859_7");
            aliasTable.put("greek8",                "ISO8859_7");
            aliasTable.put("csisolatingreek",       "ISO8859_7");
            aliasTable.put("ibm813",                "ISO8859_7");
            aliasTable.put("ibm-813",               "ISO8859_7");
            aliasTable.put("cp813",                 "ISO8859_7");
            aliasTable.put("813",                   "ISO8859_7");
            aliasTable.put("sun_eu_greek",          "ISO8859_7");

            // MIBenum: 11
            aliasTable.put("8859_8",                "ISO8859_8");
            aliasTable.put("iso_8859-8:1988",       "ISO8859_8");
            aliasTable.put("iso-ir-138",            "ISO8859_8");
            aliasTable.put("iso_8859-8",            "ISO8859_8");
            aliasTable.put("iso-8859-8",            "ISO8859_8");
            aliasTable.put("iso8859-8",             "ISO8859_8");
            aliasTable.put("hebrew",                "ISO8859_8");
            aliasTable.put("csisolatinhebrew",      "ISO8859_8");
            aliasTable.put("ibm916",                "ISO8859_8");
            aliasTable.put("ibm-916",               "ISO8859_8");
            aliasTable.put("cp916",                 "ISO8859_8");
            aliasTable.put("916",                   "ISO8859_8");

            // MIBenum: 12
            aliasTable.put("8859_9",                "ISO8859_9");
            aliasTable.put("iso-ir-148",            "ISO8859_9");
            aliasTable.put("iso_8859-9",            "ISO8859_9");
            aliasTable.put("iso-8859-9",            "ISO8859_9");
            aliasTable.put("iso8859-9",             "ISO8859_9");
            aliasTable.put("latin5",                "ISO8859_9");
            aliasTable.put("l5",                    "ISO8859_9");
            aliasTable.put("ibm920",                "ISO8859_9");
            aliasTable.put("ibm-920",               "ISO8859_9");
            aliasTable.put("cp920",                 "ISO8859_9");
            aliasTable.put("920",                   "ISO8859_9");
            aliasTable.put("csisolatin5",           "ISO8859_9");

            // MIBenum: ???
            aliasTable.put("8859_13",               "ISO8859_13");
            aliasTable.put("iso_8859-13",           "ISO8859_13");
            aliasTable.put("iso-8859-13",           "ISO8859_13");
            aliasTable.put("iso8859-13",            "ISO8859_13");


            // MIBenum: ????
            aliasTable.put("8859_15",               "ISO8859_15");
            aliasTable.put("iso-8859-15",           "ISO8859_15");
            aliasTable.put("iso_8859-15",           "ISO8859_15");
            aliasTable.put("iso8859-15",            "ISO8859_15");
            aliasTable.put("ibm923",                "ISO8859_15");
            aliasTable.put("ibm-923",               "ISO8859_15");
            aliasTable.put("cp923",                 "ISO8859_15");
            aliasTable.put("923",                   "ISO8859_15");
            aliasTable.put("latin0",                "ISO8859_15");
            aliasTable.put("latin9",                "ISO8859_15");
            aliasTable.put("csisolatin0",           "ISO8859_15");
            aliasTable.put("csisolatin9",           "ISO8859_15");

            //For compatibility purpose
            aliasTable.put("iso8859_15_fdis",       "ISO8859_15");

            // MIBenum: 106
            aliasTable.put("utf-8",                 "UTF8");

            // Alias recommended in RFC 1641
            aliasTable.put("unicode-1-1-utf-8",     "UTF8");

            // MIBenum: 1010
            aliasTable.put("unicode-1-1",           "UnicodeBigUnmarked");

            // MIBenum: 1000
            aliasTable.put("iso-10646-ucs-2",       "UnicodeBigUnmarked");

            // Per Unicode standard
            aliasTable.put("utf-16be",              "UnicodeBigUnmarked");
            aliasTable.put("utf-16le",              "UnicodeLittleUnmarked");
            aliasTable.put("utf-16",                "UTF16");

            // Used by drag-and-drop subsystem
            aliasTable.put("x-utf-16be",            "UnicodeBigUnmarked");
            aliasTable.put("x-utf-16le",            "UnicodeLittleUnmarked");

            aliasTable.put("unicode",               "Unicode");

            // MIBenum: ????
            aliasTable.put("ibm037",                "Cp037");
            aliasTable.put("ibm-037",               "Cp037");
            aliasTable.put("cp037",                 "Cp037");
            aliasTable.put("037",                   "Cp037");

            // MIBenum: ????
            aliasTable.put("ibm273",                "Cp273");
            aliasTable.put("ibm-273",               "Cp273");
            aliasTable.put("cp273",                 "Cp273");
            aliasTable.put("273",                   "Cp273");

            // MIBenum: ????
            aliasTable.put("ibm277",                "Cp277");
            aliasTable.put("ibm-277",               "Cp277");
            aliasTable.put("cp277",                 "Cp277");
            aliasTable.put("277",                   "Cp277");

            // MIBenum: ????
            aliasTable.put("ibm278",                "Cp278");
            aliasTable.put("ibm-278",               "Cp278");
            aliasTable.put("cp278",                 "Cp278");
            aliasTable.put("278",                   "Cp278");

            // MIBenum: ????
            aliasTable.put("ibm280",                "Cp280");
            aliasTable.put("ibm-280",               "Cp280");
            aliasTable.put("cp280",                 "Cp280");
            aliasTable.put("280",                   "Cp280");

            // MIBenum: ????
            aliasTable.put("ibm284",                "Cp284");
            aliasTable.put("ibm-284",               "Cp284");
            aliasTable.put("cp284",                 "Cp284");
            aliasTable.put("284",                   "Cp284");

            // MIBenum: ????
            aliasTable.put("ibm285",                "Cp285");
            aliasTable.put("ibm-285",               "Cp285");
            aliasTable.put("cp285",                 "Cp285");
            aliasTable.put("285",                   "Cp285");

            // MIBenum: ????
            aliasTable.put("ibm297",                "Cp297");
            aliasTable.put("ibm-297",               "Cp297");
            aliasTable.put("cp297",                 "Cp297");
            aliasTable.put("297",                   "Cp297");

            // MIBenum: ????
            aliasTable.put("ibm420",                "Cp420");
            aliasTable.put("ibm-420",               "Cp420");
            aliasTable.put("cp420",                 "Cp420");
            aliasTable.put("420",                   "Cp420");

            // MIBenum: ????
            aliasTable.put("ibm424",                "Cp424");
            aliasTable.put("ibm-424",               "Cp424");
            aliasTable.put("cp424",                 "Cp424");
            aliasTable.put("424",                   "Cp424");

            // MIBenum: 2011
            aliasTable.put("ibm437",                "Cp437");
            aliasTable.put("ibm-437",               "Cp437");
            aliasTable.put("cp437",                 "Cp437");
            aliasTable.put("437",                   "Cp437");
            aliasTable.put("cspc8codepage437",      "Cp437");

            // MIBenum: ????
            aliasTable.put("ibm500",                "Cp500");
            aliasTable.put("ibm-500",               "Cp500");
            aliasTable.put("cp500",                 "Cp500");
            aliasTable.put("500",                   "Cp500");

            // MIBenum: ????
            aliasTable.put("ibm737",                "Cp737");
            aliasTable.put("ibm-737",               "Cp737");
            aliasTable.put("cp737",                 "Cp737");
            aliasTable.put("737",                   "Cp737");

            // MIBenum: ????
            aliasTable.put("ibm775",                "Cp775");
            aliasTable.put("ibm-775",               "Cp775");
            aliasTable.put("cp775",                 "Cp775");
            aliasTable.put("775",                   "Cp775");

S
sherman 已提交
409 410 411 412 413
            aliasTable.put("ibm833",                "Cp833");
            aliasTable.put("ibm-833",               "Cp833");
            aliasTable.put("cp833",                 "Cp833");
            aliasTable.put("833",                   "Cp833");

D
duke 已提交
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
            aliasTable.put("ibm834",                "Cp834");
            aliasTable.put("ibm-834",               "Cp834");
            aliasTable.put("cp834",                 "Cp834");
            aliasTable.put("834",                   "Cp834");

            // MIBenum: ????
            aliasTable.put("ibm838",                "Cp838");         /* MDA */
            aliasTable.put("ibm-838",               "Cp838");         /* MDA */
            aliasTable.put("cp838",                 "Cp838");         /* MDA */
            aliasTable.put("838",                   "Cp838");         /* MDA */

            // "Cp850"
            // MIBenum: 2009
            aliasTable.put("ibm850",                "Cp850");
            aliasTable.put("ibm-850",               "Cp850");
            aliasTable.put("cp850",                 "Cp850");
            aliasTable.put("850",                   "Cp850");
            aliasTable.put("cspc850multilingual",   "Cp850");

            // "Cp852"
            // MIBenum: 2010
            aliasTable.put("ibm852",                "Cp852");
            aliasTable.put("ibm-852",               "Cp852");
            aliasTable.put("cp852",                 "Cp852");
            aliasTable.put("852",                   "Cp852");
            aliasTable.put("cspcp852",              "Cp852");

            // "Cp855"
            // MIBenum: 2046
            aliasTable.put("ibm855",                "Cp855");
            aliasTable.put("ibm-855",               "Cp855");
            aliasTable.put("cp855",                 "Cp855");
            aliasTable.put("855",                   "Cp855");
            aliasTable.put("cspcp855",              "Cp855");

            // "Cp855"
            // MIBenum: ???
            aliasTable.put("ibm856",                "Cp856");
            aliasTable.put("ibm-856",               "Cp856");
            aliasTable.put("cp856",                 "Cp856");
            aliasTable.put("856",                   "Cp856");

            // "Cp857"
            // MIBenum: 2047
            aliasTable.put("ibm857",                "Cp857");
            aliasTable.put("ibm-857",               "Cp857");
            aliasTable.put("cp857",                 "Cp857");
            aliasTable.put("857",                   "Cp857");
            aliasTable.put("csibm857",              "Cp857");

            // "Cp860"
            // MIBenum: 2048
            aliasTable.put("ibm860",                "Cp860");
            aliasTable.put("ibm-860",               "Cp860");
            aliasTable.put("cp860",                 "Cp860");
            aliasTable.put("860",                   "Cp860");
            aliasTable.put("csibm860",              "Cp860");

            // MIBenum: 2049
            aliasTable.put("ibm861",                "Cp861");
            aliasTable.put("ibm-861",               "Cp861");
            aliasTable.put("cp861",                 "Cp861");
            aliasTable.put("cp-is",                 "Cp861");
            aliasTable.put("861",                   "Cp861");
            aliasTable.put("csibm861",              "Cp861");

            // MIBenum: 2013
            aliasTable.put("ibm862",                "Cp862");
            aliasTable.put("ibm-862",               "Cp862");
            aliasTable.put("cp862",                 "Cp862");
            aliasTable.put("862",                   "Cp862");
            aliasTable.put("cspc862latinhebrew",    "Cp862");

            // MIBenum: 2050
            aliasTable.put("ibm863",                "Cp863");
            aliasTable.put("ibm-863",               "Cp863");
            aliasTable.put("cp863",                 "Cp863");
            aliasTable.put("863",                   "Cp863");
            aliasTable.put("csibm863",              "Cp863");

            // MIBenum: 2051
            aliasTable.put("ibm864",                "Cp864");
            aliasTable.put("ibm-864",               "Cp864");
            aliasTable.put("cp864",                 "Cp864");
            aliasTable.put("csibm864",              "Cp864");

            // MIBenum: 2052
            aliasTable.put("ibm865",                "Cp865");
            aliasTable.put("ibm-865",               "Cp865");
            aliasTable.put("cp865",                 "Cp865");
            aliasTable.put("865",                   "Cp865");
            aliasTable.put("csibm865",              "Cp865");

            // MIBenum: ????
            aliasTable.put("ibm866",                "Cp866");
            aliasTable.put("ibm-866",               "Cp866");
            aliasTable.put("cp866",                 "Cp866");
            aliasTable.put("866",                   "Cp866");
            aliasTable.put("csibm866",              "Cp866");

            // MIBenum: ????
            aliasTable.put("ibm868",                "Cp868");
            aliasTable.put("ibm-868",               "Cp868");
            aliasTable.put("cp868",                 "Cp868");
            aliasTable.put("868",                   "Cp868");

            // MIBenum: 2054
            aliasTable.put("ibm869",                "Cp869");
            aliasTable.put("ibm-869",               "Cp869");
            aliasTable.put("cp869",                 "Cp869");
            aliasTable.put("869",                   "Cp869");
            aliasTable.put("cp-gr",                 "Cp869");
            aliasTable.put("csibm869",              "Cp869");

            // MIBenum: ????
            aliasTable.put("ibm870",                "Cp870");
            aliasTable.put("ibm-870",               "Cp870");
            aliasTable.put("cp870",                 "Cp870");
            aliasTable.put("870",                   "Cp870");

            // MIBenum: ????
            aliasTable.put("ibm871",                "Cp871");
            aliasTable.put("ibm-871",               "Cp871");
            aliasTable.put("cp871",                 "Cp871");
            aliasTable.put("871",                   "Cp871");

            // MIBenum: ????
            aliasTable.put("ibm874",                "Cp874");
            aliasTable.put("ibm-874",               "Cp874");
            aliasTable.put("cp874",                 "Cp874");
            aliasTable.put("874",                   "Cp874");

            // MIBenum: ????
            aliasTable.put("ibm875",                "Cp875");
            aliasTable.put("ibm-875",               "Cp875");
            aliasTable.put("cp875",                 "Cp875");
            aliasTable.put("875",                   "Cp875");

            // MIBenum: ????
            aliasTable.put("ibm918",                "Cp918");
            aliasTable.put("ibm-918",               "Cp918");
            aliasTable.put("cp918",                 "Cp918");
            aliasTable.put("918",                   "Cp918");

            // MIBenum: ????
            aliasTable.put("ibm921",                "Cp921");
            aliasTable.put("ibm-921",               "Cp921");
            aliasTable.put("cp921",                 "Cp921");
            aliasTable.put("921",                   "Cp921");

            // MIBenum: ????
            aliasTable.put("ibm922",                "Cp922");
            aliasTable.put("ibm-922",               "Cp922");
            aliasTable.put("cp922",                 "Cp922");
            aliasTable.put("922",                   "Cp922");

            // MIBenum: ????
            aliasTable.put("ibm930",                "Cp930");         /* MDA */
            aliasTable.put("ibm-930",               "Cp930");         /* MDA */
            aliasTable.put("cp930",                 "Cp930");         /* MDA */
            aliasTable.put("930",                   "Cp930");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm933",                "Cp933");         /* MDA */
            aliasTable.put("ibm-933",               "Cp933");         /* MDA */
            aliasTable.put("cp933",                 "Cp933");         /* MDA */
            aliasTable.put("933",                   "Cp933");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm935",                "Cp935");         /* MDA */
            aliasTable.put("ibm-935",               "Cp935");         /* MDA */
            aliasTable.put("cp935",                 "Cp935");         /* MDA */
            aliasTable.put("935",                   "Cp935");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm937",                "Cp937");         /* MDA */
            aliasTable.put("ibm-937",               "Cp937");         /* MDA */
            aliasTable.put("cp937",                 "Cp937");         /* MDA */
            aliasTable.put("937",                   "Cp937");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm939",                "Cp939");         /* MDA */
            aliasTable.put("ibm-939",               "Cp939");         /* MDA */
            aliasTable.put("cp939",                 "Cp939");         /* MDA */
            aliasTable.put("939",                   "Cp939");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm942",                "Cp942");         /* MDA */
            aliasTable.put("ibm-942",               "Cp942");         /* MDA */
            aliasTable.put("cp942",                 "Cp942");         /* MDA */
            aliasTable.put("942",                   "Cp942");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm943",                "Cp943");         /* ibm.3158 */
            aliasTable.put("ibm-943",               "Cp943");         /* ibm.3158 */
            aliasTable.put("cp943",                 "Cp943");         /* ibm.3158 */
            aliasTable.put("943",                   "Cp943");         /* ibm.3158 */

            // MIBenum: ????
            aliasTable.put("ibm948",                "Cp948");         /* MDA */
            aliasTable.put("ibm-948",               "Cp948");         /* MDA */
            aliasTable.put("cp948",                 "Cp948");         /* MDA */
            aliasTable.put("948",                   "Cp948");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm949",                "Cp949");         /* MDA */
            aliasTable.put("ibm-949",               "Cp949");         /* MDA */
            aliasTable.put("cp949",                 "Cp949");         /* MDA */
            aliasTable.put("949",                   "Cp949");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm950",                "Cp950");         /* MDA */
            aliasTable.put("ibm-950",               "Cp950");         /* MDA */
            aliasTable.put("cp950",                 "Cp950");         /* MDA */
            aliasTable.put("950",                   "Cp950");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm964",                "Cp964");         /* MDA */
            aliasTable.put("ibm-964",               "Cp964");         /* MDA */
            aliasTable.put("cp964",                 "Cp964");         /* MDA */
            aliasTable.put("964",                   "Cp964");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm970",                "Cp970");         /* MDA */
            aliasTable.put("ibm-970",               "Cp970");         /* MDA */
            aliasTable.put("cp970",                 "Cp970");         /* MDA */
            aliasTable.put("970",                   "Cp970");         /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm1006",               "Cp1006");
            aliasTable.put("ibm-1006",              "Cp1006");
            aliasTable.put("cp1006",                "Cp1006");
            aliasTable.put("1006",                  "Cp1006");

            // MIBenum: ????
            aliasTable.put("ibm1025",               "Cp1025");
            aliasTable.put("ibm-1025",              "Cp1025");
            aliasTable.put("cp1025",                "Cp1025");
            aliasTable.put("1025",                  "Cp1025");

            // MIBenum: ????
            aliasTable.put("ibm1026",               "Cp1026");
            aliasTable.put("ibm-1026",              "Cp1026");
            aliasTable.put("cp1026",                "Cp1026");
            aliasTable.put("1026",                  "Cp1026");

            // MIBenum: ????
            aliasTable.put("ibm1097",               "Cp1097");
            aliasTable.put("ibm-1097",              "Cp1097");
            aliasTable.put("cp1097",                "Cp1097");
            aliasTable.put("1097",                  "Cp1097");

            // MIBenum: ????
            aliasTable.put("ibm1098",               "Cp1098");
            aliasTable.put("ibm-1098",              "Cp1098");
            aliasTable.put("cp1098",                "Cp1098");
            aliasTable.put("1098",                  "Cp1098");

            // MIBenum: ????
            aliasTable.put("ibm1112",               "Cp1112");
            aliasTable.put("ibm-1112",              "Cp1112");
            aliasTable.put("cp1112",                "Cp1112");
            aliasTable.put("1112",                  "Cp1112");

            // MIBenum: ????
            aliasTable.put("ibm1122",               "Cp1122");
            aliasTable.put("ibm-1122",              "Cp1122");
            aliasTable.put("cp1122",                "Cp1122");
            aliasTable.put("1122",                  "Cp1122");

            // MIBenum: ????
            aliasTable.put("ibm1123",               "Cp1123");
            aliasTable.put("ibm-1123",              "Cp1123");
            aliasTable.put("cp1123",                "Cp1123");
            aliasTable.put("1123",                  "Cp1123");

            // MIBenum: ????
            aliasTable.put("ibm1124",               "Cp1124");
            aliasTable.put("ibm-1124",              "Cp1124");
            aliasTable.put("cp1124",                "Cp1124");
            aliasTable.put("1124",                  "Cp1124");

            // MIBenum: ????
            aliasTable.put("ibm1381",               "Cp1381");        /* MDA */
            aliasTable.put("ibm-1381",              "Cp1381");        /* MDA */
            aliasTable.put("cp1381",                "Cp1381");        /* MDA */
            aliasTable.put("1381",                  "Cp1381");        /* MDA */

            // MIBenum: ????
            aliasTable.put("ibm1383",               "Cp1383");        /* MDA */
            aliasTable.put("ibm-1383",              "Cp1383");        /* MDA */
            aliasTable.put("cp1383",                "Cp1383");        /* MDA */
            aliasTable.put("1383",                  "Cp1383");        /* MDA */

            // Specialized auto-detection for Japanese charsets
            aliasTable.put("jis auto detect",       "JISAutoDetect");

            // MIBenum: 16/39
            aliasTable.put("jis",                   "ISO2022JP");
            aliasTable.put("iso-2022-jp",           "ISO2022JP");
            aliasTable.put("csiso2022jp",           "ISO2022JP");
            aliasTable.put("jis_encoding",          "ISO2022JP");
            aliasTable.put("csjisencoding",         "ISO2022JP");

            // MIBenum: 17/2024
            aliasTable.put("windows-31j",           "MS932");
            aliasTable.put("cswindows31j",          "MS932");

            // JIS-defined Shift JIS
            aliasTable.put("\u30b7\u30d5\u30c8\u7b26\u53f7\u5316\u8868\u73fe",
                           "SJIS");                             // JIS name
            aliasTable.put("pck", "PCK");           // Case independent PCK alias

            if (sjisIsMS932) {
                aliasTable.put("shift_jis",         "MS932");   // IANA shift jis aliases
                aliasTable.put("csshiftjis",        "MS932");   // updated per 4556882
                aliasTable.put("x-sjis",            "MS932");
                aliasTable.put("ms_kanji",          "MS932");
            } else {
                aliasTable.put("shift_jis",         "SJIS");    // IANA shift jis aliases
                aliasTable.put("csshiftjis",        "SJIS");
                aliasTable.put("x-sjis",            "SJIS");
                aliasTable.put("ms_kanji",          "SJIS");
            }

            // MIBenum: 18
            // Japanese EUC
            aliasTable.put("eucjis",                "EUC_JP");
            aliasTable.put("euc-jp",                "EUC_JP");
            aliasTable.put("eucjp",                 "EUC_JP");
            aliasTable.put("extended_unix_code_packed_format_for_japanese",
                           "EUC_JP");
            aliasTable.put("cseucpkdfmtjapanese",   "EUC_JP");
            aliasTable.put("x-euc-jp",              "EUC_JP");
            aliasTable.put("x-eucjp",               "EUC_JP");
            aliasTable.put("eucjp-open",            "EUC_JP_Solaris"); // 1.3.1_x compatibility

            // For handing only JIS0202 and JIS0208 in linux
            aliasTable.put("euc-jp-linux",          "EUC_JP_LINUX");

            // MIBenum: 874
            aliasTable.put("windows-874",           "MS874");

            // MIBenum: 2250
            aliasTable.put("windows-1250",          "Cp1250");

            // MIBenum: 2251
            aliasTable.put("windows-1251",          "Cp1251");
            aliasTable.put("ansi-1251",             "Cp1251"); // Solaris ru_RU.ANSI1251 locale

            // MIBenum: 2252
            aliasTable.put("windows-1252",          "Cp1252");

            // MIBenum: 2253
            aliasTable.put("windows-1253",          "Cp1253");

            // MIBenum: 2254
            aliasTable.put("windows-1254",          "Cp1254");

            // MIBenum: 2255
            aliasTable.put("windows-1255",          "Cp1255");

            // MIBenum: 2256
            aliasTable.put("windows-1256",          "Cp1256");

            // MIBenum: 2257
            aliasTable.put("windows-1257",          "Cp1257");

            // MIBenum: 2258
            aliasTable.put("windows-1258",          "Cp1258");

            // MIBenum: ????
            aliasTable.put("ibm33722",              "Cp33722");       /* MDA */
            aliasTable.put("ibm-33722",             "Cp33722");       /* MDA */
            aliasTable.put("cp33722",               "Cp33722");       /* MDA */
            aliasTable.put("33722",                 "Cp33722");       /* MDA */

            // Russian KOI8-R
            aliasTable.put("koi8-r",                "KOI8_R");
            aliasTable.put("koi8",                  "KOI8_R");
            aliasTable.put("cskoi8r",               "KOI8_R");

            // Simplified Chinese
            aliasTable.put("gb2312",                "EUC_CN");
            aliasTable.put("gb2312-80",             "EUC_CN");
            aliasTable.put("gb2312-1980",           "EUC_CN");
            aliasTable.put("euc-cn",                "EUC_CN");
            aliasTable.put("euccn",                 "EUC_CN");

            aliasTable.put("big5",                  "Big5");
            aliasTable.put("big5hk",                "Big5_HKSCS");
            aliasTable.put("big5-hkscs",            "Big5_HKSCS");
            // Added for future compatibility, explicit mapping to Unicode 3.0
            aliasTable.put("big5-hkscs:unicode3.0", "Big5_HKSCS");
            aliasTable.put("big5_solaris",          "Big5_Solaris");

            // Traditional Chinese
            aliasTable.put("cns11643",              "EUC_TW");
            aliasTable.put("euc-tw",                "EUC_TW");
            aliasTable.put("euctw",                 "EUC_TW");

            // Korean
            aliasTable.put("ksc5601",               "EUC_KR");
            aliasTable.put("euc-kr",                "EUC_KR");
            aliasTable.put("euckr",                 "EUC_KR");
            aliasTable.put("ks_c_5601-1987",        "EUC_KR");
            aliasTable.put("ksc5601-1987",          "EUC_KR");
            aliasTable.put("ksc5601_1987",          "EUC_KR");
            aliasTable.put("ksc_5601",              "EUC_KR");
            aliasTable.put("5601",                  "EUC_KR");

            aliasTable.put("ksc5601-1992",          "Johab");
            aliasTable.put("ksc5601_1992",          "Johab");
            aliasTable.put("ms1361",                "Johab");

            aliasTable.put("windows-949",           "MS949");

            //MIBenum: 37
            aliasTable.put("iso-2022-kr",           "ISO2022KR");
            aliasTable.put("csiso2022kr",           "ISO2022KR");

            // Thai
            aliasTable.put("tis620.2533",           "TIS620");
            aliasTable.put("tis-620",               "TIS620"); // Linux name

            // X11 Compound Text
            aliasTable.put("x-compound-text",       "COMPOUND_TEXT");
            aliasTable.put("x11-compound_text",     "COMPOUND_TEXT");

            // Variants
            aliasTable.put("cp942c", "Cp942C");
            aliasTable.put("cp943c", "Cp943C");
            aliasTable.put("cp949c", "Cp949C");
            aliasTable.put("iscii", "ISCII91");

            installedAll = true;
        }
    }

    /**
     * For Solaris:
     * always returns "PCK"
     *
     * For other platforms:
     * method returns "MS932" if the file.encoding property value is "MS932"
     * or an alias of "MS932"
     * otherwise, "SJIS", regardless of its
     * actual file.encoding value. This method is called from the JIS
     * Auto Detect converter.
     */
    static String getSJISName() {
865 866 867
        String encodeName = AccessController.doPrivileged(
                                               new PrivilegedAction<String>() {
            public String run() {
D
duke 已提交
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
                String osName = System.getProperty("os.name");
                if (osName.equals("Solaris") || osName.equals("SunOS")){
                    return "PCK";
                }
                else {
                    return System.getProperty("file.encoding", null);
                }
            }
        });

        if (encodeName != null) {
            if (encodeName.equals("MS932"))
                return encodeName;
            encodeName = aliasName(encodeName);
        }
        return (encodeName != null && encodeName.equals("MS932")) ? encodeName : "SJIS";
    }


    static String getEUCJPName() {
888 889 890
      String encodeName = AccessController.doPrivileged(
                                              new PrivilegedAction<String>() {
          public String run() {
D
duke 已提交
891 892 893 894 895 896 897 898 899 900
              String osName = System.getProperty("os.name");
              if (osName.equals("Solaris") || osName.equals("SunOS"))
                  return "eucJP-open";
              else
                  return "EUC_JP";
          }
      });
      return encodeName;
    }
}