Top Inners Fields Constructors Methods
com.ibm.icu.impl

public final Class ICUBinary

extends Object
Class Inheritance
Imports
java.io.DataOutputStream, .File, .FileInputStream, .FileNotFoundException, .IOException, .InputStream, java.nio.ByteBuffer, .ByteOrder, java.nio.channels.FileChannel, java.util.ArrayList, .Arrays, .List, .MissingResourceException, .Set, com.ibm.icu.util.ICUUncheckedIOException, .VersionInfo

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ICUBinary.Authenticate

Special interface for data authentication

private abstract static class
private static class
ICUBinary.DatPackageReader

Reads the ICU .dat package file format.

private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final byte
CHAR_SET_

File format authentication values

private static final byte
private static final String
private static final List<ICUBinary.DataFile>
private static final byte
MAGIC1

Magic numbers to authenticate the data file

private static final byte
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
addBaseNamesInFileFolder(String
The relative ICU data folder, like "" or "coll".
folder
,
String
Usually ".res".
suffix
,
Set<String>
File base names relative to the folder are added without the suffix, for example "de_CH".
names
)

private static void
private static void
pack-priv static int
compareKeys(CharSequence key, ByteBuffer bytes, int offset)

Compares the length-specified input key with the NUL-terminated table key.

pack-priv static int
compareKeys(CharSequence key, byte[] bytes, int offset)

public static ByteBuffer
getByteBufferFromInputStreamAndCloseStream(InputStream is)

Reads the entire contents from the stream into a byte array and wraps it into a ByteBuffer.

public static byte[]
getBytes(ByteBuffer bytes, int length, int additionalSkipLength)

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

public static ByteBuffer

Returns:

The data as a read-only ByteBuffer, or null if the resource could not be found.
getData
(String
Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".
itemPath
)

Loads an ICU binary data file and returns it as a ByteBuffer.

public static ByteBuffer

Returns:

The data as a read-only ByteBuffer, or null if the resource could not be found.
getData
(ClassLoader
Used for loader.getResourceAsStream() unless the data is found elsewhere.
loader
,
String
Resource name for use with the loader.
resourceName
,
String
Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".
itemPath
)

Loads an ICU binary data file and returns it as a ByteBuffer.

private static ByteBuffer

Returns:

The data as a read-only ByteBuffer, or null if required==false and the resource could not be found.
getData
(ClassLoader
Used for loader.getResourceAsStream() unless the data is found elsewhere.
loader
,
String
Resource name for use with the loader.
resourceName
,
String
Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".
itemPath
,
boolean
If the resource cannot be found, this method returns null (!required) or throws an exception (required).
required
)

Loads an ICU binary data file and returns it as a ByteBuffer.

private static ByteBuffer
public static int[]
getInts(ByteBuffer bytes, int length, int additionalSkipLength)

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

public static ByteBuffer

Returns:

The data as a read-only ByteBuffer.
getRequiredData
(String
Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".
itemPath
)

Loads an ICU binary data file and returns it as a ByteBuffer.

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

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

public static byte[]
getVersionByteArrayFromCompactInt(int version)

Returns an array of the bytes in the compact version integer.

public static VersionInfo
getVersionInfoFromCompactInt(int version)

Returns a VersionInfo for the bytes in the compact version integer.

private static ByteBuffer
mapFile(File path)

public static int

Returns:

dataVersion
readHeader
(ByteBuffer bytes, int dataFormat, ICUBinary.Authenticate authenticate)

Reads an ICU data header, checks the data format, and returns the data version.

public static VersionInfo
readHeaderAndDataVersion(ByteBuffer bytes, int dataFormat, ICUBinary.Authenticate authenticate)

Same as readHeader(), but returns a VersionInfo rather than a compact int.

public static void
skipBytes(ByteBuffer bytes, int skipLength)

public static ByteBuffer
sliceWithOrder(ByteBuffer bytes)

Same as ByteBuffer.slice() plus preserving the byte order.

public static int

Returns:

The length of the header (number of bytes written).
writeHeader
(int dataFormat, int formatVersion, int dataVersion, DataOutputStream dos)

Writes an ICU data header.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHAR_SET_back to summary
private static final byte CHAR_SET_

File format authentication values

CHAR_SIZE_back to summary
private static final byte CHAR_SIZE_
HEADER_AUTHENTICATION_FAILED_back to summary
private static final String HEADER_AUTHENTICATION_FAILED_
icuDataFilesback to summary
private static final List<ICUBinary.DataFile> icuDataFiles
MAGIC1back to summary
private static final byte MAGIC1

Magic numbers to authenticate the data file

