1 7 8 package com.ibm.icu.impl; 9 import java.io.*; 10 import com.ibm.icu.impl.ICUDebug; 11 12 16 17 299 final class NormalizerDataReader implements ICUBinary.Authenticate { 300 private final static boolean debug = ICUDebug.enabled("NormalizerDataReader"); 301 302 308 protected NormalizerDataReader(InputStream inputStream) 309 throws IOException{ 310 if(debug) System.out.println("Bytes in inputStream " + inputStream.available()); 311 312 unicodeVersion = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this); 313 314 if(debug) System.out.println("Bytes left in inputStream " +inputStream.available()); 315 316 dataInputStream = new DataInputStream(inputStream); 317 318 if(debug) System.out.println("Bytes left in dataInputStream " +dataInputStream.available()); 319 } 320 321 323 protected int[] readIndexes(int length)throws IOException{ 324 int[] indexes = new int[length]; 325 for (int i = 0; i <length ; i++) { 327 indexes[i] = dataInputStream.readInt(); 328 } 329 return indexes; 330 } 331 343 protected void read(byte[] normBytes, byte[] fcdBytes, byte[] auxBytes, 344 char[] extraData, char[] combiningTable, 345 Object [] canonStartSets) 346 throws IOException{ 347 348 dataInputStream.read(normBytes); 350 351 353 for(int i=0;i<extraData.length;i++){ 355 extraData[i]=dataInputStream.readChar(); 356 } 357 358 for(int i=0; i<combiningTable.length; i++){ 360 combiningTable[i]=dataInputStream.readChar(); 361 } 362 363 dataInputStream.read(fcdBytes); 365 366 367 dataInputStream.read(auxBytes); 369 370 int[] canonStartSetsIndexes = new int[NormalizerImpl.SET_INDEX_TOP]; 372 373 for(int i=0; i<canonStartSetsIndexes.length; i++){ 374 canonStartSetsIndexes[i]=dataInputStream.readChar(); 375 } 376 377 char[] startSets = new char[canonStartSetsIndexes[NormalizerImpl.SET_INDEX_CANON_SETS_LENGTH]-NormalizerImpl.SET_INDEX_TOP]; 378 379 for(int i=0; i<startSets.length; i++){ 380 startSets[i]=dataInputStream.readChar(); 381 } 382 char[] bmpTable = new char[canonStartSetsIndexes[NormalizerImpl.SET_INDEX_CANON_BMP_TABLE_LENGTH]]; 383 for(int i=0; i<bmpTable.length; i++){ 384 bmpTable[i]=dataInputStream.readChar(); 385 } 386 char[] suppTable = new char[canonStartSetsIndexes[NormalizerImpl.SET_INDEX_CANON_SUPP_TABLE_LENGTH]]; 387 for(int i=0; i<suppTable.length; i++){ 388 suppTable[i]=dataInputStream.readChar(); 389 } 390 canonStartSets[NormalizerImpl.CANON_SET_INDICIES_INDEX ] = canonStartSetsIndexes; 391 canonStartSets[NormalizerImpl.CANON_SET_START_SETS_INDEX] = startSets; 392 canonStartSets[NormalizerImpl.CANON_SET_BMP_TABLE_INDEX ] = bmpTable; 393 canonStartSets[NormalizerImpl.CANON_SET_SUPP_TABLE_INDEX] = suppTable; 394 } 395 396 public byte[] getDataFormatVersion(){ 397 return DATA_FORMAT_VERSION; 398 } 399 400 public boolean isDataVersionAcceptable(byte version[]) 401 { 402 return version[0] == DATA_FORMAT_VERSION[0] 403 && version[2] == DATA_FORMAT_VERSION[2] 404 && version[3] == DATA_FORMAT_VERSION[3]; 405 } 406 407 public byte[] getUnicodeVersion(){ 408 return unicodeVersion; 409 } 410 412 413 416 private DataInputStream dataInputStream; 417 418 private byte[] unicodeVersion; 419 420 425 private static final byte DATA_FORMAT_ID[] = {(byte)0x4E, (byte)0x6F, 426 (byte)0x72, (byte)0x6D}; 427 private static final byte DATA_FORMAT_VERSION[] = {(byte)0x2, (byte)0x2, 428 (byte)0x5, (byte)0x2}; 429 430 } 431 | Popular Tags |