1091N/A/*
2362N/A * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
1091N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1091N/A *
1091N/A * This code is free software; you can redistribute it and/or modify it
1091N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1091N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1091N/A *
1091N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1091N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1091N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1091N/A * version 2 for more details (a copy is included in the LICENSE file that
1091N/A * accompanied this code).
1091N/A *
1091N/A * You should have received a copy of the GNU General Public License version
1091N/A * 2 along with this work; if not, write to the Free Software Foundation,
1091N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1091N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1091N/A */
1091N/A/*
1091N/A *******************************************************************************
1091N/A * (C) Copyright IBM Corp. and others, 1996-2009 - All Rights Reserved *
1091N/A * *
1091N/A * The original version of this source code and documentation is copyrighted *
1091N/A * and owned by IBM, These materials are provided under terms of a License *
1091N/A * Agreement between IBM and Sun. This technology is protected by multiple *
1091N/A * US and International patents. This notice and attribution to IBM may not *
1091N/A * to removed. *
1091N/A *******************************************************************************
1091N/A* file name: UBiDiProps.java
1091N/A* encoding: US-ASCII
1091N/A* tab size: 8 (not used)
1091N/A* indentation:4
1091N/A*
1091N/A* created on: 2005jan16
1091N/A* created by: Markus W. Scherer
1091N/A*
1091N/A* Low-level Unicode bidi/shaping properties access.
1091N/A* Java port of ubidi_props.h/.c.
1091N/A*/
1091N/A
1091N/Apackage sun.text.normalizer;
1091N/A
1091N/Aimport java.io.BufferedInputStream;
1091N/Aimport java.io.DataInputStream;
1091N/Aimport java.io.InputStream;
1091N/Aimport java.io.IOException;
1091N/A
1091N/Apublic final class UBiDiProps {
1091N/A // constructors etc. --------------------------------------------------- ***
1091N/A
1091N/A // port of ubidi_openProps()
1091N/A public UBiDiProps() throws IOException{
1091N/A InputStream is=ICUData.getStream(DATA_FILE_NAME);
1091N/A BufferedInputStream b=new BufferedInputStream(is, 4096 /* data buffer size */);
1091N/A readData(b);
1091N/A b.close();
1091N/A is.close();
1091N/A
1091N/A }
1091N/A
1091N/A private void readData(InputStream is) throws IOException {
1091N/A DataInputStream inputStream=new DataInputStream(is);
1091N/A
1091N/A // read the header
1091N/A ICUBinary.readHeader(inputStream, FMT, new IsAcceptable());
1091N/A
1091N/A // read indexes[]
1091N/A int i, count;
1091N/A count=inputStream.readInt();
1091N/A if(count<IX_INDEX_TOP) {
1091N/A throw new IOException("indexes[0] too small in "+DATA_FILE_NAME);
1091N/A }
1091N/A indexes=new int[count];
1091N/A
1091N/A indexes[0]=count;
1091N/A for(i=1; i<count; ++i) {
1091N/A indexes[i]=inputStream.readInt();
1091N/A }
1091N/A
1091N/A // read the trie
1091N/A trie=new CharTrie(inputStream, null);
1091N/A
1091N/A // read mirrors[]
1091N/A count=indexes[IX_MIRROR_LENGTH];
1091N/A if(count>0) {
1091N/A mirrors=new int[count];
1091N/A for(i=0; i<count; ++i) {
1091N/A mirrors[i]=inputStream.readInt();
1091N/A }
1091N/A }
1091N/A
1091N/A // read jgArray[]
1091N/A count=indexes[IX_JG_LIMIT]-indexes[IX_JG_START];
1091N/A jgArray=new byte[count];
1091N/A for(i=0; i<count; ++i) {
1091N/A jgArray[i]=inputStream.readByte();
1091N/A }
1091N/A }
1091N/A
1091N/A // implement ICUBinary.Authenticate
1091N/A private final class IsAcceptable implements ICUBinary.Authenticate {
1091N/A public boolean isDataVersionAcceptable(byte version[]) {
1091N/A return version[0]==1 &&
1091N/A version[2]==Trie.INDEX_STAGE_1_SHIFT_ && version[3]==Trie.INDEX_STAGE_2_SHIFT_;
1091N/A }
1091N/A }
1091N/A
1091N/A // UBiDiProps singleton
1091N/A private static UBiDiProps gBdp=null;
1091N/A
1091N/A // port of ubidi_getSingleton()
1091N/A public static final synchronized UBiDiProps getSingleton() throws IOException {
1091N/A if(gBdp==null) {
1091N/A gBdp=new UBiDiProps();
1091N/A }
1091N/A return gBdp;
1091N/A }
1091N/A
1091N/A // UBiDiProps dummy singleton
1091N/A private static UBiDiProps gBdpDummy=null;
1091N/A
1091N/A private UBiDiProps(boolean makeDummy) { // ignore makeDummy, only creates a unique signature
1091N/A indexes=new int[IX_TOP];
1091N/A indexes[0]=IX_TOP;
1091N/A trie=new CharTrie(0, 0, null); // dummy trie, always returns 0
1091N/A }
1091N/A
1091N/A /**
1091N/A * Get a singleton dummy object, one that works with no real data.
1091N/A * This can be used when the real data is not available.
1091N/A * Using the dummy can reduce checks for available data after an initial failure.
1091N/A * Port of ucase_getDummy().
1091N/A */
1091N/A public static final synchronized UBiDiProps getDummy() {
1091N/A if(gBdpDummy==null) {
1091N/A gBdpDummy=new UBiDiProps(true);
1091N/A }
1091N/A return gBdpDummy;
1091N/A }
1091N/A
1091N/A public final int getClass(int c) {
1091N/A return getClassFromProps(trie.getCodePointValue(c));
1091N/A }
1091N/A
1091N/A // data members -------------------------------------------------------- ***
1091N/A private int indexes[];
1091N/A private int mirrors[];
1091N/A private byte jgArray[];
1091N/A
1091N/A private CharTrie trie;
1091N/A
1091N/A // data format constants ----------------------------------------------- ***
1091N/A private static final String DATA_FILE_NAME = "/sun/text/resources/ubidi.icu";
1091N/A
1091N/A /* format "BiDi" */
1091N/A private static final byte FMT[]={ 0x42, 0x69, 0x44, 0x69 };
1091N/A
1091N/A /* indexes into indexes[] */
1091N/A private static final int IX_INDEX_TOP=0;
1091N/A private static final int IX_MIRROR_LENGTH=3;
1091N/A
1091N/A private static final int IX_JG_START=4;
1091N/A private static final int IX_JG_LIMIT=5;
1091N/A
1091N/A private static final int IX_TOP=16;
1091N/A
1091N/A private static final int CLASS_MASK= 0x0000001f;
1091N/A
1091N/A private static final int getClassFromProps(int props) {
1091N/A return props&CLASS_MASK;
1091N/A }
1091N/A
1091N/A}