< prev index next >

src/java.base/share/classes/sun/text/normalizer/ICUBinary.java

Print this page




  48 
  49     /**
  50      * Special interface for data authentication
  51      */
  52     public static interface Authenticate
  53     {
  54         /**
  55          * Method used in ICUBinary.readHeader() to provide data format
  56          * authentication.
  57          * @param version version of the current data
  58          * @return true if dataformat is an acceptable version, false otherwise
  59          */
  60         public boolean isDataVersionAcceptable(byte version[]);
  61     }
  62 
  63     // public methods --------------------------------------------------------
  64 
  65     /**
  66     * <p>ICU data header reader method.
  67     * Takes a ICU generated big-endian input stream, parse the ICU standard
  68     * file header and authenticates them.</p>
  69     * <p>Header format:
  70     * <ul>
  71     *     <li> Header size (char)
  72     *     <li> Magic number 1 (byte)
  73     *     <li> Magic number 2 (byte)
  74     *     <li> Rest of the header size (char)
  75     *     <li> Reserved word (char)
  76     *     <li> Big endian indicator (byte)
  77     *     <li> Character set family indicator (byte)
  78     *     <li> Size of a char (byte) for c++ and c use
  79     *     <li> Reserved byte (byte)
  80     *     <li> Data format identifier (4 bytes), each ICU data has its own
  81     *          identifier to distinguish them. [0] major [1] minor
  82     *                                          [2] milli [3] micro
  83     *     <li> Data version (4 bytes), the change version of the ICU data
  84     *                             [0] major [1] minor [2] milli [3] micro
  85     *     <li> Unicode version (4 bytes) this ICU is based on.
  86     * </ul>
  87     * </p>
  88     * <p>
  89     * Example of use:<br>
  90     * <pre>
  91     * try {
  92     *    FileInputStream input = new FileInputStream(filename);
  93     *    If (Utility.readICUDataHeader(input, dataformat, dataversion,
  94     *                                  unicode) {
  95     *        System.out.println("Verified file header, this is a ICU data file");
  96     *    }
  97     * } catch (IOException e) {
  98     *    System.out.println("This is not a ICU data file");
  99     * }
 100     * </pre>
 101     * </p>
 102     * @param inputStream input stream that contains the ICU data header
 103     * @param dataFormatIDExpected Data format expected. An array of 4 bytes
 104     *                     information about the data format.
 105     *                     E.g. data format ID 1.2.3.4. will became an array of
 106     *                     {1, 2, 3, 4}
 107     * @param authenticate user defined extra data authentication. This value
 108     *                     can be null, if no extra authentication is needed.
 109     * @exception IOException thrown if there is a read error or
 110     *            when header authentication fails.
 111     * @draft 2.1
 112     */
 113     public static final byte[] readHeader(InputStream inputStream,
 114                                         byte dataFormatIDExpected[],
 115                                         Authenticate authenticate)
 116                                                           throws IOException
 117     {
 118         DataInputStream input = new DataInputStream(inputStream);
 119         char headersize = input.readChar();
 120         int readcount = 2;
 121         //reading the header format




  48 
  49     /**
  50      * Special interface for data authentication
  51      */
  52     public static interface Authenticate
  53     {
  54         /**
  55          * Method used in ICUBinary.readHeader() to provide data format
  56          * authentication.
  57          * @param version version of the current data
  58          * @return true if dataformat is an acceptable version, false otherwise
  59          */
  60         public boolean isDataVersionAcceptable(byte version[]);
  61     }
  62 
  63     // public methods --------------------------------------------------------
  64 
  65     /**
  66     * <p>ICU data header reader method.
  67     * Takes a ICU generated big-endian input stream, parse the ICU standard
  68     * file header and authenticates them.
  69     * <p>Header format:
  70     * <ul>
  71     *     <li> Header size (char)
  72     *     <li> Magic number 1 (byte)
  73     *     <li> Magic number 2 (byte)
  74     *     <li> Rest of the header size (char)
  75     *     <li> Reserved word (char)
  76     *     <li> Big endian indicator (byte)
  77     *     <li> Character set family indicator (byte)
  78     *     <li> Size of a char (byte) for c++ and c use
  79     *     <li> Reserved byte (byte)
  80     *     <li> Data format identifier (4 bytes), each ICU data has its own
  81     *          identifier to distinguish them. [0] major [1] minor
  82     *                                          [2] milli [3] micro
  83     *     <li> Data version (4 bytes), the change version of the ICU data
  84     *                             [0] major [1] minor [2] milli [3] micro
  85     *     <li> Unicode version (4 bytes) this ICU is based on.
  86     * </ul>
  87     *
  88     * <p>
  89     * Example of use:<br>
  90     * <pre>
  91     * try {
  92     *    FileInputStream input = new FileInputStream(filename);
  93     *    If (Utility.readICUDataHeader(input, dataformat, dataversion,
  94     *                                  unicode) {
  95     *        System.out.println("Verified file header, this is a ICU data file");
  96     *    }
  97     * } catch (IOException e) {
  98     *    System.out.println("This is not a ICU data file");
  99     * }
 100     * </pre>
 101     *
 102     * @param inputStream input stream that contains the ICU data header
 103     * @param dataFormatIDExpected Data format expected. An array of 4 bytes
 104     *                     information about the data format.
 105     *                     E.g. data format ID 1.2.3.4. will became an array of
 106     *                     {1, 2, 3, 4}
 107     * @param authenticate user defined extra data authentication. This value
 108     *                     can be null, if no extra authentication is needed.
 109     * @exception IOException thrown if there is a read error or
 110     *            when header authentication fails.
 111     * @draft 2.1
 112     */
 113     public static final byte[] readHeader(InputStream inputStream,
 114                                         byte dataFormatIDExpected[],
 115                                         Authenticate authenticate)
 116                                                           throws IOException
 117     {
 118         DataInputStream input = new DataInputStream(inputStream);
 119         char headersize = input.readChar();
 120         int readcount = 2;
 121         //reading the header format


< prev index next >