2 *******************************************************************************
\r
3 * Copyright (C) 1996-2008, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
7 package com.ibm.icu.impl;
\r
9 import java.io.InputStream;
\r
10 import java.io.DataInputStream;
\r
11 import java.io.IOException;
\r
12 import com.ibm.icu.util.VersionInfo;
\r
15 * <p>Internal reader class for ICU data file uprops.icu containing
\r
16 * Unicode codepoint data.</p>
\r
17 * <p>This class simply reads uprops.icu, authenticates that it is a valid
\r
18 * ICU data file and split its contents up into blocks of data for use in
\r
19 * <a href=UCharacterProperty.html>com.ibm.icu.impl.UCharacterProperty</a>.
\r
21 * <p>uprops.icu which is in big-endian format is jared together with this
\r
24 * Unicode character properties file format see
\r
25 * (ICU4C)/source/tools/genprops/store.c
\r
27 * @author Syn Wee Quek
\r
28 * @since release 2.1, February 1st 2002
\r
30 final class UCharacterPropertyReader implements ICUBinary.Authenticate
\r
32 // public methods ----------------------------------------------------
\r
34 public boolean isDataVersionAcceptable(byte version[])
\r
36 return version[0] == DATA_FORMAT_VERSION_[0]
\r
37 && version[2] == DATA_FORMAT_VERSION_[2]
\r
38 && version[3] == DATA_FORMAT_VERSION_[3];
\r
41 // protected constructor ---------------------------------------------
\r
44 * <p>Protected constructor.</p>
\r
45 * @param inputStream ICU uprop.dat file input stream
\r
46 * @exception IOException throw if data file fails authentication
\r
48 protected UCharacterPropertyReader(InputStream inputStream)
\r
51 m_unicodeVersion_ = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID_,
\r
53 m_dataInputStream_ = new DataInputStream(inputStream);
\r
56 // protected methods -------------------------------------------------
\r
59 * <p>Reads uprops.icu, parse it into blocks of data to be stored in
\r
60 * UCharacterProperty.</P
\r
61 * @param ucharppty UCharacterProperty instance
\r
62 * @exception IOException thrown when data reading fails
\r
64 protected void read(UCharacterProperty ucharppty) throws IOException
\r
67 int count = INDEX_SIZE_;
\r
68 m_propertyOffset_ = m_dataInputStream_.readInt();
\r
70 m_exceptionOffset_ = m_dataInputStream_.readInt();
\r
72 m_caseOffset_ = m_dataInputStream_.readInt();
\r
74 m_additionalOffset_ = m_dataInputStream_.readInt();
\r
76 m_additionalVectorsOffset_ = m_dataInputStream_.readInt();
\r
78 m_additionalColumnsCount_ = m_dataInputStream_.readInt();
\r
80 m_reservedOffset_ = m_dataInputStream_.readInt();
\r
82 m_dataInputStream_.skipBytes(3 << 2);
\r
84 ucharppty.m_maxBlockScriptValue_ = m_dataInputStream_.readInt();
\r
86 ucharppty.m_maxJTGValue_ = m_dataInputStream_.readInt();
\r
88 m_dataInputStream_.skipBytes(count << 2);
\r
90 // read the trie index block
\r
91 // m_props_index_ in terms of ints
\r
92 ucharppty.m_trie_ = new CharTrie(m_dataInputStream_, null);
\r
94 // skip the 32 bit properties block
\r
95 int size = m_exceptionOffset_ - m_propertyOffset_;
\r
96 m_dataInputStream_.skipBytes(size * 4);
\r
98 // reads the 32 bit exceptions block
\r
99 size = m_caseOffset_ - m_exceptionOffset_;
\r
100 m_dataInputStream_.skipBytes(size * 4);
\r
102 // reads the 32 bit case block
\r
103 size = (m_additionalOffset_ - m_caseOffset_) << 1;
\r
104 m_dataInputStream_.skipBytes(size * 2);
\r
106 if(m_additionalColumnsCount_ > 0) {
\r
107 // reads the additional property block
\r
108 ucharppty.m_additionalTrie_ = new CharTrie(m_dataInputStream_, null);
\r
110 // additional properties
\r
111 size = m_reservedOffset_ - m_additionalVectorsOffset_;
\r
112 ucharppty.m_additionalVectors_ = new int[size];
\r
113 for (int i = 0; i < size; i ++) {
\r
114 ucharppty.m_additionalVectors_[i] = m_dataInputStream_.readInt();
\r
118 m_dataInputStream_.close();
\r
119 ucharppty.m_additionalColumnsCount_ = m_additionalColumnsCount_;
\r
120 ucharppty.m_unicodeVersion_ = VersionInfo.getInstance(
\r
121 (int)m_unicodeVersion_[0], (int)m_unicodeVersion_[1],
\r
122 (int)m_unicodeVersion_[2], (int)m_unicodeVersion_[3]);
\r
125 // private variables -------------------------------------------------
\r
130 private static final int INDEX_SIZE_ = 16;
\r
133 * ICU data file input stream
\r
135 private DataInputStream m_dataInputStream_;
\r
138 * Offset information in the indexes.
\r
140 private int m_propertyOffset_;
\r
141 private int m_exceptionOffset_;
\r
142 private int m_caseOffset_;
\r
143 private int m_additionalOffset_;
\r
144 private int m_additionalVectorsOffset_;
\r
145 private int m_additionalColumnsCount_;
\r
146 private int m_reservedOffset_;
\r
147 private byte m_unicodeVersion_[];
\r
150 * Data format "UPro".
\r
152 private static final byte DATA_FORMAT_ID_[] = {(byte)0x55, (byte)0x50,
\r
153 (byte)0x72, (byte)0x6F};
\r
155 * Format version; this code works with all versions with the same major
\r
156 * version number and the same Trie bit distribution.
\r
158 private static final byte DATA_FORMAT_VERSION_[] = {(byte)0x5, (byte)0,
\r
159 (byte)Trie.INDEX_STAGE_1_SHIFT_,
\r
160 (byte)Trie.INDEX_STAGE_2_SHIFT_};
\r