001: /*
002: ******************************************************************************
003: * Copyright (C) 2003, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: ******************************************************************************
006: *
007: * Created on May 2, 2003
008: *
009: * To change the template for this generated file go to
010: * Window>Preferences>Java>Code Generation>Code and Comments
011: */
012: package com.ibm.icu.impl;
013:
014: import java.io.DataInputStream;
015: import java.io.IOException;
016: import java.io.InputStream;
017:
018: /**
019: * @author ram
020: *
021: * To change the template for this generated type comment go to
022: * Window>Preferences>Java>Code Generation>Code and Comments
023: */
024: public final class StringPrepDataReader implements
025: ICUBinary.Authenticate {
026: private final static boolean debug = ICUDebug
027: .enabled("NormalizerDataReader");
028:
029: /**
030: * <p>private constructor.</p>
031: * @param inputStream ICU uprop.dat file input stream
032: * @exception IOException throw if data file fails authentication
033: * @draft 2.1
034: */
035: public StringPrepDataReader(InputStream inputStream)
036: throws IOException {
037: if (debug)
038: System.out.println("Bytes in inputStream "
039: + inputStream.available());
040:
041: unicodeVersion = ICUBinary.readHeader(inputStream,
042: DATA_FORMAT_ID, this );
043:
044: if (debug)
045: System.out.println("Bytes left in inputStream "
046: + inputStream.available());
047:
048: dataInputStream = new DataInputStream(inputStream);
049:
050: if (debug)
051: System.out.println("Bytes left in dataInputStream "
052: + dataInputStream.available());
053: }
054:
055: public void read(byte[] idnaBytes, char[] mappingTable)
056: throws IOException {
057:
058: //Read the bytes that make up the idnaTrie
059: dataInputStream.read(idnaBytes);
060:
061: //Read the extra data
062: for (int i = 0; i < mappingTable.length; i++) {
063: mappingTable[i] = dataInputStream.readChar();
064: }
065: }
066:
067: public byte[] getDataFormatVersion() {
068: return DATA_FORMAT_VERSION;
069: }
070:
071: public boolean isDataVersionAcceptable(byte version[]) {
072: return version[0] == DATA_FORMAT_VERSION[0]
073: && version[2] == DATA_FORMAT_VERSION[2]
074: && version[3] == DATA_FORMAT_VERSION[3];
075: }
076:
077: public int[] readIndexes(int length) throws IOException {
078: int[] indexes = new int[length];
079: //Read the indexes
080: for (int i = 0; i < length; i++) {
081: indexes[i] = dataInputStream.readInt();
082: }
083: return indexes;
084: }
085:
086: public byte[] getUnicodeVersion() {
087: return unicodeVersion;
088: }
089:
090: // private data members -------------------------------------------------
091:
092: /**
093: * ICU data file input stream
094: */
095: private DataInputStream dataInputStream;
096: private byte[] unicodeVersion;
097: /**
098: * File format version that this class understands.
099: * No guarantees are made if a older version is used
100: * see store.c of gennorm for more information and values
101: */
102: ///* dataFormat="SPRP" 0x53, 0x50, 0x52, 0x50 */
103: private static final byte DATA_FORMAT_ID[] = { (byte) 0x53,
104: (byte) 0x50, (byte) 0x52, (byte) 0x50 };
105: private static final byte DATA_FORMAT_VERSION[] = { (byte) 0x3,
106: (byte) 0x2, (byte) 0x5, (byte) 0x2 };
107:
108: }
|