]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_4_2-src/main/classes/core/src/com/ibm/icu/impl/StringPrepDataReader.java
go
[Dictionary.git] / jars / icu4j-4_4_2-src / main / classes / core / src / com / ibm / icu / impl / StringPrepDataReader.java
1 /*\r
2  ******************************************************************************\r
3  * Copyright (C) 2003-2008, International Business Machines Corporation and   *\r
4  * others. All Rights Reserved.                                               *\r
5  ******************************************************************************\r
6  *\r
7  * Created on May 2, 2003\r
8  *\r
9  * To change the template for this generated file go to\r
10  * Window>Preferences>Java>Code Generation>Code and Comments\r
11  */\r
12 package com.ibm.icu.impl;\r
13 \r
14 import java.io.DataInputStream;\r
15 import java.io.IOException;\r
16 import java.io.InputStream;\r
17 \r
18 \r
19 \r
20 /**\r
21  * @author ram\r
22  *\r
23  * To change the template for this generated type comment go to\r
24  * Window>Preferences>Java>Code Generation>Code and Comments\r
25  */\r
26 public final class StringPrepDataReader implements ICUBinary.Authenticate {\r
27     private final static boolean debug = ICUDebug.enabled("NormalizerDataReader");\r
28     \r
29    /**\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
33     */\r
34     public StringPrepDataReader(InputStream inputStream) \r
35                                         throws IOException{\r
36         if(debug) System.out.println("Bytes in inputStream " + inputStream.available());\r
37         \r
38         unicodeVersion = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this);\r
39         \r
40         if(debug) System.out.println("Bytes left in inputStream " +inputStream.available());\r
41         \r
42         dataInputStream = new DataInputStream(inputStream);\r
43         \r
44         if(debug) System.out.println("Bytes left in dataInputStream " +dataInputStream.available());\r
45     }\r
46     \r
47     public void read(byte[] idnaBytes,\r
48                         char[] mappingTable) \r
49                         throws IOException{\r
50 \r
51         //Read the bytes that make up the idnaTrie  \r
52         dataInputStream.readFully(idnaBytes);\r
53         \r
54         //Read the extra data\r
55         for(int i=0;i<mappingTable.length;i++){\r
56             mappingTable[i]=dataInputStream.readChar();\r
57         }\r
58     }\r
59     \r
60     public byte[] getDataFormatVersion(){\r
61         return DATA_FORMAT_VERSION;\r
62     }\r
63     \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
68     }\r
69     public int[] readIndexes(int length)throws IOException{\r
70         int[] indexes = new int[length];\r
71         //Read the indexes\r
72         for (int i = 0; i <length ; i++) {\r
73              indexes[i] = dataInputStream.readInt();\r
74         }\r
75         return indexes;\r
76     } \r
77     \r
78     public byte[] getUnicodeVersion(){\r
79         return unicodeVersion;\r
80     }\r
81     // private data members -------------------------------------------------\r
82       \r
83 \r
84     /**\r
85     * ICU data file input stream\r
86     */\r
87     private DataInputStream dataInputStream;\r
88     private byte[] unicodeVersion;                             \r
89     /**\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
93     */\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
99     \r
100 }\r