MAGIC2back to summary
private static final byte MAGIC2
MAGIC_NUMBER_AUTHENTICATION_FAILED_back to summary
private static final String MAGIC_NUMBER_AUTHENTICATION_FAILED_

Error messages

Constructor Detail

ICUBinaryback to summary
public ICUBinary()

Method Detail

addBaseNamesInFileFolderback to summary
public static void addBaseNamesInFileFolder(String folder, String suffix, Set<String> names)
Parameters
folder:String

The relative ICU data folder, like "" or "coll".

suffix:String

Usually ".res".

names:Set<String>

File base names relative to the folder are added without the suffix, for example "de_CH".

addDataFilesFromFolderback to summary
private static void addDataFilesFromFolder(File folder, StringBuilder itemPath, List<ICUBinary.DataFile> dataFiles)
addDataFilesFromPathback to summary
private static void addDataFilesFromPath(String dataPath, List<ICUBinary.DataFile> files)
compareKeysback to summary
pack-priv static int compareKeys(CharSequence key, ByteBuffer bytes, int offset)

Compares the length-specified input key with the NUL-terminated table key. (ASCII)

compareKeysback to summary
pack-priv static int compareKeys(CharSequence key, byte[] bytes, int offset)
getByteBufferFromInputStreamAndCloseStreamback to summary
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.

getBytesback to summary
public static byte[] getBytes(ByteBuffer bytes, int length, int additionalSkipLength)
getCharsback to summary
public static char[] getChars(ByteBuffer bytes, int length, int additionalSkipLength)
getDataback to summary
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:String

Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".

Returns:ByteBuffer

The data as a read-only ByteBuffer, or null if the resource could not be found.

getDataback to summary
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:ClassLoader

Used for loader.getResourceAsStream() unless the data is found elsewhere.

resourceName:String

Resource name for use with the loader.

itemPath:String

Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".

Returns:ByteBuffer

The data as a read-only ByteBuffer, or null if the resource could not be found.

getDataback to summary
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:ClassLoader

Used for loader.getResourceAsStream() unless the data is found elsewhere.

resourceName:String

Resource name for use with the loader.

itemPath:String

Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".

required:boolean

If the resource cannot be found, this method returns null (!required) or throws an exception (required).

Returns:ByteBuffer

The data as a read-only ByteBuffer, or null if required==false and the resource could not be found.

Exceptions
MissingResourceException:
if required==true and the resource could not be found
getDataFromFileback to summary
private static ByteBuffer getDataFromFile(String itemPath)
getIntsback to summary
public static int[] getInts(ByteBuffer bytes, int length, int additionalSkipLength)
getLongsback to summary
public static long[] getLongs(ByteBuffer bytes, int length, int additionalSkipLength)
getRequiredDataback to summary
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:String

Relative ICU data item path, for example "root.res" or "coll/ucadata.icu".

Returns:ByteBuffer

The data as a read-only ByteBuffer.

Exceptions
MissingResourceException:
if required==true and the resource could not be found
getShortsback to summary
public static short[] getShorts(ByteBuffer bytes, int length, int additionalSkipLength)
getStringback to summary
public static String getString(ByteBuffer bytes, int length, int additionalSkipLength)
getVersionByteArrayFromCompactIntback to summary
public static byte[] getVersionByteArrayFromCompactInt(int version)

Returns an array of the bytes in the compact version integer.

getVersionInfoFromCompactIntback to summary
public static VersionInfo getVersionInfoFromCompactInt(int version)

Returns a VersionInfo for the bytes in the compact version integer.

mapFileback to summary
private static ByteBuffer mapFile(File path)
Annotations
@SuppressWarnings:resource
readHeaderback to summary
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:int

dataVersion

Exceptions
IOException:
if this is not a valid ICU data item of the expected dataFormat
readHeaderAndDataVersionback to summary
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.

skipBytesback to summary
public static void skipBytes(ByteBuffer bytes, int skipLength)
sliceWithOrderback to summary
public static ByteBuffer sliceWithOrder(ByteBuffer bytes)

Same as ByteBuffer.slice() plus preserving the byte order.

writeHeaderback to summary
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:int

The length of the header (number of bytes written).

Exceptions
IOException:
from the DataOutputStream
com.ibm.icu.impl back to summary

public Interface ICUBinary.Authenticate

