jdk/src/share/classes/sun/net/idn/StringPrepDataReader.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     6
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 ******************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Copyright (C) 2003, International Business Machines Corporation and   *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * others. All Rights Reserved.                                               *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 ******************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Created on May 2, 2003
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * To change the template for this generated file go to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Window>Preferences>Java>Code Generation>Code and Comments
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
// CHANGELOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
//      2005-05-19 Edward Wang
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
//          - copy this file from icu4jsrc_3_2/src/com/ibm/icu/impl/StringPrepDataReader.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
//          - move from package com.ibm.icu.impl to package sun.net.idn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
package sun.net.idn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.DataInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.text.normalizer.ICUBinary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author ram
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * To change the template for this generated type comment go to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Window>Preferences>Java>Code Generation>Code and Comments
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
final class StringPrepDataReader implements ICUBinary.Authenticate {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    * <p>private constructor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    * @param inputStream ICU uprop.dat file input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    * @exception IOException throw if data file fails authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    * @draft 2.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public StringPrepDataReader(InputStream inputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                        throws IOException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        unicodeVersion = ICUBinary.readHeader(inputStream, DATA_FORMAT_ID, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        dataInputStream = new DataInputStream(inputStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public void read(byte[] idnaBytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                        char[] mappingTable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                        throws IOException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        //Read the bytes that make up the idnaTrie
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        dataInputStream.read(idnaBytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        //Read the extra data
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        for(int i=0;i<mappingTable.length;i++){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            mappingTable[i]=dataInputStream.readChar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public byte[] getDataFormatVersion(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return DATA_FORMAT_VERSION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public boolean isDataVersionAcceptable(byte version[]){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return version[0] == DATA_FORMAT_VERSION[0]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
               && version[2] == DATA_FORMAT_VERSION[2]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
               && version[3] == DATA_FORMAT_VERSION[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public int[] readIndexes(int length)throws IOException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        int[] indexes = new int[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        //Read the indexes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        for (int i = 0; i <length ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
             indexes[i] = dataInputStream.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return indexes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public byte[] getUnicodeVersion(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return unicodeVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // private data members -------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    * ICU data file input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private DataInputStream dataInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private byte[] unicodeVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    * File format version that this class understands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    * No guarantees are made if a older version is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    * see store.c of gennorm for more information and values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    ///* dataFormat="SPRP" 0x53, 0x50, 0x52, 0x50  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static final byte DATA_FORMAT_ID[] = {(byte)0x53, (byte)0x50,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                                    (byte)0x52, (byte)0x50};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private static final byte DATA_FORMAT_VERSION[] = {(byte)0x3, (byte)0x2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                                        (byte)0x5, (byte)0x2};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}