1 12 package com.ibm.icu.impl; 13 14 import java.io.DataInputStream ; 15 import java.io.IOException ; 16 import java.io.InputStream ; 17 18 19 20 26 public final class StringPrepDataReader implements ICUBinary.Authenticate { 27 private final static boolean debug = ICUDebug.enabled("NormalizerDataReader"); 28 29 35 public StringPrepDataReader(InputStream inputStream) 36 throws IOException { 37 if(debug) System.out.println("Bytes in inputStream " + inputStream.available()); 38 39 unicodeVersion = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this); 40 41 if(debug) System.out.println("Bytes left in inputStream " +inputStream.available()); 42 43 dataInputStream = new DataInputStream (inputStream); 44 45 if(debug) System.out.println("Bytes left in dataInputStream " +dataInputStream.available()); 46 } 47 48 public void read(byte[] idnaBytes, 49 char[] mappingTable) 50 throws IOException { 51 52 dataInputStream.read(idnaBytes); 54 55 for(int i=0;i<mappingTable.length;i++){ 57 mappingTable[i]=dataInputStream.readChar(); 58 } 59 } 60 61 public byte[] getDataFormatVersion(){ 62 return DATA_FORMAT_VERSION; 63 } 64 65 public boolean isDataVersionAcceptable(byte version[]){ 66 return version[0] == DATA_FORMAT_VERSION[0] 67 && version[2] == DATA_FORMAT_VERSION[2] 68 && version[3] == DATA_FORMAT_VERSION[3]; 69 } 70 public int[] readIndexes(int length)throws IOException { 71 int[] indexes = new int[length]; 72 for (int i = 0; i <length ; i++) { 74 indexes[i] = dataInputStream.readInt(); 75 } 76 return indexes; 77 } 78 79 public byte[] getUnicodeVersion(){ 80 return unicodeVersion; 81 } 82 84 85 88 private DataInputStream dataInputStream; 89 private byte[] unicodeVersion; 90 95 private static final byte DATA_FORMAT_ID[] = {(byte)0x53, (byte)0x50, 97 (byte)0x52, (byte)0x50}; 98 private static final byte DATA_FORMAT_VERSION[] = {(byte)0x3, (byte)0x2, 99 (byte)0x5, (byte)0x2}; 100 101 } 102 | Popular Tags |