1 /*
   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 it
   5  * under the terms of the GNU General Public License version 2 only, as
   6  * published by the Free Software Foundation.  Oracle designates this
   7  * particular file as subject to the "Classpath" exception as provided
   8  * 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 WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 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 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * 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, 2003
  32  *
  33  * To change the template for this generated file go to
  34  * Window>Preferences>Java>Code Generation>Code and Comments
  35  */
  36 // CHANGELOG
  37 //      2005-05-19 Edward Wang
  38 //          - copy this file from icu4jsrc_3_2/src/com/ibm/icu/impl/StringPrepDataReader.java
  39 //          - move from package com.ibm.icu.impl to package sun.net.idn
  40 //
  41 package sun.net.idn;
  42 
  43 import java.io.DataInputStream;
  44 import java.io.IOException;
  45 import java.io.InputStream;
  46 
  47 import sun.text.normalizer.ICUBinary;
  48 
  49 
  50 /**
  51  * @author ram
  52  *
  53  * To change the template for this generated type comment go to
  54  * Window>Preferences>Java>Code Generation>Code and Comments
  55  */
  56 final class StringPrepDataReader implements ICUBinary.Authenticate {
  57 
  58    /**
  59     * <p>private constructor.</p>
  60     * @param inputStream ICU uprop.dat file input stream
  61     * @exception IOException throw if data file fails authentication
  62     * @draft 2.1
  63     */
  64     public StringPrepDataReader(InputStream inputStream)
  65                                         throws IOException{
  66 
  67         unicodeVersion = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this);
  68 
  69 
  70         dataInputStream = new DataInputStream(inputStream);
  71 
  72     }
  73 
  74     public void read(byte[] idnaBytes,
  75                         char[] mappingTable)
  76                         throws IOException{
  77 
  78         //Read the bytes that make up the idnaTrie
  79         dataInputStream.read(idnaBytes);
  80 
  81         //Read the extra data
  82         for(int i=0;i<mappingTable.length;i++){
  83             mappingTable[i]=dataInputStream.readChar();
  84         }
  85     }
  86 
  87     public byte[] getDataFormatVersion(){
  88         return DATA_FORMAT_VERSION;
  89     }
  90 
  91     public boolean isDataVersionAcceptable(byte version[]){
  92         return version[0] == DATA_FORMAT_VERSION[0]
  93                && version[2] == DATA_FORMAT_VERSION[2]
  94                && version[3] == DATA_FORMAT_VERSION[3];
  95     }
  96     public int[] readIndexes(int length)throws IOException{
  97         int[] indexes = new int[length];
  98         //Read the indexes
  99         for (int i = 0; i <length ; i++) {
 100              indexes[i] = dataInputStream.readInt();
 101         }
 102         return indexes;
 103     }
 104 
 105     public byte[] getUnicodeVersion(){
 106         return unicodeVersion;
 107     }
 108     // private data members -------------------------------------------------
 109 
 110 
 111     /**
 112     * ICU data file input stream
 113     */
 114     private DataInputStream dataInputStream;
 115     private byte[] unicodeVersion;
 116     /**
 117     * File format version that this class understands.
 118     * No guarantees are made if a older version is used
 119     * see store.c of gennorm for more information and values
 120     */
 121     ///* dataFormat="SPRP" 0x53, 0x50, 0x52, 0x50  */
 122     private static final byte DATA_FORMAT_ID[] = {(byte)0x53, (byte)0x50,
 123                                                     (byte)0x52, (byte)0x50};
 124     private static final byte DATA_FORMAT_VERSION[] = {(byte)0x3, (byte)0x2,
 125                                                         (byte)0x5, (byte)0x2};
 126 
 127 }