public class BinaryUtils extends Object
Modifier and Type | Field and Description |
---|---|
static Map<Class,BinaryWriteReplacer> |
CLS_TO_WRITE_REPLACER
Map from class to associated write replacer.
|
static int |
FIELD_ID_LEN
Field ID length.
|
static boolean |
FIELDS_SORTED_ORDER
Whether to sort field in binary objects (doesn't affect Binarylizable).
|
static short |
FLAG_COMPACT_FOOTER
Flag: compact footer, no field IDs.
|
static short |
FLAG_CUSTOM_DOTNET_TYPE
Flag: raw data contains .NET type information.
|
static short |
FLAG_HAS_RAW
Flag indicating that object has raw data.
|
static short |
FLAG_HAS_SCHEMA
Flag: only raw data exists.
|
static short |
FLAG_OFFSET_ONE_BYTE
Flag: offsets take 1 byte.
|
static short |
FLAG_OFFSET_TWO_BYTES
Flag: offsets take 2 bytes.
|
static Map<Byte,Class<?>> |
FLAG_TO_CLASS |
static short |
FLAG_USR_TYP
Flag: user type.
|
static int |
OFFSET_1
Offset which fits into 1 byte.
|
static int |
OFFSET_2
Offset which fits into 2 bytes.
|
static int |
OFFSET_4
Offset which fits into 4 bytes.
|
static Map<Class<?>,Byte> |
PLAIN_CLASS_TO_FLAG |
static Class<? extends Collection> |
SINGLETON_LIST_CLS
Class for SingletonList obtained at runtime.
|
static boolean |
USE_STR_SERIALIZATION_VER_2 |
static boolean |
WRAP_TREES
Whether to skip TreeMap/TreeSet wrapping.
|
Constructor and Description |
---|
BinaryUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
checkProtocolVersion(byte protoVer)
Check protocol version.
|
static BinaryEnumObjectImpl |
doReadBinaryEnum(BinaryInputStream in,
BinaryContext ctx)
Read binary enum.
|
static BinaryObject |
doReadBinaryObject(BinaryInputStream in,
BinaryContext ctx,
boolean detach) |
static boolean[] |
doReadBooleanArray(BinaryInputStream in) |
static byte[] |
doReadByteArray(BinaryInputStream in) |
static char[] |
doReadCharArray(BinaryInputStream in) |
static Class |
doReadClass(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr) |
static Class |
doReadClass(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
boolean deserialize) |
static Class |
doReadClass(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
int typeId) |
static String |
doReadClassName(BinaryInputStream in) |
static Collection<?> |
doReadCollection(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
BinaryReaderHandlesHolder handles,
boolean detach,
boolean deserialize,
BinaryCollectionFactory factory) |
static Date |
doReadDate(BinaryInputStream in) |
static Date[] |
doReadDateArray(BinaryInputStream in) |
static BigDecimal |
doReadDecimal(BinaryInputStream in) |
static BigDecimal[] |
doReadDecimalArray(BinaryInputStream in) |
static double[] |
doReadDoubleArray(BinaryInputStream in) |
static Enum<?> |
doReadEnum(BinaryInputStream in,
Class<?> cls,
boolean useCache)
Having target class in place we simply read ordinal and create final representation.
|
static Object[] |
doReadEnumArray(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
Class<?> cls) |
static float[] |
doReadFloatArray(BinaryInputStream in) |
static int[] |
doReadIntArray(BinaryInputStream in) |
static long[] |
doReadLongArray(BinaryInputStream in) |
static Map<?,?> |
doReadMap(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
BinaryReaderHandlesHolder handles,
boolean detach,
boolean deserialize,
BinaryMapFactory factory) |
static @Nullable Object |
doReadObject(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
BinaryReaderHandlesHolder handles) |
static Object[] |
doReadObjectArray(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
BinaryReaderHandlesHolder handles,
boolean detach,
boolean deserialize) |
static Object |
doReadOptimized(BinaryInputStream in,
BinaryContext ctx,
@Nullable ClassLoader clsLdr)
Read object serialized using optimized marshaller.
|
static Object |
doReadProxy(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
BinaryReaderHandlesHolder handles) |
static short[] |
doReadShortArray(BinaryInputStream in) |
static String |
doReadString(BinaryInputStream in) |
static String[] |
doReadStringArray(BinaryInputStream in) |
static Time |
doReadTime(BinaryInputStream in) |
static Time[] |
doReadTimeArray(BinaryInputStream in) |
static Timestamp |
doReadTimestamp(BinaryInputStream in) |
static Timestamp[] |
doReadTimestampArray(BinaryInputStream in) |
static UUID |
doReadUuid(BinaryInputStream in) |
static UUID[] |
doReadUuidArray(BinaryInputStream in) |
static int |
fieldIdLength(short flags)
Get field ID length.
|
static int |
fieldOffsetLength(short flags)
Get offset length for the given flags.
|
static int |
fieldOffsetRelative(BinaryPositionReadable stream,
int pos,
int fieldOffsetSize)
Get relative field offset.
|
static String |
fieldTypeName(int typeId) |
static IgniteBiTuple<Integer,Integer> |
footerAbsolute(BinaryPositionReadable in,
int start)
Get object's footer.
|
static int |
footerStartAbsolute(BinaryPositionReadable in,
int start)
Get object's footer.
|
static int |
footerStartRelative(BinaryPositionReadable in,
int start)
Get footer start of the object.
|
static boolean |
hasRaw(short flags)
Check if raw-only flag is set.
|
static boolean |
hasSchema(short flags)
Check if raw-only flag is set.
|
static boolean |
isBinarylizable(Class cls)
Check if class is binarylizable.
|
static boolean |
isBinaryType(Class<?> cls)
Tells whether provided type is binary.
|
static boolean |
isCompactFooter(short flags)
Check if "no-field-ids" flag is set.
|
static boolean |
isCustomJavaSerialization(Class cls)
Determines whether class contains custom Java serialization logic.
|
static boolean |
isFlagSet(short flags,
short flag)
Check whether particular flag is set.
|
static boolean |
isPlainArrayType(int type)
Checks whether an array type values can or can not contain references to other object.
|
static boolean |
isPlainType(int type) |
static boolean |
isSpecialCollection(Class cls)
Check if class represents a collection which must be treated specially.
|
static boolean |
isSpecialMap(Class cls)
Check if class represents a map which must be treated specially.
|
static boolean |
isUserType(short flags)
Check if user type flag is set.
|
static boolean |
knownArray(Object arr) |
static boolean |
knownCacheObject(Object obj) |
static boolean |
knownCollection(Object col) |
static boolean |
knownMap(Object map) |
static int |
length(BinaryPositionReadable in,
int start)
Get binary object length.
|
static Map<String,Integer> |
mergeEnumValues(String typeName,
@Nullable Map<String,Integer> oldValues,
Map<String,Integer> newValues)
Merges enum value mappings and checks for conflicts.
|
static BinaryMetadata |
mergeMetadata(@Nullable BinaryMetadata oldMeta,
BinaryMetadata newMeta)
Merge old and new metas.
|
static BinaryMetadata |
mergeMetadata(@Nullable BinaryMetadata oldMeta,
BinaryMetadata newMeta,
@Nullable Set<Integer> changedSchemas)
Merge old and new metas.
|
static BinaryWriteMode |
mode(Class<?> cls) |
static <V> Collection<V> |
newKnownCollection(Object col)
Attempts to create a new collection of the same known type.
|
static <K,V> Map<K,V> |
newKnownMap(Object map)
Attempts to create a new map of the same known type.
|
static <K,V> Map<K,V> |
newMap(Map<K,V> map)
Attempts to create a new map of the same type as
map has. |
static <V> Set<V> |
newSet(Set<V> set)
Attempts to create a new set of the same type as
set has. |
static int |
positionForHandle(BinaryInputStream in)
Get position to be used for handle.
|
static String |
qualifiedFieldName(Class cls,
String fieldName)
Create qualified field name.
|
static int |
rawOffsetAbsolute(BinaryPositionReadable in,
int start)
Get absolute raw offset of the object.
|
static int |
rawOffsetRelative(BinaryPositionReadable in,
int start)
Get relative raw offset of the object.
|
static @Nullable IgniteUuid |
readIgniteUuid(BinaryRawReader in)
Read
IgniteUuid instance. |
static Class |
resolveClass(BinaryContext ctx,
int typeId,
@Nullable String clsName,
@Nullable ClassLoader ldr,
boolean registerMeta)
Resolve the class.
|
static int |
schemaInitialId()
Schema initial ID.
|
static byte[] |
strToUtf8Bytes(String val)
Converts the string into UTF-8 byte array considering special symbols like the surrogates.
|
static BinaryType |
type(BinaryContext ctx,
BinaryObjectEx obj)
Create binary type which is used by users.
|
static byte |
typeByClass(Class<?> cls) |
static BinaryType |
typeProxy(BinaryContext ctx,
BinaryObjectEx obj)
Create binary type proxy.
|
static @Nullable Object |
unmarshal(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr) |
static @Nullable Object |
unmarshal(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
BinaryReaderHandlesHolder handles) |
static @Nullable Object |
unmarshal(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
BinaryReaderHandlesHolder handles,
boolean detach) |
static @Nullable Object |
unmarshal(BinaryInputStream in,
BinaryContext ctx,
ClassLoader ldr,
BinaryReaderHandlesHolder handles,
boolean detach,
boolean deserialize) |
static Object |
unwrapLazy(@Nullable Object obj) |
static Iterator<Object> |
unwrapLazyIterator(Iterator<Object> delegate) |
static int |
updateSchemaId(int schemaId,
int fieldId)
Update schema ID when new field is added.
|
static String |
utf8BytesToStr(byte[] arr,
int off,
int len)
Reconstructs string from UTF-8 bytes.
|
static void |
validateEnumValues(String typeName,
@Nullable Map<String,Integer> enumValues)
Checks enum values mapping.
|
static boolean |
wrapTrees() |
static void |
writeIgniteUuid(BinaryRawWriter out,
@Nullable IgniteUuid val)
Write
IgniteUuid instance. |
static void |
writePlainObject(BinaryWriterExImpl writer,
Object val)
Write value with flag. e.g. writePlainObject(writer, (byte)77) will write two byte: {BYTE, 77}.
|
static BinaryWriteReplacer |
writeReplacer(Class cls)
Get predefined write-replacer associated with class.
|
public static final boolean USE_STR_SERIALIZATION_VER_2
public static final Map<Class,BinaryWriteReplacer> CLS_TO_WRITE_REPLACER
public static final Class<? extends Collection> SINGLETON_LIST_CLS
public static final short FLAG_USR_TYP
public static final short FLAG_HAS_SCHEMA
public static final short FLAG_HAS_RAW
public static final short FLAG_OFFSET_ONE_BYTE
public static final short FLAG_OFFSET_TWO_BYTES
public static final short FLAG_COMPACT_FOOTER
public static final short FLAG_CUSTOM_DOTNET_TYPE
public static final int OFFSET_1
public static final int OFFSET_2
public static final int OFFSET_4
public static final int FIELD_ID_LEN
public static final boolean WRAP_TREES
public static final boolean FIELDS_SORTED_ORDER
public static boolean isUserType(short flags)
flags
- Flags.True
if set.public static boolean hasSchema(short flags)
flags
- Flags.True
if set.public static boolean hasRaw(short flags)
flags
- Flags.True
if set.public static boolean isCompactFooter(short flags)
flags
- Flags.True
if set.public static boolean isFlagSet(short flags, short flag)
flags
- Flags.flag
- Flag.True
if flag is set in flags.public static int schemaInitialId()
public static int updateSchemaId(int schemaId, int fieldId)
schemaId
- Current schema ID.fieldId
- Field ID.public static String fieldTypeName(int typeId)
typeId
- Field type ID.null
if unknown.public static void writePlainObject(BinaryWriterExImpl writer, Object val)
writer
- Wval
- Value.public static Object unwrapLazy(@Nullable @Nullable Object obj)
obj
- Value to unwrap.public static Iterator<Object> unwrapLazyIterator(Iterator<Object> delegate)
delegate
- Iterator to delegate.public static boolean isPlainType(int type)
true
if content of serialized value cannot contain references to other object.public static boolean isPlainArrayType(int type)
type
- Array type.true
if content of serialized array value cannot contain references to other object.public static byte typeByClass(Class<?> cls)
cls
- Class.public static boolean isBinaryType(Class<?> cls)
cls
- Class to check.public static boolean wrapTrees()
public static boolean knownMap(Object map)
map
- Map to check.True
if this map type is supported.public static <K,V> Map<K,V> newKnownMap(Object map)
map
- Map.public static <K,V> Map<K,V> newMap(Map<K,V> map)
map
has. Otherwise returns new HashMap
instance.map
- Original map.public static boolean knownCollection(Object col)
col
- Collection to check.public static boolean knownCacheObject(Object obj)
obj
- Object to check.public static boolean knownArray(Object arr)
arr
- Array to check.true
if this array is of a known type.public static <V> Collection<V> newKnownCollection(Object col)
col
- Collection.public static <V> Set<V> newSet(Set<V> set)
set
has. Otherwise returns new HashSet
instance.set
- Original set.public static void checkProtocolVersion(byte protoVer)
protoVer
- Protocol version.public static int length(BinaryPositionReadable in, int start)
in
- Input stream.start
- Start position.public static int footerStartRelative(BinaryPositionReadable in, int start)
in
- Input stream.start
- Object start position inside the stream.public static int footerStartAbsolute(BinaryPositionReadable in, int start)
in
- Input stream.start
- Start position.public static IgniteBiTuple<Integer,Integer> footerAbsolute(BinaryPositionReadable in, int start)
in
- Input stream.start
- Start position.public static int rawOffsetRelative(BinaryPositionReadable in, int start)
in
- Input stream.start
- Object start position inside the stream.public static int rawOffsetAbsolute(BinaryPositionReadable in, int start)
in
- Input stream.start
- Object start position inside the stream.public static int fieldOffsetLength(short flags)
flags
- Flags.public static int fieldIdLength(short flags)
flags
- Flags.public static int fieldOffsetRelative(BinaryPositionReadable stream, int pos, int fieldOffsetSize)
stream
- Stream.pos
- Position.fieldOffsetSize
- Field offset size.public static BinaryMetadata mergeMetadata(@Nullable @Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta)
oldMeta
- Old meta.newMeta
- New meta.BinaryObjectException
- If merge failed due to metadata conflict.public static BinaryMetadata mergeMetadata(@Nullable @Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta, @Nullable @Nullable Set<Integer> changedSchemas)
oldMeta
- Old meta.newMeta
- New meta.changedSchemas
- Set for holding changed schemas.BinaryObjectException
- If merge failed due to metadata conflict.public static BinaryWriteMode mode(Class<?> cls)
cls
- Class.public static boolean isSpecialCollection(Class cls)
cls
- Class.True
if this is a special collection class.public static boolean isSpecialMap(Class cls)
cls
- Class.True
if this is a special map class.public static byte[] doReadByteArray(BinaryInputStream in)
public static boolean[] doReadBooleanArray(BinaryInputStream in)
public static short[] doReadShortArray(BinaryInputStream in)
public static char[] doReadCharArray(BinaryInputStream in)
public static int[] doReadIntArray(BinaryInputStream in)
public static long[] doReadLongArray(BinaryInputStream in)
public static float[] doReadFloatArray(BinaryInputStream in)
public static double[] doReadDoubleArray(BinaryInputStream in)
public static BigDecimal doReadDecimal(BinaryInputStream in)
public static String doReadString(BinaryInputStream in)
public static UUID doReadUuid(BinaryInputStream in)
public static Date doReadDate(BinaryInputStream in)
public static Timestamp doReadTimestamp(BinaryInputStream in)
public static Time doReadTime(BinaryInputStream in)
public static BigDecimal[] doReadDecimalArray(BinaryInputStream in) throws BinaryObjectException
BinaryObjectException
- In case of error.public static String[] doReadStringArray(BinaryInputStream in) throws BinaryObjectException
BinaryObjectException
- In case of error.public static UUID[] doReadUuidArray(BinaryInputStream in) throws BinaryObjectException
BinaryObjectException
- In case of error.public static Date[] doReadDateArray(BinaryInputStream in) throws BinaryObjectException
BinaryObjectException
- In case of error.public static Timestamp[] doReadTimestampArray(BinaryInputStream in) throws BinaryObjectException
BinaryObjectException
- In case of error.public static Time[] doReadTimeArray(BinaryInputStream in) throws BinaryObjectException
BinaryObjectException
- In case of error.public static BinaryObject doReadBinaryObject(BinaryInputStream in, BinaryContext ctx, boolean detach)
public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr) throws BinaryObjectException
in
- Binary input stream.ctx
- Binary context.ldr
- Class loader.BinaryObjectException
- If failed.public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, boolean deserialize) throws BinaryObjectException
in
- Binary input stream.ctx
- Binary context.ldr
- Class loader.deserialize
- Doesn't load the class when the flag is false
. Class information is skipped.deserialize == true
. Otherwise returns null
BinaryObjectException
- If failed.public static Object doReadProxy(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles)
public static String doReadClassName(BinaryInputStream in)
in
- Input stream.public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, int typeId) throws BinaryObjectException
in
- Binary input stream.ctx
- Binary context.ldr
- Class loader.typeId
- Type id.BinaryObjectException
- If failed.public static Class resolveClass(BinaryContext ctx, int typeId, @Nullable @Nullable String clsName, @Nullable @Nullable ClassLoader ldr, boolean registerMeta)
ctx
- Binary context.typeId
- Type ID.clsName
- Class name.ldr
- Class loaded.public static BinaryEnumObjectImpl doReadBinaryEnum(BinaryInputStream in, BinaryContext ctx)
in
- Input stream.ctx
- Binary context.public static Enum<?> doReadEnum(BinaryInputStream in, Class<?> cls, boolean useCache) throws BinaryObjectException
cls
- Enum class.useCache
- True if class loader cache will be used, false otherwise.BinaryObjectException
public static Object[] doReadEnumArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, Class<?> cls) throws BinaryObjectException
cls
- Enum class.BinaryObjectException
public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @Nullable @Nullable ClassLoader clsLdr)
@Nullable public static @Nullable Object doReadObject(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles) throws BinaryObjectException
BinaryObjectException
- In case of error.@Nullable public static @Nullable Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr) throws BinaryObjectException
BinaryObjectException
- In case of error.@Nullable public static @Nullable Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles) throws BinaryObjectException
BinaryObjectException
- In case of error.@Nullable public static @Nullable Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach) throws BinaryObjectException
BinaryObjectException
- In case of error.@Nullable public static @Nullable Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) throws BinaryObjectException
BinaryObjectException
- In case of error.public static Object[] doReadObjectArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) throws BinaryObjectException
in
- Binary input stream.ctx
- Binary context.ldr
- Class loader.handles
- Holder for handles.detach
- Detach flag.deserialize
- Deep flag.BinaryObjectException
- In case of error.public static Collection<?> doReadCollection(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize, BinaryCollectionFactory factory) throws BinaryObjectException
deserialize
- Deep flag.factory
- Collection factory.BinaryObjectException
- In case of error.public static Map<?,?> doReadMap(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize, BinaryMapFactory factory) throws BinaryObjectException
deserialize
- Deep flag.factory
- Map factory.BinaryObjectException
- In case of error.public static int positionForHandle(BinaryInputStream in)
public static boolean isBinarylizable(Class cls)
cls
- Class.True
if binarylizable.public static boolean isCustomJavaSerialization(Class cls)
cls
- Class.true
if custom Java serialization logic exists, false
otherwise.public static String qualifiedFieldName(Class cls, String fieldName)
cls
- Class.fieldName
- Field name.public static void writeIgniteUuid(BinaryRawWriter out, @Nullable @Nullable IgniteUuid val)
IgniteUuid
instance.out
- Writer.val
- Value.@Nullable public static @Nullable IgniteUuid readIgniteUuid(BinaryRawReader in)
IgniteUuid
instance.in
- Reader.public static String utf8BytesToStr(byte[] arr, int off, int len)
arr
- array Byte array.off
- offset Offset in the array.len
- length Byte array lenght.public static byte[] strToUtf8Bytes(String val)
val
- String to convert.public static BinaryType typeProxy(BinaryContext ctx, BinaryObjectEx obj)
ctx
- Context.obj
- Binary object.public static BinaryType type(BinaryContext ctx, BinaryObjectEx obj)
ctx
- Context.obj
- Binary object.public static BinaryWriteReplacer writeReplacer(Class cls)
cls
- Class.public static void validateEnumValues(String typeName, @Nullable @Nullable Map<String,Integer> enumValues) throws BinaryObjectException
typeName
- Name of the type.enumValues
- Enum name to ordinal mapping.BinaryObjectException
public static Map<String,Integer> mergeEnumValues(String typeName, @Nullable @Nullable Map<String,Integer> oldValues, Map<String,Integer> newValues) throws BinaryObjectException
typeName
- Name of the type.oldValues
- Old enum value mapping.newValues
- New enum value mapping.BinaryObjectException
- in case of name or value conflict.
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.10.0 Release Date : March 10 2021