1 7 package com.ibm.icu.impl; 8 9 import java.io.InputStream ; 10 import java.io.DataInputStream ; 11 import java.io.IOException ; 12 import com.ibm.icu.util.VersionInfo; 13 14 30 final class UCharacterPropertyReader implements ICUBinary.Authenticate 31 { 32 34 public boolean isDataVersionAcceptable(byte version[]) 35 { 36 return version[0] == DATA_FORMAT_VERSION_[0] 37 && version[2] == DATA_FORMAT_VERSION_[2] 38 && version[3] == DATA_FORMAT_VERSION_[3]; 39 } 40 41 43 49 protected UCharacterPropertyReader(InputStream inputStream) 50 throws IOException 51 { 52 m_unicodeVersion_ = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID_, 53 this); 54 m_dataInputStream_ = new DataInputStream (inputStream); 55 } 56 57 59 66 protected void read(UCharacterProperty ucharppty) throws IOException 67 { 68 int count = INDEX_SIZE_; 70 m_propertyOffset_ = m_dataInputStream_.readInt(); 71 count --; 72 m_exceptionOffset_ = m_dataInputStream_.readInt(); 73 count --; 74 m_caseOffset_ = m_dataInputStream_.readInt(); 75 count --; 76 m_additionalOffset_ = m_dataInputStream_.readInt(); 77 count --; 78 m_additionalVectorsOffset_ = m_dataInputStream_.readInt(); 79 count --; 80 m_additionalColumnsCount_ = m_dataInputStream_.readInt(); 81 count --; 82 m_reservedOffset_ = m_dataInputStream_.readInt(); 83 count --; 84 m_dataInputStream_.skipBytes(3 << 2); 85 count -= 3; 86 ucharppty.m_maxBlockScriptValue_ = m_dataInputStream_.readInt(); 87 count --; ucharppty.m_maxJTGValue_ = m_dataInputStream_.readInt(); 89 count --; m_dataInputStream_.skipBytes(count << 2); 91 92 ucharppty.m_trie_ = new CharTrie(m_dataInputStream_, null); 95 96 int size = m_exceptionOffset_ - m_propertyOffset_; 98 m_dataInputStream_.skipBytes(size * 4); 99 100 size = m_caseOffset_ - m_exceptionOffset_; 102 m_dataInputStream_.skipBytes(size * 4); 103 104 size = (m_additionalOffset_ - m_caseOffset_) << 1; 106 m_dataInputStream_.skipBytes(size * 2); 107 108 if(m_additionalColumnsCount_ > 0) { 109 ucharppty.m_additionalTrie_ = new CharTrie(m_dataInputStream_, null); 111 112 size = m_reservedOffset_ - m_additionalVectorsOffset_; 114 ucharppty.m_additionalVectors_ = new int[size]; 115 for (int i = 0; i < size; i ++) { 116 ucharppty.m_additionalVectors_[i] = m_dataInputStream_.readInt(); 117 } 118 } 119 120 m_dataInputStream_.close(); 121 ucharppty.m_additionalColumnsCount_ = m_additionalColumnsCount_; 122 ucharppty.m_unicodeVersion_ = VersionInfo.getInstance( 123 (int)m_unicodeVersion_[0], (int)m_unicodeVersion_[1], 124 (int)m_unicodeVersion_[2], (int)m_unicodeVersion_[3]); 125 } 126 127 129 132 private static final int INDEX_SIZE_ = 16; 133 134 137 private DataInputStream m_dataInputStream_; 138 139 142 private int m_propertyOffset_; 143 private int m_exceptionOffset_; 144 private int m_caseOffset_; 145 private int m_additionalOffset_; 146 private int m_additionalVectorsOffset_; 147 private int m_additionalColumnsCount_; 148 private int m_reservedOffset_; 149 private byte m_unicodeVersion_[]; 150 151 154 private static final byte DATA_FORMAT_ID_[] = {(byte)0x55, (byte)0x50, 155 (byte)0x72, (byte)0x6F}; 156 160 private static final byte DATA_FORMAT_VERSION_[] = {(byte)0x4, (byte)0, 161 (byte)Trie.INDEX_STAGE_1_SHIFT_, 162 (byte)Trie.INDEX_STAGE_2_SHIFT_}; 163 } 164 | Popular Tags |