1 // 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 ****************************************************************************** 5 * Copyright (C) 2003-2015, International Business Machines Corporation and 6 * others. All Rights Reserved. 7 ****************************************************************************** 8 * 9 * Created on May 2, 2003 10 * 11 * To change the template for this generated file go to 12 * Window>Preferences>Java>Code Generation>Code and Comments 13 */ 14 15 package com.ibm.icu.impl; 16 17 import java.io.IOException; 18 import java.nio.ByteBuffer; 19 20 21 /** 22 * @author ram 23 * 24 * To change the template for this generated type comment go to 25 * Window>Preferences>Java>Code Generation>Code and Comments 26 */ 27 public final class StringPrepDataReader implements ICUBinary.Authenticate { 28 private final static boolean debug = ICUDebug.enabled("NormalizerDataReader"); 29 30 /** 31 * <p>private constructor.</p> 32 * @param bytes ICU StringPrep data file buffer 33 * @exception IOException throw if data file fails authentication 34 */ 35 public StringPrepDataReader(ByteBuffer bytes) 36 throws IOException{ 37 if(debug) System.out.println("Bytes in buffer " + bytes.remaining()); 38 39 byteBuffer = bytes; 40 unicodeVersion = ICUBinary.readHeader(byteBuffer, DATA_FORMAT_ID, this); 41 42 if(debug) System.out.println("Bytes left in byteBuffer " + byteBuffer.remaining()); 43 } 44 45 public char[] read(int length) throws IOException{ 46 //Read the extra data 47 return ICUBinary.getChars(byteBuffer, length, 0); 48 } 49 50 @Override 51 public boolean isDataVersionAcceptable(byte version[]){ 52 return version[0] == DATA_FORMAT_VERSION[0] 53 && version[2] == DATA_FORMAT_VERSION[2] 54 && version[3] == DATA_FORMAT_VERSION[3]; 55 } 56 public int[] readIndexes(int length)throws IOException{ 57 int[] indexes = new int[length]; 58 //Read the indexes 59 for (int i = 0; i <length ; i++) { 60 indexes[i] = byteBuffer.getInt(); 61 } 62 return indexes; 63 } 64 65 public byte[] getUnicodeVersion(){ 66 return ICUBinary.getVersionByteArrayFromCompactInt(unicodeVersion); 67 } 68 // private data members ------------------------------------------------- 69 70 71 /** 72 * ICU data file input stream 73 */ 74 private ByteBuffer byteBuffer; 75 private int unicodeVersion; 76 /** 77 * File format version that this class understands. 78 * No guarantees are made if a older version is used 79 * see store.c of gennorm for more information and values 80 */ 81 ///* dataFormat="SPRP" 0x53, 0x50, 0x52, 0x50 */ 82 private static final int DATA_FORMAT_ID = 0x53505250; 83 private static final byte DATA_FORMAT_VERSION[] = {(byte)0x3, (byte)0x2, 84 (byte)0x5, (byte)0x2}; 85 } 86