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