Known Direct Implementers
com.ibm.icu.impl.ICUResourceBundleReader.IsAcceptable, com.ibm.icu.impl.UBiDiProps.IsAcceptable, com.ibm.icu.impl.UCaseProps.IsAcceptable, com.ibm.icu.impl.UCharacterNameReader, com.ibm.icu.impl.UCharacterProperty.LayoutProps.IsAcceptable, com.ibm.icu.impl.UCharacterProperty.IsAcceptable, com.ibm.icu.impl.UPropertyAliases.IsAcceptable, com.ibm.icu.impl.StringPrepDataReader, com.ibm.icu.impl.coll.CollationDataReader.IsAcceptable, com.ibm.icu.text.SpoofChecker.SpoofData.IsAcceptable, com.ibm.icu.impl.EmojiProps.IsAcceptable, com.ibm.icu.impl.Normalizer2Impl.IsAcceptable, com.ibm.icu.impl.RBBIDataWrapper.IsAcceptable, com.ibm.icu.impl.ICUBinary.DatPackageReader.IsAcceptable

Special interface for data authentication

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if dataformat is an acceptable version, false otherwise
isDataVersionAcceptable
(byte[]
version of the current data
version
)

Method used in ICUBinary.readHeader() to provide data format authentication.

Method Detail

isDataVersionAcceptableback to summary
public boolean isDataVersionAcceptable(byte[] version)

Method used in ICUBinary.readHeader() to provide data format authentication.

Parameters
version:byte[]

version of the current data

Returns:boolean

true if dataformat is an acceptable version, false otherwise

com.ibm.icu.impl back to summary

private abstract Class ICUBinary.DataFile

extends Object
Class Inheritance
Known Direct Subclasses
com.ibm.icu.impl.ICUBinary.SingleDataFile, com.ibm.icu.impl.ICUBinary.PackageDataFile

Field Summary

Modifier and TypeField and Description
protected final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract void
addBaseNamesInFolder(String
The relative ICU data folder, like "" or "coll".
folder
,
String
Usually ".res".
suffix
,
Set<String>
File base names relative to the folder are added without the suffix, for example "de_CH".
names
)

pack-priv abstract ByteBuffer
getData(String requestedPath)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

itemPathback to summary
protected final String itemPath

Constructor Detail

DataFileback to summary
pack-priv DataFile(String item)

Method Detail

addBaseNamesInFolderback to summary
pack-priv abstract void addBaseNamesInFolder(String folder, String suffix, Set<String> names)
Parameters
folder:String

The relative ICU data folder, like "" or "coll".

suffix:String

Usually ".res".

names:Set<String>

File base names relative to the folder are added without the suffix, for example "de_CH".

getDataback to summary
pack-priv abstract ByteBuffer getData(String requestedPath)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.ibm.icu.impl back to summary

private final Class ICUBinary.DatPackageReader

extends Object
Class Inheritance

Reads the ICU .dat package file format. Most methods do not modify the ByteBuffer in any way, not even its position or other state.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final int
DATA_FORMAT

.dat package data format ID "CmnD".

private static final ICUBinary.DatPackageReader.IsAcceptable

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static boolean
addBaseName(ByteBuffer bytes, int index, String folder, String suffix, StringBuilder sb, Set<String> names)

pack-priv static void
addBaseNamesInFolder(ByteBuffer bytes, String folder, String suffix, Set<String> names)

private static int
pack-priv static ByteBuffer
private static int
getDataOffset(ByteBuffer bytes, int index)

private static int
getNameOffset(ByteBuffer bytes, int index)

private static boolean
pack-priv static boolean
validate(ByteBuffer bytes)

Checks that the ByteBuffer contains a valid, usable ICU .dat package.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DATA_FORMATback to summary
private static final int DATA_FORMAT

.dat package data format ID "CmnD".

IS_ACCEPTABLEback to summary
private static final ICUBinary.DatPackageReader.IsAcceptable IS_ACCEPTABLE

Constructor Detail

DatPackageReaderback to summary
private DatPackageReader()

Method Detail

addBaseNameback to summary
pack-priv static boolean addBaseName(ByteBuffer bytes, int index, String folder, String suffix, StringBuilder sb, Set<String> names)
addBaseNamesInFolderback to summary
pack-priv static void addBaseNamesInFolder(ByteBuffer bytes, String folder, String suffix, Set<String> names)
binarySearchback to summary
private static int binarySearch(ByteBuffer bytes, CharSequence key)
getDataback to summary
pack-priv static ByteBuffer getData(ByteBuffer bytes, CharSequence key)
getDataOffsetback to summary
private static int getDataOffset(ByteBuffer bytes, int index)
getNameOffsetback to summary
private static int getNameOffset(ByteBuffer bytes, int index)
startsWithPackageNameback to summary
private static boolean startsWithPackageName(ByteBuffer bytes, int start)
validateback to summary
pack-priv static boolean validate(ByteBuffer bytes)

