Class ICUBinary


  • public final class ICUBinary
    extends Object
    • Constructor Detail

      • ICUBinary

        public ICUBinary()
    • Method Detail

      • getData

        public static ByteBuffer getData​(String itemPath)
        Loads an ICU binary data file and returns it as a ByteBuffer. The buffer contents is normally read-only, but its position etc. can be modified.
        Parameters:
        itemPath - Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".
        Returns:
        The data as a read-only ByteBuffer, or null if the resource could not be found.
      • getData

        public static ByteBuffer getData​(ClassLoader loader,
                                         String resourceName,
                                         String itemPath)
        Loads an ICU binary data file and returns it as a ByteBuffer. The buffer contents is normally read-only, but its position etc. can be modified.
        Parameters:
        loader - Used for loader.getResourceAsStream() unless the data is found elsewhere.
        resourceName - Resource name for use with the loader.
        itemPath - Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".
        Returns:
        The data as a read-only ByteBuffer, or null if the resource could not be found.
      • getRequiredData

        public static ByteBuffer getRequiredData​(String itemPath)
        Loads an ICU binary data file and returns it as a ByteBuffer. The buffer contents is normally read-only, but its position etc. can be modified.
        Parameters:
        itemPath - Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".
        Returns:
        The data as a read-only ByteBuffer.
        Throws:
        MissingResourceException - if required==true and the resource could not be found
      • addBaseNamesInFileFolder

        public static void addBaseNamesInFileFolder​(String folder,
                                                    String suffix,
                                                    Set<String> names)
        Parameters:
        folder - The relative ICU data folder, like "" or "coll".
        suffix - Usually ".res".
        names - File base names relative to the folder are added without the suffix, for example "de_CH".
      • readHeader

        public static int readHeader​(ByteBuffer bytes,
                                     int dataFormat,
                                     ICUBinary.Authenticate authenticate)
                              throws IOException
        Reads an ICU data header, checks the data format, and returns the data version.

        Assumes that the ByteBuffer position is 0 on input. The buffer byte order is set according to the data. The buffer position is advanced past the header (including UDataInfo and comment).

        See C++ ucmndata.h and unicode/udata.h.

        Returns:
        dataVersion
        Throws:
        IOException - if this is not a valid ICU data item of the expected dataFormat
      • writeHeader

        public static int writeHeader​(int dataFormat,
                                      int formatVersion,
                                      int dataVersion,
                                      DataOutputStream dos)
                               throws IOException
        Writes an ICU data header. Does not write a copyright string.
        Returns:
        The length of the header (number of bytes written).
        Throws:
        IOException - from the DataOutputStream
      • skipBytes

        public static void skipBytes​(ByteBuffer bytes,
                                     int skipLength)
      • getString

        public static String getString​(ByteBuffer bytes,
                                       int length,
                                       int additionalSkipLength)
      • getChars

        public static char[] getChars​(ByteBuffer bytes,
                                      int length,
                                      int additionalSkipLength)
      • getShorts

        public static short[] getShorts​(ByteBuffer bytes,
                                        int length,
                                        int additionalSkipLength)
      • getInts

        public static int[] getInts​(ByteBuffer bytes,
                                    int length,
                                    int additionalSkipLength)
      • getLongs

        public static long[] getLongs​(ByteBuffer bytes,
                                      int length,
                                      int additionalSkipLength)
      • sliceWithOrder

        public static ByteBuffer sliceWithOrder​(ByteBuffer bytes)
        Same as ByteBuffer.slice() plus preserving the byte order.
      • getByteBufferFromInputStreamAndCloseStream

        public static ByteBuffer getByteBufferFromInputStreamAndCloseStream​(InputStream is)
                                                                     throws IOException
        Reads the entire contents from the stream into a byte array and wraps it into a ByteBuffer. Closes the InputStream at the end.
        Throws:
        IOException
      • getVersionInfoFromCompactInt

        public static VersionInfo getVersionInfoFromCompactInt​(int version)
        Returns a VersionInfo for the bytes in the compact version integer.
      • getVersionByteArrayFromCompactInt

        public static byte[] getVersionByteArrayFromCompactInt​(int version)
        Returns an array of the bytes in the compact version integer.