Path: blob/master/src/java.base/share/classes/jdk/internal/icu/impl/StringPrepDataReader.java
41161 views
/*1* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24/*25/*26******************************************************************************27* Copyright (C) 2003, International Business Machines Corporation and *28* others. All Rights Reserved. *29******************************************************************************30*31* Created on May 2, 200332*33* To change the template for this generated file go to34* Window>Preferences>Java>Code Generation>Code and Comments35*/36// CHANGELOG37// 2005-05-19 Edward Wang38// - copy this file from icu4jsrc_3_2/src/com/ibm/icu/impl/StringPrepDataReader.java39// - move from package com.ibm.icu.impl to package sun.net.idn40//41package jdk.internal.icu.impl;4243import java.io.DataInputStream;44import java.io.IOException;45import java.io.InputStream;4647import jdk.internal.icu.impl.ICUBinary;484950/**51* @author ram52*53* To change the template for this generated type comment go to54* Window>Preferences>Java>Code Generation>Code and Comments55*/56public final class StringPrepDataReader implements ICUBinary.Authenticate {5758/**59* <p>private constructor.</p>60* @param inputStream ICU uprop.dat file input stream61* @exception IOException throw if data file fails authentication62* @draft 2.163*/64public StringPrepDataReader(InputStream inputStream)65throws IOException{6667unicodeVersion = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this);686970dataInputStream = new DataInputStream(inputStream);7172}7374public void read(byte[] idnaBytes,75char[] mappingTable)76throws IOException{7778// Read the bytes that make up the idnaTrie79dataInputStream.read(idnaBytes);8081// Read the extra data82for(int i=0;i<mappingTable.length;i++){83mappingTable[i]=dataInputStream.readChar();84}85}8687public byte[] getDataFormatVersion(){88return DATA_FORMAT_VERSION;89}9091public boolean isDataVersionAcceptable(byte version[]){92return version[0] == DATA_FORMAT_VERSION[0]93&& version[2] == DATA_FORMAT_VERSION[2]94&& version[3] == DATA_FORMAT_VERSION[3];95}96public int[] readIndexes(int length) throws IOException{97int[] indexes = new int[length];98// Read the indexes99for (int i = 0; i <length ; i++) {100indexes[i] = dataInputStream.readInt();101}102return indexes;103}104105public byte[] getUnicodeVersion(){106return unicodeVersion;107}108// private data members -------------------------------------------------109110111/**112* ICU data file input stream113*/114private DataInputStream dataInputStream;115private byte[] unicodeVersion;116/**117* File format version that this class understands.118* No guarantees are made if a older version is used119* see store.c of gennorm for more information and values120*/121///* dataFormat="SPRP" 0x53, 0x50, 0x52, 0x50 */122private static final byte DATA_FORMAT_ID[] = {(byte)0x53, (byte)0x50,123(byte)0x52, (byte)0x50};124private static final byte DATA_FORMAT_VERSION[] = {(byte)0x3, (byte)0x2,125(byte)0x5, (byte)0x2};126127}128129130