Checks that the ByteBuffer contains a valid, usable ICU .dat package. Moves the buffer position from 0 to after the data header.

com.ibm.icu.impl back to summary

private final Class ICUBinary.DatPackageReader.IsAcceptable

extends Object
implements Authenticate
Class Inheritance
All Implemented Interfaces
com.ibm.icu.impl.ICUBinary.Authenticate

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
isDataVersionAcceptable(byte[]
version of the current data
version
)

Implements com.ibm.icu.impl.ICUBinary.Authenticate.isDataVersionAcceptable.

Method used in ICUBinary.readHeader() to provide data format authentication.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

IsAcceptableback to summary
private IsAcceptable()

Method Detail

isDataVersionAcceptableback to summary
public boolean isDataVersionAcceptable(byte[] version)

Implements com.ibm.icu.impl.ICUBinary.Authenticate.isDataVersionAcceptable.

Doc from com.ibm.icu.impl.ICUBinary.Authenticate.isDataVersionAcceptable.

Method used in ICUBinary.readHeader() to provide data format authentication.

Parameters
version:byte[]

version of the current data

Returns:boolean

true if dataformat is an acceptable version, false otherwise

Annotations
@Override
com.ibm.icu.impl back to summary

private final Class ICUBinary.PackageDataFile

extends DataFile
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ByteBuffer
pkgBytes

.dat package bytes, or null if not a .dat package.

Inherited from com.ibm.icu.impl.ICUBinary.DataFile:
itemPath

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addBaseNamesInFolder(String
The relative ICU data folder, like "" or "coll".
folder
,
String
Usually ".res".
suffix
,
Set<String>
File base names relative to the folder are added without the suffix, for example "de_CH".
names
)

Implements abstract com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

pack-priv ByteBuffer
getData(String requestedPath)

Implements abstract com.ibm.icu.impl.ICUBinary.DataFile.getData.

Inherited from com.ibm.icu.impl.ICUBinary.DataFile:
toString

Field Detail

pkgBytesback to summary
private final ByteBuffer pkgBytes

.dat package bytes, or null if not a .dat package. position() is after the header. Do not modify the position or other state, for thread safety.

Constructor Detail

PackageDataFileback to summary
pack-priv PackageDataFile(String item, ByteBuffer bytes)

Method Detail

addBaseNamesInFolderback to summary
pack-priv void addBaseNamesInFolder(String folder, String suffix, Set<String> names)

Implements abstract com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

Parameters
folder:String

Doc from com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

The relative ICU data folder, like "" or "coll".

suffix:String

Doc from com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

Usually ".res".

names:Set<String>

Doc from com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

File base names relative to the folder are added without the suffix, for example "de_CH".

Annotations
@Override
getDataback to summary
pack-priv ByteBuffer getData(String requestedPath)

Implements abstract com.ibm.icu.impl.ICUBinary.DataFile.getData.

Annotations
@Override
com.ibm.icu.impl back to summary

private final Class ICUBinary.SingleDataFile

extends DataFile
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final File
Inherited from com.ibm.icu.impl.ICUBinary.DataFile:
itemPath

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addBaseNamesInFolder(String
The relative ICU data folder, like "" or "coll".
folder
,
String
Usually ".res".
suffix
,
Set<String>
File base names relative to the folder are added without the suffix, for example "de_CH".
names
)

Implements abstract com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

pack-priv ByteBuffer
getData(String requestedPath)

Implements abstract com.ibm.icu.impl.ICUBinary.DataFile.getData.

public String
toString()

Overrides com.ibm.icu.impl.ICUBinary.DataFile.toString.

Returns a string representation of the object.

Field Detail

pathback to summary
private final File path

Constructor Detail

SingleDataFileback to summary
pack-priv SingleDataFile(String item, File path)

Method Detail

addBaseNamesInFolderback to summary
pack-priv void addBaseNamesInFolder(String folder, String suffix, Set<String> names)

Implements abstract com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

Parameters
folder:String

Doc from com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

The relative ICU data folder, like "" or "coll".

suffix:String

Doc from com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

Usually ".res".

names:Set<String>

Doc from com.ibm.icu.impl.ICUBinary.DataFile.addBaseNamesInFolder.

File base names relative to the folder are added without the suffix, for example "de_CH".

Annotations
@Override
getDataback to summary
pack-priv ByteBuffer getData(String requestedPath)

Implements abstract com.ibm.icu.impl.ICUBinary.DataFile.getData.

Annotations
@Override
toStringback to summary
public String toString()

Overrides com.ibm.icu.impl.ICUBinary.DataFile.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override