jdk/make/src/classes/build/tools/generatecharacter/CharacterName.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 21805 c7d7946239de
child 35783 2690535d72cc
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5610
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
     1
package build.tools.generatecharacter;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
     2
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
     3
import java.io.*;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
     4
import java.nio.*;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
     5
import java.util.*;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
     6
import java.util.zip.*;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
     7
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
     8
public class CharacterName {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
     9
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    10
    public static void main(String[] args) {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    11
        FileReader reader = null;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    12
        try {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    13
            if (args.length != 2) {
19864
41c6dfb2022e 7186311: (props) "Unicode" is misspelled as "Uniocde" in JavaDoc and error message
sherman
parents: 5610
diff changeset
    14
                System.err.println("Usage: java CharacterName UnicodeData.txt uniName.dat");
5610
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    15
                System.exit(1);
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    16
            }
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    17
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    18
            reader = new FileReader(args[0]);
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    19
            BufferedReader bfr = new BufferedReader(reader);
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    20
            String line = null;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    21
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    22
            StringBuilder namePool = new StringBuilder();
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    23
            byte[] cpPoolBytes = new byte[0x100000];
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    24
            ByteBuffer cpBB = ByteBuffer.wrap(cpPoolBytes);
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    25
            int lastCp = 0;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    26
            int cpNum = 0;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    27
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    28
            while ((line = bfr.readLine()) != null) {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    29
                if (line.startsWith("#"))
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    30
                    continue;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    31
                UnicodeSpec spec = UnicodeSpec.parse(line);
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    32
                if (spec != null) {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    33
                    int cp = spec.getCodePoint();
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    34
                    String name = spec.getName();
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    35
                    cpNum++;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    36
                    if (name.equals("<control>") && spec.getOldName() != null) {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    37
                        if (spec.getOldName().length() != 0)
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    38
                            name = spec.getOldName();
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    39
                        else
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    40
                            continue;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    41
                    } else if (name.startsWith("<")) {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    42
                        /*
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    43
                          3400    <CJK Ideograph Extension A, First>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    44
                          4db5    <CJK Ideograph Extension A, Last>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    45
                          4e00    <CJK Ideograph, First>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    46
                          9fc3    <CJK Ideograph, Last>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    47
                          ac00    <Hangul Syllable, First>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    48
                          d7a3    <Hangul Syllable, Last>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    49
                          d800    <Non Private Use High Surrogate, First>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    50
                          db7f    <Non Private Use High Surrogate, Last>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    51
                          db80    <Private Use High Surrogate, First>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    52
                          dbff    <Private Use High Surrogate, Last>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    53
                          dc00    <Low Surrogate, First>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    54
                          dfff    <Low Surrogate, Last>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    55
                          e000    <Private Use, First>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    56
                          f8ff    <Private Use, Last>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    57
                         20000    <CJK Ideograph Extension B, First>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    58
                         2a6d6    <CJK Ideograph Extension B, Last>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    59
                         f0000    <Plane 15 Private Use, First>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    60
                         ffffd    <Plane 15 Private Use, Last>
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    61
                        */
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    62
                        continue;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    63
                    }
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    64
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    65
                    if (cp == lastCp + 1) {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    66
                        cpBB.put((byte)name.length());
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    67
                    } else {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    68
                        cpBB.put((byte)0);  // segment start flag
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    69
                        cpBB.putInt((name.length() << 24) | (cp & 0xffffff));
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    70
                    }
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    71
                    namePool.append(name);
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    72
                    lastCp = cp;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    73
                }
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    74
            }
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    75
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    76
            byte[] namePoolBytes = namePool.toString().getBytes("ASCII");
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    77
            int cpLen = cpBB.position();
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    78
            int total = cpLen + namePoolBytes.length;
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    79
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    80
            DataOutputStream dos = new DataOutputStream(
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    81
                                       new DeflaterOutputStream(
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    82
                                           new FileOutputStream(args[1])));
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    83
            dos.writeInt(total);  // total
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    84
            dos.writeInt(cpLen);  // nameOff
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    85
            dos.write(cpPoolBytes, 0, cpLen);
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    86
            dos.write(namePoolBytes);
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    87
            dos.close();
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    88
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    89
        } catch (Throwable e) {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    90
            System.out.println("Unexpected exception:");
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    91
            e.printStackTrace();
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    92
        } finally {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    93
            if (reader != null) {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    94
                try {
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    95
                    reader.close();
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    96
                } catch (Throwable ee) { ee.printStackTrace(); }
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    97
            }
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    98
        }
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
    99
    }
fd2427610c7f 6945564: Unicode script support in Character class
sherman
parents:
diff changeset
   100
}