Package com.ibm.icu.impl
Class ICUBinary
java.lang.Object
com.ibm.icu.impl.ICUBinary
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceSpecial interface for data authenticationprivate static classprivate static final classReads the ICU .dat package file format.private static final classprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byteFile format authentication valuesprivate static final byteprivate static final Stringprivate static final List<ICUBinary.DataFile> private static final StringError messagesprivate static final byteMagic numbers to authenticate the data fileprivate static final byte -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddBaseNamesInFileFolder(String folder, String suffix, Set<String> names) private static voidaddDataFilesFromFolder(File folder, StringBuilder itemPath, List<ICUBinary.DataFile> dataFiles) private static voidaddDataFilesFromPath(String dataPath, List<ICUBinary.DataFile> files) (package private) static intcompareKeys(CharSequence key, byte[] bytes, int offset) (package private) static intcompareKeys(CharSequence key, ByteBuffer bytes, int offset) Compares the length-specified input key with the NUL-terminated table key.static ByteBufferReads the entire contents from the stream into a byte array and wraps it into a ByteBuffer.static byte[]getBytes(ByteBuffer bytes, int length, int additionalSkipLength) static char[]getChars(ByteBuffer bytes, int length, int additionalSkipLength) static ByteBuffergetData(ClassLoader loader, String resourceName, String itemPath) Loads an ICU binary data file and returns it as a ByteBuffer.private static ByteBuffergetData(ClassLoader loader, String resourceName, String itemPath, boolean required) Loads an ICU binary data file and returns it as a ByteBuffer.static ByteBufferLoads an ICU binary data file and returns it as a ByteBuffer.private static ByteBuffergetDataFromFile(String itemPath) static int[]getInts(ByteBuffer bytes, int length, int additionalSkipLength) static long[]getLongs(ByteBuffer bytes, int length, int additionalSkipLength) static ByteBuffergetRequiredData(String itemPath) Loads an ICU binary data file and returns it as a ByteBuffer.static short[]getShorts(ByteBuffer bytes, int length, int additionalSkipLength) static StringgetString(ByteBuffer bytes, int length, int additionalSkipLength) static byte[]getVersionByteArrayFromCompactInt(int version) Returns an array of the bytes in the compact version integer.static VersionInfogetVersionInfoFromCompactInt(int version) Returns a VersionInfo for the bytes in the compact version integer.private static ByteBufferstatic intreadHeader(ByteBuffer bytes, int dataFormat, ICUBinary.Authenticate authenticate) Reads an ICU data header, checks the data format, and returns the data version.static VersionInforeadHeaderAndDataVersion(ByteBuffer bytes, int dataFormat, ICUBinary.Authenticate authenticate) Same as readHeader(), but returns a VersionInfo rather than a compact int.static voidskipBytes(ByteBuffer bytes, int skipLength) static ByteBuffersliceWithOrder(ByteBuffer bytes) Same as ByteBuffer.slice() plus preserving the byte order.static intwriteHeader(int dataFormat, int formatVersion, int dataVersion, DataOutputStream dos) Writes an ICU data header.
-
Field Details
-
icuDataFiles
-
MAGIC1
private static final byte MAGIC1Magic numbers to authenticate the data file- See Also:
-
MAGIC2
private static final byte MAGIC2- See Also:
-
CHAR_SET_
private static final byte CHAR_SET_File format authentication values- See Also:
-
CHAR_SIZE_
private static final byte CHAR_SIZE_- See Also:
-
MAGIC_NUMBER_AUTHENTICATION_FAILED_
Error messages- See Also:
-
HEADER_AUTHENTICATION_FAILED_
- See Also:
-
-
Constructor Details
-
ICUBinary
public ICUBinary()
-
-
Method Details
-
addDataFilesFromPath
-
addDataFilesFromFolder
private static void addDataFilesFromFolder(File folder, StringBuilder itemPath, List<ICUBinary.DataFile> dataFiles) -
compareKeys
Compares the length-specified input key with the NUL-terminated table key. (ASCII) -
compareKeys
-
getData
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
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
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
-
getData
private static ByteBuffer getData(ClassLoader loader, String resourceName, String itemPath, boolean required) 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".required- If the resource cannot be found, this method returns null (!required) or throws an exception (required).- Returns:
- The data as a read-only ByteBuffer, or null if required==false and the resource could not be found.
- Throws:
MissingResourceException- if required==true and the resource could not be found
-
getDataFromFile
-
mapFile
-
addBaseNamesInFileFolder
- 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".
-
readHeaderAndDataVersion
public static VersionInfo readHeaderAndDataVersion(ByteBuffer bytes, int dataFormat, ICUBinary.Authenticate authenticate) throws IOException Same as readHeader(), but returns a VersionInfo rather than a compact int.- Throws:
IOException
-
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
-
getBytes
-
getString
-
getChars
-
getShorts
-
getInts
-
getLongs
-
sliceWithOrder
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
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.
-