Package com.ibm.icu.impl
Class ICUBinary
- java.lang.Object
-
- com.ibm.icu.impl.ICUBinary
-
public final class ICUBinary extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ICUBinary.Authenticate
Special interface for data authenticationprivate static class
ICUBinary.DataFile
private static class
ICUBinary.DatPackageReader
Reads the ICU .dat package file format.private static class
ICUBinary.PackageDataFile
private static class
ICUBinary.SingleDataFile
-
Field Summary
Fields Modifier and Type Field Description private static byte
CHAR_SET_
File format authentication valuesprivate static byte
CHAR_SIZE_
private static java.lang.String
HEADER_AUTHENTICATION_FAILED_
private static java.util.List<ICUBinary.DataFile>
icuDataFiles
private static java.lang.String
MAGIC_NUMBER_AUTHENTICATION_FAILED_
Error messagesprivate static byte
MAGIC1
Magic numbers to authenticate the data fileprivate static byte
MAGIC2
-
Constructor Summary
Constructors Constructor Description ICUBinary()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addBaseNamesInFileFolder(java.lang.String folder, java.lang.String suffix, java.util.Set<java.lang.String> names)
private static void
addDataFilesFromFolder(java.io.File folder, java.lang.StringBuilder itemPath, java.util.List<ICUBinary.DataFile> dataFiles)
private static void
addDataFilesFromPath(java.lang.String dataPath, java.util.List<ICUBinary.DataFile> files)
(package private) static int
compareKeys(java.lang.CharSequence key, byte[] bytes, int offset)
(package private) static int
compareKeys(java.lang.CharSequence key, java.nio.ByteBuffer bytes, int offset)
Compares the length-specified input key with the NUL-terminated table key.static java.nio.ByteBuffer
getByteBufferFromInputStreamAndCloseStream(java.io.InputStream is)
Reads the entire contents from the stream into a byte array and wraps it into a ByteBuffer.static byte[]
getBytes(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
static char[]
getChars(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
static java.nio.ByteBuffer
getData(java.lang.ClassLoader loader, java.lang.String resourceName, java.lang.String itemPath)
Loads an ICU binary data file and returns it as a ByteBuffer.private static java.nio.ByteBuffer
getData(java.lang.ClassLoader loader, java.lang.String resourceName, java.lang.String itemPath, boolean required)
Loads an ICU binary data file and returns it as a ByteBuffer.static java.nio.ByteBuffer
getData(java.lang.String itemPath)
Loads an ICU binary data file and returns it as a ByteBuffer.private static java.nio.ByteBuffer
getDataFromFile(java.lang.String itemPath)
static int[]
getInts(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
static long[]
getLongs(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
static java.nio.ByteBuffer
getRequiredData(java.lang.String itemPath)
Loads an ICU binary data file and returns it as a ByteBuffer.static short[]
getShorts(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
static java.lang.String
getString(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
static byte[]
getVersionByteArrayFromCompactInt(int version)
Returns an array of the bytes in the compact version integer.static VersionInfo
getVersionInfoFromCompactInt(int version)
Returns a VersionInfo for the bytes in the compact version integer.private static java.nio.ByteBuffer
mapFile(java.io.File path)
static int
readHeader(java.nio.ByteBuffer bytes, int dataFormat, ICUBinary.Authenticate authenticate)
Reads an ICU data header, checks the data format, and returns the data version.static VersionInfo
readHeaderAndDataVersion(java.nio.ByteBuffer bytes, int dataFormat, ICUBinary.Authenticate authenticate)
Same as readHeader(), but returns a VersionInfo rather than a compact int.static void
skipBytes(java.nio.ByteBuffer bytes, int skipLength)
static java.nio.ByteBuffer
sliceWithOrder(java.nio.ByteBuffer bytes)
Same as ByteBuffer.slice() plus preserving the byte order.static int
writeHeader(int dataFormat, int formatVersion, int dataVersion, java.io.DataOutputStream dos)
Writes an ICU data header.
-
-
-
Field Detail
-
icuDataFiles
private static final java.util.List<ICUBinary.DataFile> icuDataFiles
-
MAGIC1
private static final byte MAGIC1
Magic numbers to authenticate the data file- See Also:
- Constant Field Values
-
MAGIC2
private static final byte MAGIC2
- See Also:
- Constant Field Values
-
CHAR_SET_
private static final byte CHAR_SET_
File format authentication values- See Also:
- Constant Field Values
-
CHAR_SIZE_
private static final byte CHAR_SIZE_
- See Also:
- Constant Field Values
-
MAGIC_NUMBER_AUTHENTICATION_FAILED_
private static final java.lang.String MAGIC_NUMBER_AUTHENTICATION_FAILED_
Error messages- See Also:
- Constant Field Values
-
HEADER_AUTHENTICATION_FAILED_
private static final java.lang.String HEADER_AUTHENTICATION_FAILED_
- See Also:
- Constant Field Values
-
-
Method Detail
-
addDataFilesFromPath
private static void addDataFilesFromPath(java.lang.String dataPath, java.util.List<ICUBinary.DataFile> files)
-
addDataFilesFromFolder
private static void addDataFilesFromFolder(java.io.File folder, java.lang.StringBuilder itemPath, java.util.List<ICUBinary.DataFile> dataFiles)
-
compareKeys
static int compareKeys(java.lang.CharSequence key, java.nio.ByteBuffer bytes, int offset)
Compares the length-specified input key with the NUL-terminated table key. (ASCII)
-
compareKeys
static int compareKeys(java.lang.CharSequence key, byte[] bytes, int offset)
-
getData
public static java.nio.ByteBuffer getData(java.lang.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 java.nio.ByteBuffer getData(java.lang.ClassLoader loader, java.lang.String resourceName, java.lang.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 java.nio.ByteBuffer getRequiredData(java.lang.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:
java.util.MissingResourceException
- if required==true and the resource could not be found
-
getData
private static java.nio.ByteBuffer getData(java.lang.ClassLoader loader, java.lang.String resourceName, java.lang.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:
java.util.MissingResourceException
- if required==true and the resource could not be found
-
getDataFromFile
private static java.nio.ByteBuffer getDataFromFile(java.lang.String itemPath)
-
mapFile
private static java.nio.ByteBuffer mapFile(java.io.File path)
-
addBaseNamesInFileFolder
public static void addBaseNamesInFileFolder(java.lang.String folder, java.lang.String suffix, java.util.Set<java.lang.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".
-
readHeaderAndDataVersion
public static VersionInfo readHeaderAndDataVersion(java.nio.ByteBuffer bytes, int dataFormat, ICUBinary.Authenticate authenticate) throws java.io.IOException
Same as readHeader(), but returns a VersionInfo rather than a compact int.- Throws:
java.io.IOException
-
readHeader
public static int readHeader(java.nio.ByteBuffer bytes, int dataFormat, ICUBinary.Authenticate authenticate) throws java.io.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:
java.io.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, java.io.DataOutputStream dos) throws java.io.IOException
Writes an ICU data header. Does not write a copyright string.- Returns:
- The length of the header (number of bytes written).
- Throws:
java.io.IOException
- from the DataOutputStream
-
skipBytes
public static void skipBytes(java.nio.ByteBuffer bytes, int skipLength)
-
getBytes
public static byte[] getBytes(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
-
getString
public static java.lang.String getString(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
-
getChars
public static char[] getChars(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
-
getShorts
public static short[] getShorts(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
-
getInts
public static int[] getInts(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
-
getLongs
public static long[] getLongs(java.nio.ByteBuffer bytes, int length, int additionalSkipLength)
-
sliceWithOrder
public static java.nio.ByteBuffer sliceWithOrder(java.nio.ByteBuffer bytes)
Same as ByteBuffer.slice() plus preserving the byte order.
-
getByteBufferFromInputStreamAndCloseStream
public static java.nio.ByteBuffer getByteBufferFromInputStreamAndCloseStream(java.io.InputStream is) throws java.io.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:
java.io.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.
-
-