ICU-1586
Shifted common ICU binary data header reading to class ICUBinary. ICUBinary will have to be shifted during the ICU4J reorganization. X-SVN-Rev: 7611
This commit is contained in:
parent
372280d1aa
commit
21222853da
150
icu4j/src/com/ibm/icu/impl/ICUBinary.java
Executable file
150
icu4j/src/com/ibm/icu/impl/ICUBinary.java
Executable file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ICUBinary.java,v $
|
||||
* $Date: 2002/02/08 23:22:40 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.internal;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class ICUBinary
|
||||
{
|
||||
/**
|
||||
* <p>ICU data header reader method.
|
||||
* Takes a ICU generated big-endian input stream, parse the ICU standard
|
||||
* file header and authenticates them.</p>
|
||||
* <p>Header format:
|
||||
* <ul>
|
||||
* <li> Header size (char)
|
||||
* <li> Magic number 1 (byte)
|
||||
* <li> Magic number 2 (byte)
|
||||
* <li> Rest of the header size (char)
|
||||
* <li> Reserved word (char)
|
||||
* <li> Big endian indicator (byte)
|
||||
* <li> Character set family indicator (byte)
|
||||
* <li> Size of a char (byte) for c++ and c use
|
||||
* <li> Reserved byte (byte)
|
||||
* <li> Data format identifier (4 bytes), each ICU data has its own
|
||||
* identifier to distinguish them. [0] major [1] minor
|
||||
* [2] milli [3] micro
|
||||
* <li> Data version (4 bytes), the change version of the ICU data
|
||||
* [0] major [1] minor [2] milli [3] micro
|
||||
* <li> Unicode version (4 bytes) this ICU is based on.
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
* Example of use:<br>
|
||||
* <pre>
|
||||
* try {
|
||||
* FileInputStream input = new FileInputStream(filename);
|
||||
* If (Utility.readICUDataHeader(input, dataformat, dataversion,
|
||||
* unicode) {
|
||||
* System.out.println("Verified file header, this is a ICU data file");
|
||||
* }
|
||||
* } catch (IOException e) {
|
||||
* System.out.println("This is not a ICU data file");
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
* @param inputStream input stream that contains the ICU data header
|
||||
* @param dataFormatIDExpected Data format expected. An array of 4 bytes
|
||||
* information about the data format.
|
||||
* E.g. data format ID 1.2.3.4. will became an array of
|
||||
* {1, 2, 3, 4}
|
||||
* @param dataVersionExpected Data version expected. An array of 4 bytes
|
||||
* information about the data version.
|
||||
* E.g. data version 1.2.3.4. will became an array of
|
||||
* {1, 2, 3, 4}
|
||||
* @param unicodeVersionExpected Unicode version expected. An array of 4
|
||||
* bytes information about the unicode
|
||||
* version this set of data belongs to.
|
||||
* E.g. unicode version 3.1.1.0. will became an array
|
||||
* of {3, 1, 1, 0}
|
||||
* @exception IOException thrown if there is a read error or
|
||||
* when header authentication fails.
|
||||
* @draft 2.1
|
||||
*/
|
||||
public static final void readHeader(InputStream inputStream,
|
||||
byte dataFormatIDExpected[],
|
||||
byte dataVersionExpected[],
|
||||
byte unicodeVersionExpected[])
|
||||
throws IOException
|
||||
{
|
||||
DataInputStream input = new DataInputStream(inputStream);
|
||||
char headersize = input.readChar();
|
||||
headersize -= 2;
|
||||
//reading the header format
|
||||
byte magic1 = input.readByte();
|
||||
headersize --;
|
||||
byte magic2 = input.readByte();
|
||||
headersize --;
|
||||
if (magic1 != MAGIC1 || magic2 != MAGIC2) {
|
||||
throw new IOException(MAGIC_NUMBER_AUTHENTICATION_FAILED_);
|
||||
}
|
||||
|
||||
input.readChar(); // reading size
|
||||
headersize -= 2;
|
||||
input.readChar(); // reading reserved word
|
||||
headersize -= 2;
|
||||
byte bigendian = input.readByte();
|
||||
headersize --;
|
||||
byte charset = input.readByte();
|
||||
headersize --;
|
||||
byte charsize = input.readByte();
|
||||
headersize --;
|
||||
input.readByte(); // reading reserved byte
|
||||
headersize --;
|
||||
|
||||
byte dataFormatID[] = new byte[4];
|
||||
input.readFully(dataFormatID);
|
||||
headersize -= 4;
|
||||
byte dataVersion[] = new byte[4];
|
||||
input.readFully(dataVersion);
|
||||
headersize -= 4;
|
||||
byte unicodeVersion[] = new byte[4];
|
||||
input.readFully(unicodeVersion);
|
||||
headersize -= 4;
|
||||
input.skipBytes(headersize);
|
||||
|
||||
if (bigendian != BIG_ENDIAN_ || charset != CHAR_SET_ ||
|
||||
charsize != CHAR_SIZE_ ||
|
||||
!Arrays.equals(dataFormatIDExpected, dataFormatID) ||
|
||||
!Arrays.equals(dataVersionExpected, dataVersion) ||
|
||||
!Arrays.equals(unicodeVersionExpected, unicodeVersion)) {
|
||||
throw new IOException(HEADER_AUTHENTICATION_FAILED_);
|
||||
}
|
||||
}
|
||||
|
||||
// private variables -------------------------------------------------
|
||||
|
||||
/**
|
||||
* Magic numbers to authenticate the data file
|
||||
*/
|
||||
private static final byte MAGIC1 = (byte)0xda;
|
||||
private static final byte MAGIC2 = (byte)0x27;
|
||||
|
||||
/**
|
||||
* File format authentication values
|
||||
*/
|
||||
private static final byte BIG_ENDIAN_ = 1;
|
||||
private static final byte CHAR_SET_ = 0;
|
||||
private static final byte CHAR_SIZE_ = 2;
|
||||
|
||||
/**
|
||||
* Error messages
|
||||
*/
|
||||
private static final String MAGIC_NUMBER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Not an ICU data file";
|
||||
private static final String HEADER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Header authentication failed, please check if you have the most updated ICU data file";
|
||||
}
|
@ -5,17 +5,13 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Utility.java,v $
|
||||
* $Date: 2002/02/08 01:10:34 $
|
||||
* $Revision: 1.20 $
|
||||
* $Date: 2002/02/08 23:22:40 $
|
||||
* $Revision: 1.21 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.util;
|
||||
import com.ibm.text.*;
|
||||
import java.io.InputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class Utility {
|
||||
|
||||
@ -1510,133 +1506,4 @@ public final class Utility {
|
||||
true, escapeUnprintable, quoteBuf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>ICU data header reader method.
|
||||
* Takes a ICU generated big-endian input stream, parse the ICU standard
|
||||
* file header and authenticates them.</p>
|
||||
* <p>Header format:
|
||||
* <ul>
|
||||
* <li> Header size (char)
|
||||
* <li> Magic number 1 (byte)
|
||||
* <li> Magic number 2 (byte)
|
||||
* <li> Rest of the header size (char)
|
||||
* <li> Reserved word (char)
|
||||
* <li> Big endian indicator (byte)
|
||||
* <li> Character set family indicator (byte)
|
||||
* <li> Size of a char (byte) for c++ and c use
|
||||
* <li> Reserved byte (byte)
|
||||
* <li> Data format identifier (4 bytes), each ICU data has its own
|
||||
* identifier to distinguish them. [0] major [1] minor
|
||||
* [2] milli [3] micro
|
||||
* <li> Data version (4 bytes), the change version of the ICU data
|
||||
* [0] major [1] minor [2] milli [3] micro
|
||||
* <li> Unicode version (4 bytes) this ICU is based on.
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
* Example of use:<br>
|
||||
* <pre>
|
||||
* try {
|
||||
* FileInputStream input = new FileInputStream(filename);
|
||||
* If (Utility.readICUDataHeader(input, dataformat, dataversion,
|
||||
* unicode) {
|
||||
* System.out.println("Verified file header, this is a ICU data file");
|
||||
* }
|
||||
* } catch (IOException e) {
|
||||
* System.out.println("This is not a ICU data file");
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
* @param inputStream input stream that contains the ICU data header
|
||||
* @param dataFormatIDExpected Data format expected. An array of 4 bytes
|
||||
* information about the data format.
|
||||
* E.g. data format ID 1.2.3.4. will became an array of
|
||||
* {1, 2, 3, 4}
|
||||
* @param dataVersionExpected Data version expected. An array of 4 bytes
|
||||
* information about the data version.
|
||||
* E.g. data version 1.2.3.4. will became an array of
|
||||
* {1, 2, 3, 4}
|
||||
* @param unicodeVersionExpected Unicode version expected. An array of 4
|
||||
* bytes information about the unicode
|
||||
* version this set of data belongs to.
|
||||
* E.g. unicode version 3.1.1.0. will became an array
|
||||
* of {3, 1, 1, 0}
|
||||
* @exception IOException thrown if there is a read error or
|
||||
* when header authentication fails.
|
||||
* @draft 2.1
|
||||
*/
|
||||
public static final void readICUDataHeader(InputStream inputStream,
|
||||
byte dataFormatIDExpected[],
|
||||
byte dataVersionExpected[],
|
||||
byte unicodeVersionExpected[])
|
||||
throws IOException
|
||||
{
|
||||
DataInputStream input = new DataInputStream(inputStream);
|
||||
char headersize = input.readChar();
|
||||
headersize -= 2;
|
||||
//reading the header format
|
||||
byte magic1 = input.readByte();
|
||||
headersize --;
|
||||
byte magic2 = input.readByte();
|
||||
headersize --;
|
||||
if (magic1 != MAGIC1 || magic2 != MAGIC2) {
|
||||
throw new IOException(MAGIC_NUMBER_AUTHENTICATION_FAILED_);
|
||||
}
|
||||
|
||||
input.readChar(); // reading size
|
||||
headersize -= 2;
|
||||
input.readChar(); // reading reserved word
|
||||
headersize -= 2;
|
||||
byte bigendian = input.readByte();
|
||||
headersize --;
|
||||
byte charset = input.readByte();
|
||||
headersize --;
|
||||
byte charsize = input.readByte();
|
||||
headersize --;
|
||||
input.readByte(); // reading reserved byte
|
||||
headersize --;
|
||||
|
||||
byte dataFormatID[] = new byte[4];
|
||||
input.readFully(dataFormatID);
|
||||
headersize -= 4;
|
||||
byte dataVersion[] = new byte[4];
|
||||
input.readFully(dataVersion);
|
||||
headersize -= 4;
|
||||
byte unicodeVersion[] = new byte[4];
|
||||
input.readFully(unicodeVersion);
|
||||
headersize -= 4;
|
||||
input.skipBytes(headersize);
|
||||
|
||||
if (bigendian != BIG_ENDIAN_ || charset != CHAR_SET_ ||
|
||||
charsize != CHAR_SIZE_ ||
|
||||
!Arrays.equals(dataFormatIDExpected, dataFormatID) ||
|
||||
!Arrays.equals(dataVersionExpected, dataVersion) ||
|
||||
!Arrays.equals(unicodeVersionExpected, unicodeVersion)) {
|
||||
throw new IOException(HEADER_AUTHENTICATION_FAILED_);
|
||||
}
|
||||
}
|
||||
|
||||
// private variables -------------------------------------------------
|
||||
|
||||
/**
|
||||
* Magic numbers to authenticate the data file
|
||||
*/
|
||||
private static final byte MAGIC1 = (byte)0xda;
|
||||
private static final byte MAGIC2 = (byte)0x27;
|
||||
|
||||
/**
|
||||
* File format authentication values
|
||||
*/
|
||||
private static final byte BIG_ENDIAN_ = 1;
|
||||
private static final byte CHAR_SET_ = 0;
|
||||
private static final byte CHAR_SIZE_ = 2;
|
||||
|
||||
/**
|
||||
* Error messages
|
||||
*/
|
||||
private static final String MAGIC_NUMBER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Not an ICU data file";
|
||||
private static final String HEADER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Header authentication failed, please check if you have the most updated ICU data file";
|
||||
}
|
||||
|
150
icu4j/src/com/ibm/icu/internal/ICUBinary.java
Executable file
150
icu4j/src/com/ibm/icu/internal/ICUBinary.java
Executable file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/internal/Attic/ICUBinary.java,v $
|
||||
* $Date: 2002/02/08 23:22:40 $
|
||||
* $Revision: 1.1 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.internal;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class ICUBinary
|
||||
{
|
||||
/**
|
||||
* <p>ICU data header reader method.
|
||||
* Takes a ICU generated big-endian input stream, parse the ICU standard
|
||||
* file header and authenticates them.</p>
|
||||
* <p>Header format:
|
||||
* <ul>
|
||||
* <li> Header size (char)
|
||||
* <li> Magic number 1 (byte)
|
||||
* <li> Magic number 2 (byte)
|
||||
* <li> Rest of the header size (char)
|
||||
* <li> Reserved word (char)
|
||||
* <li> Big endian indicator (byte)
|
||||
* <li> Character set family indicator (byte)
|
||||
* <li> Size of a char (byte) for c++ and c use
|
||||
* <li> Reserved byte (byte)
|
||||
* <li> Data format identifier (4 bytes), each ICU data has its own
|
||||
* identifier to distinguish them. [0] major [1] minor
|
||||
* [2] milli [3] micro
|
||||
* <li> Data version (4 bytes), the change version of the ICU data
|
||||
* [0] major [1] minor [2] milli [3] micro
|
||||
* <li> Unicode version (4 bytes) this ICU is based on.
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
* Example of use:<br>
|
||||
* <pre>
|
||||
* try {
|
||||
* FileInputStream input = new FileInputStream(filename);
|
||||
* If (Utility.readICUDataHeader(input, dataformat, dataversion,
|
||||
* unicode) {
|
||||
* System.out.println("Verified file header, this is a ICU data file");
|
||||
* }
|
||||
* } catch (IOException e) {
|
||||
* System.out.println("This is not a ICU data file");
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
* @param inputStream input stream that contains the ICU data header
|
||||
* @param dataFormatIDExpected Data format expected. An array of 4 bytes
|
||||
* information about the data format.
|
||||
* E.g. data format ID 1.2.3.4. will became an array of
|
||||
* {1, 2, 3, 4}
|
||||
* @param dataVersionExpected Data version expected. An array of 4 bytes
|
||||
* information about the data version.
|
||||
* E.g. data version 1.2.3.4. will became an array of
|
||||
* {1, 2, 3, 4}
|
||||
* @param unicodeVersionExpected Unicode version expected. An array of 4
|
||||
* bytes information about the unicode
|
||||
* version this set of data belongs to.
|
||||
* E.g. unicode version 3.1.1.0. will became an array
|
||||
* of {3, 1, 1, 0}
|
||||
* @exception IOException thrown if there is a read error or
|
||||
* when header authentication fails.
|
||||
* @draft 2.1
|
||||
*/
|
||||
public static final void readHeader(InputStream inputStream,
|
||||
byte dataFormatIDExpected[],
|
||||
byte dataVersionExpected[],
|
||||
byte unicodeVersionExpected[])
|
||||
throws IOException
|
||||
{
|
||||
DataInputStream input = new DataInputStream(inputStream);
|
||||
char headersize = input.readChar();
|
||||
headersize -= 2;
|
||||
//reading the header format
|
||||
byte magic1 = input.readByte();
|
||||
headersize --;
|
||||
byte magic2 = input.readByte();
|
||||
headersize --;
|
||||
if (magic1 != MAGIC1 || magic2 != MAGIC2) {
|
||||
throw new IOException(MAGIC_NUMBER_AUTHENTICATION_FAILED_);
|
||||
}
|
||||
|
||||
input.readChar(); // reading size
|
||||
headersize -= 2;
|
||||
input.readChar(); // reading reserved word
|
||||
headersize -= 2;
|
||||
byte bigendian = input.readByte();
|
||||
headersize --;
|
||||
byte charset = input.readByte();
|
||||
headersize --;
|
||||
byte charsize = input.readByte();
|
||||
headersize --;
|
||||
input.readByte(); // reading reserved byte
|
||||
headersize --;
|
||||
|
||||
byte dataFormatID[] = new byte[4];
|
||||
input.readFully(dataFormatID);
|
||||
headersize -= 4;
|
||||
byte dataVersion[] = new byte[4];
|
||||
input.readFully(dataVersion);
|
||||
headersize -= 4;
|
||||
byte unicodeVersion[] = new byte[4];
|
||||
input.readFully(unicodeVersion);
|
||||
headersize -= 4;
|
||||
input.skipBytes(headersize);
|
||||
|
||||
if (bigendian != BIG_ENDIAN_ || charset != CHAR_SET_ ||
|
||||
charsize != CHAR_SIZE_ ||
|
||||
!Arrays.equals(dataFormatIDExpected, dataFormatID) ||
|
||||
!Arrays.equals(dataVersionExpected, dataVersion) ||
|
||||
!Arrays.equals(unicodeVersionExpected, unicodeVersion)) {
|
||||
throw new IOException(HEADER_AUTHENTICATION_FAILED_);
|
||||
}
|
||||
}
|
||||
|
||||
// private variables -------------------------------------------------
|
||||
|
||||
/**
|
||||
* Magic numbers to authenticate the data file
|
||||
*/
|
||||
private static final byte MAGIC1 = (byte)0xda;
|
||||
private static final byte MAGIC2 = (byte)0x27;
|
||||
|
||||
/**
|
||||
* File format authentication values
|
||||
*/
|
||||
private static final byte BIG_ENDIAN_ = 1;
|
||||
private static final byte CHAR_SET_ = 0;
|
||||
private static final byte CHAR_SIZE_ = 2;
|
||||
|
||||
/**
|
||||
* Error messages
|
||||
*/
|
||||
private static final String MAGIC_NUMBER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Not an ICU data file";
|
||||
private static final String HEADER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Header authentication failed, please check if you have the most updated ICU data file";
|
||||
}
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/lang/Attic/UCharacterNameReader.java,v $
|
||||
* $Date: 2002/02/08 01:12:11 $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2002/02/08 23:22:40 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -16,7 +16,7 @@ import java.io.InputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import com.ibm.util.Utility;
|
||||
import com.ibm.icu.internal.ICUBinary;
|
||||
|
||||
/**
|
||||
* <p>Internal reader class for ICU data file uname.dat containing
|
||||
@ -48,8 +48,8 @@ final class UCharacterNameReader
|
||||
protected UCharacterNameReader(InputStream inputStream)
|
||||
throws IOException
|
||||
{
|
||||
Utility.readICUDataHeader(inputStream, DATA_FORMAT_ID_,
|
||||
DATA_FORMAT_VERSION_, UNICODE_VERSION_);
|
||||
ICUBinary.readHeader(inputStream, DATA_FORMAT_ID_,
|
||||
DATA_FORMAT_VERSION_, UNICODE_VERSION_);
|
||||
m_dataInputStream_ = new DataInputStream(inputStream);
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/lang/Attic/UCharacterPropertyReader.java,v $
|
||||
* $Date: 2002/02/08 01:12:10 $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2002/02/08 23:22:40 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -17,7 +17,7 @@ import java.io.DataInputStream;
|
||||
import java.util.Arrays;
|
||||
import java.io.IOException;
|
||||
import com.ibm.icu.util.CharTrie;
|
||||
import com.ibm.util.Utility;
|
||||
import com.ibm.icu.internal.ICUBinary;
|
||||
|
||||
/**
|
||||
* <p>Internal reader class for ICU data file uprops.dat containing
|
||||
@ -49,8 +49,8 @@ final class UCharacterPropertyReader
|
||||
protected UCharacterPropertyReader(InputStream inputStream)
|
||||
throws IOException
|
||||
{
|
||||
Utility.readICUDataHeader(inputStream, DATA_FORMAT_ID_,
|
||||
DATA_FORMAT_VERSION_, UNICODE_VERSION_);
|
||||
ICUBinary.readHeader(inputStream, DATA_FORMAT_ID_,
|
||||
DATA_FORMAT_VERSION_, UNICODE_VERSION_);
|
||||
m_dataInputStream_ = new DataInputStream(inputStream);
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UCharacterNameReader.java,v $
|
||||
* $Date: 2002/02/08 01:12:11 $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2002/02/08 23:22:40 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -16,7 +16,7 @@ import java.io.InputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import com.ibm.util.Utility;
|
||||
import com.ibm.icu.internal.ICUBinary;
|
||||
|
||||
/**
|
||||
* <p>Internal reader class for ICU data file uname.dat containing
|
||||
@ -48,8 +48,8 @@ final class UCharacterNameReader
|
||||
protected UCharacterNameReader(InputStream inputStream)
|
||||
throws IOException
|
||||
{
|
||||
Utility.readICUDataHeader(inputStream, DATA_FORMAT_ID_,
|
||||
DATA_FORMAT_VERSION_, UNICODE_VERSION_);
|
||||
ICUBinary.readHeader(inputStream, DATA_FORMAT_ID_,
|
||||
DATA_FORMAT_VERSION_, UNICODE_VERSION_);
|
||||
m_dataInputStream_ = new DataInputStream(inputStream);
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UCharacterPropertyReader.java,v $
|
||||
* $Date: 2002/02/08 01:12:10 $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2002/02/08 23:22:40 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -17,7 +17,7 @@ import java.io.DataInputStream;
|
||||
import java.util.Arrays;
|
||||
import java.io.IOException;
|
||||
import com.ibm.icu.util.CharTrie;
|
||||
import com.ibm.util.Utility;
|
||||
import com.ibm.icu.internal.ICUBinary;
|
||||
|
||||
/**
|
||||
* <p>Internal reader class for ICU data file uprops.dat containing
|
||||
@ -49,8 +49,8 @@ final class UCharacterPropertyReader
|
||||
protected UCharacterPropertyReader(InputStream inputStream)
|
||||
throws IOException
|
||||
{
|
||||
Utility.readICUDataHeader(inputStream, DATA_FORMAT_ID_,
|
||||
DATA_FORMAT_VERSION_, UNICODE_VERSION_);
|
||||
ICUBinary.readHeader(inputStream, DATA_FORMAT_ID_,
|
||||
DATA_FORMAT_VERSION_, UNICODE_VERSION_);
|
||||
m_dataInputStream_ = new DataInputStream(inputStream);
|
||||
}
|
||||
|
||||
|
@ -5,17 +5,13 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/util/Attic/Utility.java,v $
|
||||
* $Date: 2002/02/08 01:10:34 $
|
||||
* $Revision: 1.20 $
|
||||
* $Date: 2002/02/08 23:22:40 $
|
||||
* $Revision: 1.21 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
package com.ibm.util;
|
||||
import com.ibm.text.*;
|
||||
import java.io.InputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class Utility {
|
||||
|
||||
@ -1510,133 +1506,4 @@ public final class Utility {
|
||||
true, escapeUnprintable, quoteBuf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>ICU data header reader method.
|
||||
* Takes a ICU generated big-endian input stream, parse the ICU standard
|
||||
* file header and authenticates them.</p>
|
||||
* <p>Header format:
|
||||
* <ul>
|
||||
* <li> Header size (char)
|
||||
* <li> Magic number 1 (byte)
|
||||
* <li> Magic number 2 (byte)
|
||||
* <li> Rest of the header size (char)
|
||||
* <li> Reserved word (char)
|
||||
* <li> Big endian indicator (byte)
|
||||
* <li> Character set family indicator (byte)
|
||||
* <li> Size of a char (byte) for c++ and c use
|
||||
* <li> Reserved byte (byte)
|
||||
* <li> Data format identifier (4 bytes), each ICU data has its own
|
||||
* identifier to distinguish them. [0] major [1] minor
|
||||
* [2] milli [3] micro
|
||||
* <li> Data version (4 bytes), the change version of the ICU data
|
||||
* [0] major [1] minor [2] milli [3] micro
|
||||
* <li> Unicode version (4 bytes) this ICU is based on.
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
* Example of use:<br>
|
||||
* <pre>
|
||||
* try {
|
||||
* FileInputStream input = new FileInputStream(filename);
|
||||
* If (Utility.readICUDataHeader(input, dataformat, dataversion,
|
||||
* unicode) {
|
||||
* System.out.println("Verified file header, this is a ICU data file");
|
||||
* }
|
||||
* } catch (IOException e) {
|
||||
* System.out.println("This is not a ICU data file");
|
||||
* }
|
||||
* </pre>
|
||||
* </p>
|
||||
* @param inputStream input stream that contains the ICU data header
|
||||
* @param dataFormatIDExpected Data format expected. An array of 4 bytes
|
||||
* information about the data format.
|
||||
* E.g. data format ID 1.2.3.4. will became an array of
|
||||
* {1, 2, 3, 4}
|
||||
* @param dataVersionExpected Data version expected. An array of 4 bytes
|
||||
* information about the data version.
|
||||
* E.g. data version 1.2.3.4. will became an array of
|
||||
* {1, 2, 3, 4}
|
||||
* @param unicodeVersionExpected Unicode version expected. An array of 4
|
||||
* bytes information about the unicode
|
||||
* version this set of data belongs to.
|
||||
* E.g. unicode version 3.1.1.0. will became an array
|
||||
* of {3, 1, 1, 0}
|
||||
* @exception IOException thrown if there is a read error or
|
||||
* when header authentication fails.
|
||||
* @draft 2.1
|
||||
*/
|
||||
public static final void readICUDataHeader(InputStream inputStream,
|
||||
byte dataFormatIDExpected[],
|
||||
byte dataVersionExpected[],
|
||||
byte unicodeVersionExpected[])
|
||||
throws IOException
|
||||
{
|
||||
DataInputStream input = new DataInputStream(inputStream);
|
||||
char headersize = input.readChar();
|
||||
headersize -= 2;
|
||||
//reading the header format
|
||||
byte magic1 = input.readByte();
|
||||
headersize --;
|
||||
byte magic2 = input.readByte();
|
||||
headersize --;
|
||||
if (magic1 != MAGIC1 || magic2 != MAGIC2) {
|
||||
throw new IOException(MAGIC_NUMBER_AUTHENTICATION_FAILED_);
|
||||
}
|
||||
|
||||
input.readChar(); // reading size
|
||||
headersize -= 2;
|
||||
input.readChar(); // reading reserved word
|
||||
headersize -= 2;
|
||||
byte bigendian = input.readByte();
|
||||
headersize --;
|
||||
byte charset = input.readByte();
|
||||
headersize --;
|
||||
byte charsize = input.readByte();
|
||||
headersize --;
|
||||
input.readByte(); // reading reserved byte
|
||||
headersize --;
|
||||
|
||||
byte dataFormatID[] = new byte[4];
|
||||
input.readFully(dataFormatID);
|
||||
headersize -= 4;
|
||||
byte dataVersion[] = new byte[4];
|
||||
input.readFully(dataVersion);
|
||||
headersize -= 4;
|
||||
byte unicodeVersion[] = new byte[4];
|
||||
input.readFully(unicodeVersion);
|
||||
headersize -= 4;
|
||||
input.skipBytes(headersize);
|
||||
|
||||
if (bigendian != BIG_ENDIAN_ || charset != CHAR_SET_ ||
|
||||
charsize != CHAR_SIZE_ ||
|
||||
!Arrays.equals(dataFormatIDExpected, dataFormatID) ||
|
||||
!Arrays.equals(dataVersionExpected, dataVersion) ||
|
||||
!Arrays.equals(unicodeVersionExpected, unicodeVersion)) {
|
||||
throw new IOException(HEADER_AUTHENTICATION_FAILED_);
|
||||
}
|
||||
}
|
||||
|
||||
// private variables -------------------------------------------------
|
||||
|
||||
/**
|
||||
* Magic numbers to authenticate the data file
|
||||
*/
|
||||
private static final byte MAGIC1 = (byte)0xda;
|
||||
private static final byte MAGIC2 = (byte)0x27;
|
||||
|
||||
/**
|
||||
* File format authentication values
|
||||
*/
|
||||
private static final byte BIG_ENDIAN_ = 1;
|
||||
private static final byte CHAR_SET_ = 0;
|
||||
private static final byte CHAR_SIZE_ = 2;
|
||||
|
||||
/**
|
||||
* Error messages
|
||||
*/
|
||||
private static final String MAGIC_NUMBER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Not an ICU data file";
|
||||
private static final String HEADER_AUTHENTICATION_FAILED_ =
|
||||
"ICU data file error: Header authentication failed, please check if you have the most updated ICU data file";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user