Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/text/normalizer/UBiDiProps.java
38830 views
/*1* Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24/*25*******************************************************************************26* (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved *27* *28* The original version of this source code and documentation is copyrighted *29* and owned by IBM, These materials are provided under terms of a License *30* Agreement between IBM and Sun. This technology is protected by multiple *31* US and International patents. This notice and attribution to IBM may not *32* to removed. *33*******************************************************************************34* file name: UBiDiProps.java35* encoding: US-ASCII36* tab size: 8 (not used)37* indentation:438*39* created on: 2005jan1640* created by: Markus W. Scherer41*42* Low-level Unicode bidi/shaping properties access.43* Java port of ubidi_props.h/.c.44*/4546package sun.text.normalizer;4748import java.io.BufferedInputStream;49import java.io.DataInputStream;50import java.io.InputStream;51import java.io.IOException;5253public final class UBiDiProps {54// constructors etc. --------------------------------------------------- ***5556// port of ubidi_openProps()57public UBiDiProps() throws IOException{58InputStream is=ICUData.getStream(DATA_FILE_NAME);59BufferedInputStream b=new BufferedInputStream(is, 4096 /* data buffer size */);60readData(b);61b.close();62is.close();6364}6566private void readData(InputStream is) throws IOException {67DataInputStream inputStream=new DataInputStream(is);6869// read the header70ICUBinary.readHeader(inputStream, FMT, new IsAcceptable());7172// read indexes[]73int i, count;74count=inputStream.readInt();75if(count<IX_INDEX_TOP) {76throw new IOException("indexes[0] too small in "+DATA_FILE_NAME);77}78indexes=new int[count];7980indexes[0]=count;81for(i=1; i<count; ++i) {82indexes[i]=inputStream.readInt();83}8485// read the trie86trie=new CharTrie(inputStream, null);8788// read mirrors[]89count=indexes[IX_MIRROR_LENGTH];90if(count>0) {91mirrors=new int[count];92for(i=0; i<count; ++i) {93mirrors[i]=inputStream.readInt();94}95}9697// read jgArray[]98count=indexes[IX_JG_LIMIT]-indexes[IX_JG_START];99jgArray=new byte[count];100for(i=0; i<count; ++i) {101jgArray[i]=inputStream.readByte();102}103}104105// implement ICUBinary.Authenticate106private final class IsAcceptable implements ICUBinary.Authenticate {107public boolean isDataVersionAcceptable(byte version[]) {108return version[0]==1 &&109version[2]==Trie.INDEX_STAGE_1_SHIFT_ && version[3]==Trie.INDEX_STAGE_2_SHIFT_;110}111}112113// UBiDiProps singleton114private static UBiDiProps gBdp=null;115116// port of ubidi_getSingleton()117public static final synchronized UBiDiProps getSingleton() throws IOException {118if(gBdp==null) {119gBdp=new UBiDiProps();120}121return gBdp;122}123124// UBiDiProps dummy singleton125private static UBiDiProps gBdpDummy=null;126127private UBiDiProps(boolean makeDummy) { // ignore makeDummy, only creates a unique signature128indexes=new int[IX_TOP];129indexes[0]=IX_TOP;130trie=new CharTrie(0, 0, null); // dummy trie, always returns 0131}132133/**134* Get a singleton dummy object, one that works with no real data.135* This can be used when the real data is not available.136* Using the dummy can reduce checks for available data after an initial failure.137* Port of ucase_getDummy().138*/139public static final synchronized UBiDiProps getDummy() {140if(gBdpDummy==null) {141gBdpDummy=new UBiDiProps(true);142}143return gBdpDummy;144}145146public final int getClass(int c) {147return getClassFromProps(trie.getCodePointValue(c));148}149150// data members -------------------------------------------------------- ***151private int indexes[];152private int mirrors[];153private byte jgArray[];154155private CharTrie trie;156157// data format constants ----------------------------------------------- ***158private static final String DATA_FILE_NAME = "/sun/text/resources/ubidi.icu";159160/* format "BiDi" */161private static final byte FMT[]={ 0x42, 0x69, 0x44, 0x69 };162163/* indexes into indexes[] */164private static final int IX_INDEX_TOP=0;165private static final int IX_MIRROR_LENGTH=3;166167private static final int IX_JG_START=4;168private static final int IX_JG_LIMIT=5;169170private static final int IX_TOP=16;171172private static final int CLASS_MASK= 0x0000001f;173174private static final int getClassFromProps(int props) {175return props&CLASS_MASK;176}177178}179180181