jdk/make/src/classes/build/tools/charsetmapping/JIS0213.java
author ihse
Thu, 14 Nov 2013 11:19:32 +0100
changeset 21805 c7d7946239de
parent 7668 jdk/make/tools/src/build/tools/charsetmapping/JIS0213.java@d4a77089c587
child 23010 6dadb192ad81
permissions -rw-r--r--
8027566: Remove the old build system Reviewed-by: erikj, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     4
 *
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    10
 *
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    15
 * accompanied this code).
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    16
 *
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5167
diff changeset
    23
 * questions.
5167
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    24
 */
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    25
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    26
package build.tools.charsetmapping;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    27
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    28
import java.io.*;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    29
import java.util.regex.*;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    30
import java.util.*;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    31
import static build.tools.charsetmapping.Utils.*;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    32
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    33
public class JIS0213 {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    34
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    35
    // regex pattern to parse the "jis0213.map" file
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    36
    static Pattern sjis0213 = Pattern.compile("0x(\\p{XDigit}++)\\s++U\\+(\\p{XDigit}++)(?:\\+(\\p{XDigit}++))?\\s++#.*");
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    37
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    38
    static void genClass(String argv[]) throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    39
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    40
        InputStream in = new FileInputStream(argv[0]) ;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    41
        OutputStream out = new FileOutputStream(argv[1]);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    42
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    43
        int[] sb = new int[0x100];                         // singlebyte
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    44
        int[] db = new int[0x10000];                       // doublebyte
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    45
        int[] indexC2B = new int[256];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    46
        Entry[] supp = new Entry[0x10000];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    47
        Entry[] comp = new Entry[0x100];
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    48
        int suppTotal = 0;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    49
        int compTotal = 0;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    50
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    51
        int b1Min1 = 0x81;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    52
        int b1Max1 = 0x9f;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    53
        int b1Min2 = 0xe0;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    54
        int b1Max2 = 0xfc;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    55
        int b2Min = 0x40;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    56
        int b2Max = 0xfe;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    57
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    58
        //init
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    59
        for (int i = 0; i < 0x80; i++) sb[i] = i;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    60
        for (int i = 0x80; i < 0x100; i++) sb[i] = UNMAPPABLE_DECODING;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    61
        for (int i = 0; i < 0x10000; i++) db[i] = UNMAPPABLE_DECODING;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    62
        try {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    63
            Parser p = new Parser(in, sjis0213);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    64
            Entry  e = null;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    65
            while ((e = p.next()) != null) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    66
                if (e.cp2 != 0) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    67
                    comp[compTotal++] = e;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    68
                } else {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    69
                    if (e.cp <= 0xffff) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    70
                        if (e.bs <= 0xff)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    71
                            sb[e.bs] = e.cp;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    72
                        else
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    73
                            db[e.bs] = e.cp;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    74
                        indexC2B[e.cp>>8] = 1;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    75
                    } else {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    76
                        supp[suppTotal++] = e;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    77
                    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    78
                }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    79
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    80
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    81
            // c2b Index Table, always the first one
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    82
            writeINDEXC2B(baos, indexC2B);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    83
            writeSINGLEBYTE(baos, sb);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    84
            writeDOUBLEBYTE1(baos, db, b1Min1, b1Max1, b2Min, b2Max);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    85
            writeDOUBLEBYTE2(baos, db, b1Min2, b1Max2, b2Min, b2Max);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    86
            writeSUPPLEMENT(baos, supp, suppTotal);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    87
            writeCOMPOSITE(baos, comp, compTotal);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    88
            writeSIZE(out, baos.size());
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    89
            baos.writeTo(out);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    90
            out.close();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    91
        } catch (Exception x) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    92
            x.printStackTrace();
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    93
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    94
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    95
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    96
    static Comparator<Entry> comparatorCP =
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    97
        new Comparator<Entry>() {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    98
            public int compare(Entry m1, Entry m2) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
    99
                return m1.cp - m2.cp;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   100
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   101
            public boolean equals(Object obj) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   102
                return this == obj;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   103
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   104
    };
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   105
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   106
    // tags of different charset mapping tables
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   107
    private final static int MAP_SINGLEBYTE      = 0x1; // 0..256  : c
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   108
    private final static int MAP_DOUBLEBYTE1     = 0x2; // min..max: c
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   109
    private final static int MAP_DOUBLEBYTE2     = 0x3; // min..max: c [DB2]
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   110
    private final static int MAP_SUPPLEMENT      = 0x5; //           db,c
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   111
    private final static int MAP_SUPPLEMENT_C2B  = 0x6; //           c,db
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   112
    private final static int MAP_COMPOSITE       = 0x7; //           db,base,cc
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   113
    private final static int MAP_INDEXC2B        = 0x8; // index table of c->bb
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   114
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   115
    private static final void writeShort(OutputStream out, int data)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   116
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   117
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   118
        out.write((data >>> 8) & 0xFF);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   119
        out.write((data      ) & 0xFF);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   120
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   121
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   122
    private static final void writeShortArray(OutputStream out,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   123
                                              int type,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   124
                                              int[] array,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   125
                                              int off,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   126
                                              int size)   // exclusive
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   127
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   128
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   129
        writeShort(out, type);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   130
        writeShort(out, size);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   131
        for (int i = off; i < size; i++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   132
            writeShort(out, array[off+i]);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   133
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   134
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   135
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   136
    private static final void writeSIZE(OutputStream out, int data)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   137
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   138
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   139
        out.write((data >>> 24) & 0xFF);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   140
        out.write((data >>> 16) & 0xFF);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   141
        out.write((data >>>  8) & 0xFF);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   142
        out.write((data       ) & 0xFF);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   143
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   144
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   145
    private static void writeINDEXC2B(OutputStream out, int[] indexC2B)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   146
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   147
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   148
        writeShort(out, MAP_INDEXC2B);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   149
        writeShort(out, indexC2B.length);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   150
        int off = 0;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   151
        for (int i = 0; i < indexC2B.length; i++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   152
            if (indexC2B[i] != 0) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   153
                writeShort(out, off);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   154
                off += 256;
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   155
            } else {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   156
                writeShort(out, -1);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   157
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   158
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   159
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   160
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   161
    private static void writeSINGLEBYTE(OutputStream out, int[] sb)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   162
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   163
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   164
        writeShortArray(out, MAP_SINGLEBYTE, sb, 0, 256);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   165
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   166
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   167
    private static void writeDOUBLEBYTE(OutputStream out,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   168
                                        int type,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   169
                                        int[] db,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   170
                                        int b1Min, int b1Max,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   171
                                        int b2Min, int b2Max)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   172
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   173
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   174
        writeShort(out, type);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   175
        writeShort(out, b1Min);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   176
        writeShort(out, b1Max);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   177
        writeShort(out, b2Min);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   178
        writeShort(out, b2Max);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   179
        writeShort(out, (b1Max - b1Min + 1) * (b2Max - b2Min + 1));
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   180
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   181
        for (int b1 = b1Min; b1 <= b1Max; b1++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   182
            for (int b2 = b2Min; b2 <= b2Max; b2++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   183
                writeShort(out, db[b1 * 256 + b2]);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   184
            }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   185
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   186
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   187
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   188
    private static void writeDOUBLEBYTE1(OutputStream out,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   189
                                        int[] db,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   190
                                        int b1Min, int b1Max,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   191
                                        int b2Min, int b2Max)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   192
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   193
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   194
        writeDOUBLEBYTE(out, MAP_DOUBLEBYTE1, db, b1Min, b1Max, b2Min, b2Max);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   195
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   196
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   197
    private static void writeDOUBLEBYTE2(OutputStream out,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   198
                                        int[] db,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   199
                                        int b1Min, int b1Max,
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   200
                                        int b2Min, int b2Max)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   201
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   202
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   203
        writeDOUBLEBYTE(out, MAP_DOUBLEBYTE2, db, b1Min, b1Max, b2Min, b2Max);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   204
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   205
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   206
    // the c2b table is output as well
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   207
    private static void writeSUPPLEMENT(OutputStream out, Entry[] supp, int size)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   208
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   209
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   210
        writeShort(out, MAP_SUPPLEMENT);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   211
        writeShort(out, size * 2);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   212
        // db at first half, cc at the low half
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   213
        for (int i = 0; i < size; i++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   214
            writeShort(out, supp[i].bs);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   215
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   216
        for (int i = 0; i < size; i++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   217
            writeShort(out, supp[i].cp);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   218
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   219
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   220
        //c2b
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   221
        writeShort(out, MAP_SUPPLEMENT_C2B);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   222
        writeShort(out, size*2);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   223
        Arrays.sort(supp, 0, size, comparatorCP);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   224
        for (int i = 0; i < size; i++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   225
            writeShort(out, supp[i].cp);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   226
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   227
        for (int i = 0; i < size; i++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   228
            writeShort(out, supp[i].bs);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   229
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   230
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   231
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   232
    private static void writeCOMPOSITE(OutputStream out, Entry[] comp, int size)
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   233
        throws IOException
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   234
    {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   235
        writeShort(out, MAP_COMPOSITE);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   236
        writeShort(out, size*3);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   237
        // comp is sorted already
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   238
        for (int i = 0; i < size; i++) {
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   239
            writeShort(out, (char)comp[i].bs);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   240
            writeShort(out, (char)comp[i].cp);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   241
            writeShort(out, (char)comp[i].cp2);
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   242
        }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   243
    }
dbd299f8fdae 6902790: Converting/displaying HKSCs characters issue on Vista and Windows7
sherman
parents:
diff changeset
   244
}