author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 29986 | 97167d851fc4 |
child 35783 | 2690535d72cc |
permissions | -rw-r--r-- |
5610 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
11275
diff
changeset
|
2 |
* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. |
5610 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
6374
e214162c907e
6982137: Rebranding pass 2 - missed copyright changes
ohair
parents:
5610
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
5610 | 8 |
* particular file as subject to the "Classpath" exception as provided |
6374
e214162c907e
6982137: Rebranding pass 2 - missed copyright changes
ohair
parents:
5610
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
5610 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
6374
e214162c907e
6982137: Rebranding pass 2 - missed copyright changes
ohair
parents:
5610
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e214162c907e
6982137: Rebranding pass 2 - missed copyright changes
ohair
parents:
5610
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
e214162c907e
6982137: Rebranding pass 2 - missed copyright changes
ohair
parents:
5610
diff
changeset
|
23 |
* questions. |
5610 | 24 |
*/ |
25 |
||
26 |
package java.lang; |
|
27 |
||
28 |
import java.io.DataInputStream; |
|
29 |
import java.io.InputStream; |
|
30 |
import java.lang.ref.SoftReference; |
|
31 |
import java.util.Arrays; |
|
32 |
import java.util.zip.InflaterInputStream; |
|
33 |
import java.security.AccessController; |
|
34 |
import java.security.PrivilegedAction; |
|
35 |
||
36 |
class CharacterName { |
|
37 |
||
38 |
private static SoftReference<byte[]> refStrPool; |
|
39 |
private static int[][] lookup; |
|
40 |
||
41 |
private static synchronized byte[] initNamePool() { |
|
42 |
byte[] strPool = null; |
|
43 |
if (refStrPool != null && (strPool = refStrPool.get()) != null) |
|
44 |
return strPool; |
|
45 |
DataInputStream dis = null; |
|
46 |
try { |
|
47 |
dis = new DataInputStream(new InflaterInputStream( |
|
29986
97167d851fc4
8078467: Update core libraries to use diamond with anonymous classes
darcy
parents:
25859
diff
changeset
|
48 |
AccessController.doPrivileged(new PrivilegedAction<>() |
5610 | 49 |
{ |
50 |
public InputStream run() { |
|
51 |
return getClass().getResourceAsStream("uniName.dat"); |
|
52 |
} |
|
53 |
}))); |
|
54 |
||
55 |
lookup = new int[(Character.MAX_CODE_POINT + 1) >> 8][]; |
|
56 |
int total = dis.readInt(); |
|
57 |
int cpEnd = dis.readInt(); |
|
58 |
byte ba[] = new byte[cpEnd]; |
|
59 |
dis.readFully(ba); |
|
60 |
||
61 |
int nameOff = 0; |
|
62 |
int cpOff = 0; |
|
63 |
int cp = 0; |
|
64 |
do { |
|
65 |
int len = ba[cpOff++] & 0xff; |
|
66 |
if (len == 0) { |
|
67 |
len = ba[cpOff++] & 0xff; |
|
68 |
// always big-endian |
|
69 |
cp = ((ba[cpOff++] & 0xff) << 16) | |
|
70 |
((ba[cpOff++] & 0xff) << 8) | |
|
71 |
((ba[cpOff++] & 0xff)); |
|
72 |
} else { |
|
73 |
cp++; |
|
74 |
} |
|
75 |
int hi = cp >> 8; |
|
76 |
if (lookup[hi] == null) { |
|
77 |
lookup[hi] = new int[0x100]; |
|
78 |
} |
|
79 |
lookup[hi][cp&0xff] = (nameOff << 8) | len; |
|
80 |
nameOff += len; |
|
81 |
} while (cpOff < cpEnd); |
|
82 |
strPool = new byte[total - cpEnd]; |
|
83 |
dis.readFully(strPool); |
|
7803
56bc97d69d93
6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents:
6374
diff
changeset
|
84 |
refStrPool = new SoftReference<>(strPool); |
5610 | 85 |
} catch (Exception x) { |
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
7803
diff
changeset
|
86 |
throw new InternalError(x.getMessage(), x); |
5610 | 87 |
} finally { |
88 |
try { |
|
89 |
if (dis != null) |
|
90 |
dis.close(); |
|
91 |
} catch (Exception xx) {} |
|
92 |
} |
|
93 |
return strPool; |
|
94 |
} |
|
95 |
||
96 |
public static String get(int cp) { |
|
97 |
byte[] strPool = null; |
|
98 |
if (refStrPool == null || (strPool = refStrPool.get()) == null) |
|
99 |
strPool = initNamePool(); |
|
100 |
int off = 0; |
|
101 |
if (lookup[cp>>8] == null || |
|
102 |
(off = lookup[cp>>8][cp&0xff]) == 0) |
|
103 |
return null; |
|
11275 | 104 |
@SuppressWarnings("deprecation") |
105 |
String result = new String(strPool, 0, off >>> 8, off & 0xff); // ASCII |
|
106 |
return result; |
|
5610 | 107 |
} |
108 |
} |