2 ******************************************************************************
\r
3 * Copyright (C) 2003-2008, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 ******************************************************************************
\r
7 * Created on May 2, 2003
\r
9 * To change the template for this generated file go to
\r
10 * Window>Preferences>Java>Code Generation>Code and Comments
\r
12 package com.ibm.icu.impl;
\r
14 import java.io.DataInputStream;
\r
15 import java.io.IOException;
\r
16 import java.io.InputStream;
\r
23 * To change the template for this generated type comment go to
\r
24 * Window>Preferences>Java>Code Generation>Code and Comments
\r
26 public final class StringPrepDataReader implements ICUBinary.Authenticate {
\r
27 private final static boolean debug = ICUDebug.enabled("NormalizerDataReader");
\r
30 * <p>private constructor.</p>
\r
31 * @param inputStream ICU uprop.dat file input stream
\r
32 * @exception IOException throw if data file fails authentication
\r
34 public StringPrepDataReader(InputStream inputStream)
\r
36 if(debug) System.out.println("Bytes in inputStream " + inputStream.available());
\r
38 unicodeVersion = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this);
\r
40 if(debug) System.out.println("Bytes left in inputStream " +inputStream.available());
\r
42 dataInputStream = new DataInputStream(inputStream);
\r
44 if(debug) System.out.println("Bytes left in dataInputStream " +dataInputStream.available());
\r
47 public void read(byte[] idnaBytes,
\r
48 char[] mappingTable)
\r
51 //Read the bytes that make up the idnaTrie
\r
52 dataInputStream.readFully(idnaBytes);
\r
54 //Read the extra data
\r
55 for(int i=0;i<mappingTable.length;i++){
\r
56 mappingTable[i]=dataInputStream.readChar();
\r
60 public byte[] getDataFormatVersion(){
\r
61 return DATA_FORMAT_VERSION;
\r
64 public boolean isDataVersionAcceptable(byte version[]){
\r
65 return version[0] == DATA_FORMAT_VERSION[0]
\r
66 && version[2] == DATA_FORMAT_VERSION[2]
\r
67 && version[3] == DATA_FORMAT_VERSION[3];
\r
69 public int[] readIndexes(int length)throws IOException{
\r
70 int[] indexes = new int[length];
\r
72 for (int i = 0; i <length ; i++) {
\r
73 indexes[i] = dataInputStream.readInt();
\r
78 public byte[] getUnicodeVersion(){
\r
79 return unicodeVersion;
\r
81 // private data members -------------------------------------------------
\r
85 * ICU data file input stream
\r
87 private DataInputStream dataInputStream;
\r
88 private byte[] unicodeVersion;
\r
90 * File format version that this class understands.
\r
91 * No guarantees are made if a older version is used
\r
92 * see store.c of gennorm for more information and values
\r
94 ///* dataFormat="SPRP" 0x53, 0x50, 0x52, 0x50 */
\r
95 private static final byte DATA_FORMAT_ID[] = {(byte)0x53, (byte)0x50,
\r
96 (byte)0x52, (byte)0x50};
\r
97 private static final byte DATA_FORMAT_VERSION[] = {(byte)0x3, (byte)0x2,
\r
98 (byte)0x5, (byte)0x2};
\r