Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/net/idn/StringPrepDataReader.java
38918 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/23/*24/*25******************************************************************************26* Copyright (C) 2003, International Business Machines Corporation and *27* others. All Rights Reserved. *28******************************************************************************29*30* Created on May 2, 200331*32* To change the template for this generated file go to33* Window>Preferences>Java>Code Generation>Code and Comments34*/35// CHANGELOG36// 2005-05-19 Edward Wang37// - copy this file from icu4jsrc_3_2/src/com/ibm/icu/impl/StringPrepDataReader.java38// - move from package com.ibm.icu.impl to package sun.net.idn39//40package sun.net.idn;4142import java.io.DataInputStream;43import java.io.IOException;44import java.io.InputStream;4546import sun.text.normalizer.ICUBinary;474849/**50* @author ram51*52* To change the template for this generated type comment go to53* Window>Preferences>Java>Code Generation>Code and Comments54*/55final class StringPrepDataReader implements ICUBinary.Authenticate {5657/**58* <p>private constructor.</p>59* @param inputStream ICU uprop.dat file input stream60* @exception IOException throw if data file fails authentication61* @draft 2.162*/63public StringPrepDataReader(InputStream inputStream)64throws IOException{6566unicodeVersion = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this);676869dataInputStream = new DataInputStream(inputStream);7071}7273public void read(byte[] idnaBytes,74char[] mappingTable)75throws IOException{7677//Read the bytes that make up the idnaTrie78dataInputStream.read(idnaBytes);7980//Read the extra data81for(int i=0;i<mappingTable.length;i++){82mappingTable[i]=dataInputStream.readChar();83}84}8586public byte[] getDataFormatVersion(){87return DATA_FORMAT_VERSION;88}8990public boolean isDataVersionAcceptable(byte version[]){91return version[0] == DATA_FORMAT_VERSION[0]92&& version[2] == DATA_FORMAT_VERSION[2]93&& version[3] == DATA_FORMAT_VERSION[3];94}95public int[] readIndexes(int length)throws IOException{96int[] indexes = new int[length];97//Read the indexes98for (int i = 0; i <length ; i++) {99indexes[i] = dataInputStream.readInt();100}101return indexes;102}103104public byte[] getUnicodeVersion(){105return unicodeVersion;106}107// private data members -------------------------------------------------108109110/**111* ICU data file input stream112*/113private DataInputStream dataInputStream;114private byte[] unicodeVersion;115/**116* File format version that this class understands.117* No guarantees are made if a older version is used118* see store.c of gennorm for more information and values119*/120///* dataFormat="SPRP" 0x53, 0x50, 0x52, 0x50 */121private static final byte DATA_FORMAT_ID[] = {(byte)0x53, (byte)0x50,122(byte)0x52, (byte)0x50};123private static final byte DATA_FORMAT_VERSION[] = {(byte)0x3, (byte)0x2,124(byte)0x5, (byte)0x2};125126}127128129