Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/text/normalizer/UCharacterPropertyReader.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*/3536package sun.text.normalizer;3738import java.io.DataInputStream;39import java.io.InputStream;40import java.io.IOException;4142/**43* <p>Internal reader class for ICU data file uprops.icu containing44* Unicode codepoint data.</p>45* <p>This class simply reads uprops.icu, authenticates that it is a valid46* ICU data file and split its contents up into blocks of data for use in47* <a href=UCharacterProperty.html>com.ibm.icu.impl.UCharacterProperty</a>.48* </p>49* <p>uprops.icu which is in big-endian format is jared together with this50* package.</p>51*52* Unicode character properties file format see53* (ICU4C)/source/tools/genprops/store.c54*55* @author Syn Wee Quek56* @since release 2.1, February 1st 200257*/58final class UCharacterPropertyReader implements ICUBinary.Authenticate59{60// public methods ----------------------------------------------------6162public boolean isDataVersionAcceptable(byte version[])63{64return version[0] == DATA_FORMAT_VERSION_[0]65&& version[2] == DATA_FORMAT_VERSION_[2]66&& version[3] == DATA_FORMAT_VERSION_[3];67}6869// protected constructor ---------------------------------------------7071/**72* <p>Protected constructor.</p>73* @param inputStream ICU uprop.dat file input stream74* @exception IOException throw if data file fails authentication75*/76protected UCharacterPropertyReader(InputStream inputStream)77throws IOException78{79m_unicodeVersion_ = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID_,80this);81m_dataInputStream_ = new DataInputStream(inputStream);82}8384// protected methods -------------------------------------------------8586/**87* <p>Reads uprops.icu, parse it into blocks of data to be stored in88* UCharacterProperty.</P89* @param ucharppty UCharacterProperty instance90* @exception IOException thrown when data reading fails91*/92protected void read(UCharacterProperty ucharppty) throws IOException93{94// read the indexes95int count = INDEX_SIZE_;96m_propertyOffset_ = m_dataInputStream_.readInt();97count --;98m_exceptionOffset_ = m_dataInputStream_.readInt();99count --;100m_caseOffset_ = m_dataInputStream_.readInt();101count --;102m_additionalOffset_ = m_dataInputStream_.readInt();103count --;104m_additionalVectorsOffset_ = m_dataInputStream_.readInt();105count --;106m_additionalColumnsCount_ = m_dataInputStream_.readInt();107count --;108m_reservedOffset_ = m_dataInputStream_.readInt();109count --;110m_dataInputStream_.skipBytes(3 << 2);111count -= 3;112ucharppty.m_maxBlockScriptValue_ = m_dataInputStream_.readInt();113count --; // 10114ucharppty.m_maxJTGValue_ = m_dataInputStream_.readInt();115count --; // 11116m_dataInputStream_.skipBytes(count << 2);117118// read the trie index block119// m_props_index_ in terms of ints120ucharppty.m_trie_ = new CharTrie(m_dataInputStream_, null);121122// skip the 32 bit properties block123int size = m_exceptionOffset_ - m_propertyOffset_;124m_dataInputStream_.skipBytes(size * 4);125126// reads the 32 bit exceptions block127size = m_caseOffset_ - m_exceptionOffset_;128m_dataInputStream_.skipBytes(size * 4);129130// reads the 32 bit case block131size = (m_additionalOffset_ - m_caseOffset_) << 1;132m_dataInputStream_.skipBytes(size * 2);133134if(m_additionalColumnsCount_ > 0) {135// reads the additional property block136ucharppty.m_additionalTrie_ = new CharTrie(m_dataInputStream_, null);137138// additional properties139size = m_reservedOffset_ - m_additionalVectorsOffset_;140ucharppty.m_additionalVectors_ = new int[size];141for (int i = 0; i < size; i ++) {142ucharppty.m_additionalVectors_[i] = m_dataInputStream_.readInt();143}144}145146m_dataInputStream_.close();147ucharppty.m_additionalColumnsCount_ = m_additionalColumnsCount_;148ucharppty.m_unicodeVersion_ = VersionInfo.getInstance(149(int)m_unicodeVersion_[0], (int)m_unicodeVersion_[1],150(int)m_unicodeVersion_[2], (int)m_unicodeVersion_[3]);151}152153// private variables -------------------------------------------------154155/**156* Index size157*/158private static final int INDEX_SIZE_ = 16;159160/**161* ICU data file input stream162*/163private DataInputStream m_dataInputStream_;164165/**166* Offset information in the indexes.167*/168private int m_propertyOffset_;169private int m_exceptionOffset_;170private int m_caseOffset_;171private int m_additionalOffset_;172private int m_additionalVectorsOffset_;173private int m_additionalColumnsCount_;174private int m_reservedOffset_;175private byte m_unicodeVersion_[];176177/**178* Data format "UPro".179*/180private static final byte DATA_FORMAT_ID_[] = {(byte)0x55, (byte)0x50,181(byte)0x72, (byte)0x6F};182/**183* Format version; this code works with all versions with the same major184* version number and the same Trie bit distribution.185*/186private static final byte DATA_FORMAT_VERSION_[] = {(byte)0x5, (byte)0,187(byte)Trie.INDEX_STAGE_1_SHIFT_,188(byte)Trie.INDEX_STAGE_2_SHIFT_};189}190191192