KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > icu > impl > StringPrepDataReader


1 /*
2  ******************************************************************************
3  * Copyright (C) 2003, International Business Machines Corporation and *
4  * others. All Rights Reserved. *
5  ******************************************************************************
6  *
7  * Created on May 2, 2003
8  *
9  * To change the template for this generated file go to
10  * Window>Preferences>Java>Code Generation>Code and Comments
11  */

12 package com.ibm.icu.impl;
13
14 import java.io.DataInputStream JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.io.InputStream JavaDoc;
17
18
19
20 /**
21  * @author ram
22  *
23  * To change the template for this generated type comment go to
24  * Window>Preferences>Java>Code Generation>Code and Comments
25  */

26 public final class StringPrepDataReader implements ICUBinary.Authenticate {
27     private final static boolean debug = ICUDebug.enabled("NormalizerDataReader");
28     
29    /**
30     * <p>private constructor.</p>
31     * @param inputStream ICU uprop.dat file input stream
32     * @exception IOException throw if data file fails authentication
33     * @draft 2.1
34     */

35     public StringPrepDataReader(InputStream JavaDoc inputStream)
36                                         throws IOException JavaDoc{
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 JavaDoc(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 JavaDoc{
51
52         //Read the bytes that make up the idnaTrie
53
dataInputStream.read(idnaBytes);
54         
55         //Read the extra data
56
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 JavaDoc{
71         int[] indexes = new int[length];
72         //Read the indexes
73
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     // private data members -------------------------------------------------
83

84
85     /**
86     * ICU data file input stream
87     */

88     private DataInputStream JavaDoc dataInputStream;
89     private byte[] unicodeVersion;
90     /**
91     * File format version that this class understands.
92     * No guarantees are made if a older version is used
93     * see store.c of gennorm for more information and values
94     */

95     ///* dataFormat="SPRP" 0x53, 0x50, 0x52, 0x50 */
96
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