]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/impl/StringPrepDataReader.java
Clean up imports.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / impl / StringPrepDataReader.java
1 /*
2  ******************************************************************************
3  * Copyright (C) 2003-2008, 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;
15 import java.io.IOException;
16 import java.io.InputStream;
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     */
34     public StringPrepDataReader(InputStream inputStream) 
35                                         throws IOException{
36         if(debug) System.out.println("Bytes in inputStream " + inputStream.available());
37         
38         unicodeVersion = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this);
39         
40         if(debug) System.out.println("Bytes left in inputStream " +inputStream.available());
41         
42         dataInputStream = new DataInputStream(inputStream);
43         
44         if(debug) System.out.println("Bytes left in dataInputStream " +dataInputStream.available());
45     }
46     
47     public void read(byte[] idnaBytes,
48                         char[] mappingTable) 
49                         throws IOException{
50
51         //Read the bytes that make up the idnaTrie  
52         dataInputStream.readFully(idnaBytes);
53         
54         //Read the extra data
55         for(int i=0;i<mappingTable.length;i++){
56             mappingTable[i]=dataInputStream.readChar();
57         }
58     }
59     
60     public byte[] getDataFormatVersion(){
61         return DATA_FORMAT_VERSION;
62     }
63     
64     public boolean isDataVersionAcceptable(byte version[]){
65         return version[0] == DATA_FORMAT_VERSION[0] 
66                && version[2] == DATA_FORMAT_VERSION[2] 
67                && version[3] == DATA_FORMAT_VERSION[3];
68     }
69     public int[] readIndexes(int length)throws IOException{
70         int[] indexes = new int[length];
71         //Read the indexes
72         for (int i = 0; i <length ; i++) {
73              indexes[i] = dataInputStream.readInt();
74         }
75         return indexes;
76     } 
77     
78     public byte[] getUnicodeVersion(){
79         return unicodeVersion;
80     }
81     // private data members -------------------------------------------------
82       
83
84     /**
85     * ICU data file input stream
86     */
87     private DataInputStream dataInputStream;
88     private byte[] unicodeVersion;                             
89     /**
90     * File format version that this class understands.
91     * No guarantees are made if a older version is used
92     * see store.c of gennorm for more information and values
93     */
94     ///* dataFormat="SPRP" 0x53, 0x50, 0x52, 0x50  */ 
95     private static final byte DATA_FORMAT_ID[] = {(byte)0x53, (byte)0x50, 
96                                                     (byte)0x52, (byte)0x50};
97     private static final byte DATA_FORMAT_VERSION[] = {(byte)0x3, (byte)0x2, 
98                                                         (byte)0x5, (byte)0x2};
99     
100 }