Class BinaryUtils
- java.lang.Object
-
- org.apache.ignite.internal.binary.BinaryUtils
-
public class BinaryUtils extends Object
Binary utils.
-
-
Field Summary
Fields Modifier and Type Field Description static Map<Class,BinaryWriteReplacer>CLS_TO_WRITE_REPLACERMap from class to associated write replacer.static intFIELD_ID_LENField ID length.static booleanFIELDS_SORTED_ORDERWhether to sort field in binary objects (doesn't affect Binarylizable).static shortFLAG_COMPACT_FOOTERFlag: compact footer, no field IDs.static shortFLAG_CUSTOM_DOTNET_TYPEFlag: raw data contains .NET type information.static shortFLAG_HAS_RAWFlag indicating that object has raw data.static shortFLAG_HAS_SCHEMAFlag: only raw data exists.static shortFLAG_OFFSET_ONE_BYTEFlag: offsets take 1 byte.static shortFLAG_OFFSET_TWO_BYTESFlag: offsets take 2 bytes.static Map<Byte,Class<?>>FLAG_TO_CLASSstatic shortFLAG_USR_TYPFlag: user type.static StringMAPPING_FILE_EXTENSIONActual file name "{type_id}.classname{platform_id}".static StringMETADATA_FILE_SUFFIXBinary metadata file suffix.static intOFFSET_1Offset which fits into 1 byte.static intOFFSET_2Offset which fits into 2 bytes.static intOFFSET_4Offset which fits into 4 bytes.static Map<Class<?>,Byte>PLAIN_CLASS_TO_FLAGstatic Class<? extends Collection>SINGLETON_LIST_CLSClass for SingletonList obtained at runtime.static booleanUSE_STR_SERIALIZATION_VER_2static booleanWRAP_TREESWhether to skip TreeMap/TreeSet wrapping.
-
Constructor Summary
Constructors Constructor Description BinaryUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbinaryMetaFileName(int typeId)static voidcheckProtocolVersion(byte protoVer)Check protocol version.static intdataStartRelative(BinaryPositionReadable in, int start)static BinaryArraydoReadBinaryArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize, boolean isEnumArray)static BinaryEnumObjectImpldoReadBinaryEnum(BinaryInputStream in, BinaryContext ctx)Read binary enum.static BinaryObjectdoReadBinaryObject(BinaryInputStream in, BinaryContext ctx, boolean detach)static boolean[]doReadBooleanArray(BinaryInputStream in)static byte[]doReadByteArray(BinaryInputStream in)static char[]doReadCharArray(BinaryInputStream in)static ClassdoReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr)static ClassdoReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, boolean deserialize)static ClassdoReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, int typeId)static StringdoReadClassName(BinaryInputStream in)static Collection<?>doReadCollection(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize, BinaryCollectionFactory factory)static DatedoReadDate(BinaryInputStream in)static Date[]doReadDateArray(BinaryInputStream in)static BigDecimaldoReadDecimal(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 ObjectdoReadObject(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles)static Object[]doReadObjectArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize)static ObjectdoReadOptimized(BinaryInputStream in, BinaryContext ctx, @Nullable ClassLoader clsLdr)Read object serialized using optimized marshaller.static ObjectdoReadProxy(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles)static short[]doReadShortArray(BinaryInputStream in)static StringdoReadString(BinaryInputStream in)static String[]doReadStringArray(BinaryInputStream in)static TimedoReadTime(BinaryInputStream in)static Time[]doReadTimeArray(BinaryInputStream in)static TimestampdoReadTimestamp(BinaryInputStream in)static Timestamp[]doReadTimestampArray(BinaryInputStream in)static UUIDdoReadUuid(BinaryInputStream in)static UUID[]doReadUuidArray(BinaryInputStream in)static intfieldIdLength(short flags)Get field ID length.static intfieldOffsetLength(short flags)Get offset length for the given flags.static intfieldOffsetRelative(BinaryPositionReadable stream, int pos, int fieldOffsetSize)Get relative field offset.static StringfieldTypeName(int typeId)static IgniteBiTuple<Integer,Integer>footerAbsolute(BinaryPositionReadable in, int start)Get object's footer.static intfooterStartAbsolute(BinaryPositionReadable in, int start)Get object's footer.static intfooterStartRelative(BinaryPositionReadable in, int start)Get footer start of the object.static booleanhasRaw(short flags)Check if raw-only flag is set.static booleanhasSchema(short flags)Check if raw-only flag is set.static booleanisBinarylizable(Class cls)Check if class is binarylizable.static booleanisBinaryType(Class<?> cls)Tells whether provided type is binary.static booleanisCompactFooter(short flags)Check if "no-field-ids" flag is set.static booleanisCustomJavaSerialization(Class cls)Determines whether class contains custom Java serialization logic.static booleanisFlagSet(short flags, short flag)Check whether particular flag is set.static booleanisObjectArray(Class<?> cls)static booleanisPlainArrayType(int type)Checks whether an array type values can or can not contain references to other object.static booleanisPlainType(int type)static booleanisSpecialCollection(Class cls)Check if class represents a collection which must be treated specially.static booleanisSpecialMap(Class cls)Check if class represents a map which must be treated specially.static booleanisUserType(short flags)Check if user type flag is set.static booleanknownArray(Object arr)static booleanknownCacheObject(Object obj)static booleanknownCollection(Object col)static booleanknownMap(Object map)static intlength(BinaryPositionReadable in, int start)Get binary object length.static bytemappedFilePlatformId(String fileName)static intmappedTypeId(String fileName)static StringmappingFileName(byte platformId, int typeId)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 BinaryMetadatamergeMetadata(@Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta)Merge old and new metas.static BinaryMetadatamergeMetadata(@Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta, @Nullable Set<Integer> changedSchemas)Merge old and new metas.static BinaryWriteModemode(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 asmaphas.static <V> Set<V>newSet(Set<V> set)Attempts to create a new set of the same type assethas.static booleannotTmpFile(File f)static intpositionForHandle(BinaryInputStream in)Get position to be used for handle.static StringqualifiedFieldName(Class cls, String fieldName)Create qualified field name.static Object[]rawArrayFromBinary(Object obj)static intrawOffsetAbsolute(BinaryPositionReadable in, int start)Get absolute raw offset of the object.static intrawOffsetRelative(BinaryPositionReadable in, int start)Get relative raw offset of the object.static @Nullable IgniteUuidreadIgniteUuid(BinaryRawReader in)ReadIgniteUuidinstance.static StringreadMapping(File file)static ClassresolveClass(BinaryContext ctx, int typeId, @Nullable String clsName, @Nullable ClassLoader ldr, boolean registerMeta)Resolve the class.static intschemaInitialId()Schema initial ID.static byte[]strToUtf8Bytes(String val)Converts the string into UTF-8 byte array considering special symbols like the surrogates.static BinaryTypetype(BinaryContext ctx, BinaryObjectEx obj)Create binary type which is used by users.static bytetypeByClass(Class<?> cls)static inttypeId(String fileName)static StringtypeName(Object obj)static BinaryTypetypeProxy(BinaryContext ctx, BinaryObjectEx obj)Create binary type proxy.static @Nullable Objectunmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr)static @Nullable Objectunmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles)static @Nullable Objectunmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach)static @Nullable Objectunmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize)static ObjectunwrapLazy(@Nullable Object obj)static Iterator<Object>unwrapLazyIterator(Iterator<Object> delegate)static intupdateSchemaId(int schemaId, int fieldId)Update schema ID when new field is added.static Stringutf8BytesToStr(byte[] arr, int off, int len)Reconstructs string from UTF-8 bytes.static voidvalidateEnumValues(String typeName, @Nullable Map<String,Integer> enumValues)Checks enum values mapping.static booleanwrapTrees()static voidwriteIgniteUuid(BinaryRawWriter out, @Nullable IgniteUuid val)WriteIgniteUuidinstance.static voidwritePlainObject(BinaryWriterExImpl writer, Object val)Write value with flag. e.g. writePlainObject(writer, (byte)77) will write two byte: {BYTE, 77}.static BinaryWriteReplacerwriteReplacer(Class cls)Get predefined write-replacer associated with class.
-
-
-
Field Detail
-
METADATA_FILE_SUFFIX
public static final String METADATA_FILE_SUFFIX
Binary metadata file suffix.- See Also:
- Constant Field Values
-
MAPPING_FILE_EXTENSION
public static final String MAPPING_FILE_EXTENSION
Actual file name "{type_id}.classname{platform_id}". Wheretype_idis integer type id andplatform_idis byte fromPlatformType- See Also:
- Constant Field Values
-
USE_STR_SERIALIZATION_VER_2
public static final boolean USE_STR_SERIALIZATION_VER_2
-
CLS_TO_WRITE_REPLACER
public static final Map<Class,BinaryWriteReplacer> CLS_TO_WRITE_REPLACER
Map from class to associated write replacer.
-
SINGLETON_LIST_CLS
public static final Class<? extends Collection> SINGLETON_LIST_CLS
Class for SingletonList obtained at runtime.
-
FLAG_USR_TYP
public static final short FLAG_USR_TYP
Flag: user type.- See Also:
- Constant Field Values
-
FLAG_HAS_SCHEMA
public static final short FLAG_HAS_SCHEMA
Flag: only raw data exists.- See Also:
- Constant Field Values
-
FLAG_HAS_RAW
public static final short FLAG_HAS_RAW
Flag indicating that object has raw data.- See Also:
- Constant Field Values
-
FLAG_OFFSET_ONE_BYTE
public static final short FLAG_OFFSET_ONE_BYTE
Flag: offsets take 1 byte.- See Also:
- Constant Field Values
-
FLAG_OFFSET_TWO_BYTES
public static final short FLAG_OFFSET_TWO_BYTES
Flag: offsets take 2 bytes.- See Also:
- Constant Field Values
-
FLAG_COMPACT_FOOTER
public static final short FLAG_COMPACT_FOOTER
Flag: compact footer, no field IDs.- See Also:
- Constant Field Values
-
FLAG_CUSTOM_DOTNET_TYPE
public static final short FLAG_CUSTOM_DOTNET_TYPE
Flag: raw data contains .NET type information. Always 0 in Java. Keep it here for information only.- See Also:
- Constant Field Values
-
OFFSET_1
public static final int OFFSET_1
Offset which fits into 1 byte.- See Also:
- Constant Field Values
-
OFFSET_2
public static final int OFFSET_2
Offset which fits into 2 bytes.- See Also:
- Constant Field Values
-
OFFSET_4
public static final int OFFSET_4
Offset which fits into 4 bytes.- See Also:
- Constant Field Values
-
FIELD_ID_LEN
public static final int FIELD_ID_LEN
Field ID length.- See Also:
- Constant Field Values
-
WRAP_TREES
public static final boolean WRAP_TREES
Whether to skip TreeMap/TreeSet wrapping.
-
FIELDS_SORTED_ORDER
public static boolean FIELDS_SORTED_ORDER
Whether to sort field in binary objects (doesn't affect Binarylizable).
-
-
Method Detail
-
isUserType
public static boolean isUserType(short flags)
Check if user type flag is set.- Parameters:
flags- Flags.- Returns:
Trueif set.
-
hasSchema
public static boolean hasSchema(short flags)
Check if raw-only flag is set.- Parameters:
flags- Flags.- Returns:
Trueif set.
-
hasRaw
public static boolean hasRaw(short flags)
Check if raw-only flag is set.- Parameters:
flags- Flags.- Returns:
Trueif set.
-
isCompactFooter
public static boolean isCompactFooter(short flags)
Check if "no-field-ids" flag is set.- Parameters:
flags- Flags.- Returns:
Trueif set.
-
isFlagSet
public static boolean isFlagSet(short flags, short flag)Check whether particular flag is set.- Parameters:
flags- Flags.flag- Flag.- Returns:
Trueif flag is set in flags.
-
schemaInitialId
public static int schemaInitialId()
Schema initial ID.- Returns:
- ID.
-
updateSchemaId
public static int updateSchemaId(int schemaId, int fieldId)Update schema ID when new field is added.- Parameters:
schemaId- Current schema ID.fieldId- Field ID.- Returns:
- New schema ID.
-
fieldTypeName
public static String fieldTypeName(int typeId)
- Parameters:
typeId- Field type ID.- Returns:
- Field type name or
nullif unknown.
-
writePlainObject
public static void writePlainObject(BinaryWriterExImpl writer, Object val)
Write value with flag. e.g. writePlainObject(writer, (byte)77) will write two byte: {BYTE, 77}.- Parameters:
writer- Wval- Value.
-
unwrapLazy
public static Object unwrapLazy(@Nullable @Nullable Object obj)
- Parameters:
obj- Value to unwrap.- Returns:
- Unwrapped value.
-
unwrapLazyIterator
public static Iterator<Object> unwrapLazyIterator(Iterator<Object> delegate)
- Parameters:
delegate- Iterator to delegate.- Returns:
- New iterator.
-
isPlainType
public static boolean isPlainType(int type)
- Returns:
trueif content of serialized value cannot contain references to other object.
-
isPlainArrayType
public static boolean isPlainArrayType(int type)
Checks whether an array type values can or can not contain references to other object.- Parameters:
type- Array type.- Returns:
trueif content of serialized array value cannot contain references to other object.
-
typeByClass
public static byte typeByClass(Class<?> cls)
- Parameters:
cls- Class.- Returns:
- Binary field type.
-
isBinaryType
public static boolean isBinaryType(Class<?> cls)
Tells whether provided type is binary.- Parameters:
cls- Class to check.- Returns:
- Whether type is binary.
-
wrapTrees
public static boolean wrapTrees()
- Returns:
- Whether tree structures should be wrapped.
-
knownMap
public static boolean knownMap(Object map)
- Parameters:
map- Map to check.- Returns:
Trueif this map type is supported.
-
newKnownMap
public static <K,V> Map<K,V> newKnownMap(Object map)
Attempts to create a new map of the same known type. Will return null if map type is not supported.- Parameters:
map- Map.- Returns:
- New map of the same type or null.
-
newMap
public static <K,V> Map<K,V> newMap(Map<K,V> map)
Attempts to create a new map of the same type asmaphas. Otherwise returns newHashMapinstance.- Parameters:
map- Original map.- Returns:
- New map.
-
knownCollection
public static boolean knownCollection(Object col)
- Parameters:
col- Collection to check.- Returns:
- True if this is a collection of a known type.
-
knownCacheObject
public static boolean knownCacheObject(Object obj)
- Parameters:
obj- Object to check.- Returns:
- True if this is an object of a known type.
-
knownArray
public static boolean knownArray(Object arr)
- Parameters:
arr- Array to check.- Returns:
trueif this array is of a known type.
-
newKnownCollection
public static <V> Collection<V> newKnownCollection(Object col)
Attempts to create a new collection of the same known type. Will return null if collection type is unknown.- Parameters:
col- Collection.- Returns:
- New empty collection.
-
newSet
public static <V> Set<V> newSet(Set<V> set)
Attempts to create a new set of the same type assethas. Otherwise returns newHashSetinstance.- Parameters:
set- Original set.- Returns:
- New set.
-
checkProtocolVersion
public static void checkProtocolVersion(byte protoVer)
Check protocol version.- Parameters:
protoVer- Protocol version.
-
length
public static int length(BinaryPositionReadable in, int start)
Get binary object length.- Parameters:
in- Input stream.start- Start position.- Returns:
- Length.
-
dataStartRelative
public static int dataStartRelative(BinaryPositionReadable in, int start)
-
footerStartRelative
public static int footerStartRelative(BinaryPositionReadable in, int start)
Get footer start of the object.- Parameters:
in- Input stream.start- Object start position inside the stream.- Returns:
- Footer start.
-
footerStartAbsolute
public static int footerStartAbsolute(BinaryPositionReadable in, int start)
Get object's footer.- Parameters:
in- Input stream.start- Start position.- Returns:
- Footer start.
-
footerAbsolute
public static IgniteBiTuple<Integer,Integer> footerAbsolute(BinaryPositionReadable in, int start)
Get object's footer.- Parameters:
in- Input stream.start- Start position.- Returns:
- Footer.
-
rawOffsetRelative
public static int rawOffsetRelative(BinaryPositionReadable in, int start)
Get relative raw offset of the object.- Parameters:
in- Input stream.start- Object start position inside the stream.- Returns:
- Raw offset.
-
rawOffsetAbsolute
public static int rawOffsetAbsolute(BinaryPositionReadable in, int start)
Get absolute raw offset of the object.- Parameters:
in- Input stream.start- Object start position inside the stream.- Returns:
- Raw offset.
-
fieldOffsetLength
public static int fieldOffsetLength(short flags)
Get offset length for the given flags.- Parameters:
flags- Flags.- Returns:
- Offset size.
-
fieldIdLength
public static int fieldIdLength(short flags)
Get field ID length.- Parameters:
flags- Flags.- Returns:
- Field ID length.
-
fieldOffsetRelative
public static int fieldOffsetRelative(BinaryPositionReadable stream, int pos, int fieldOffsetSize)
Get relative field offset.- Parameters:
stream- Stream.pos- Position.fieldOffsetSize- Field offset size.- Returns:
- Relative field offset.
-
mergeMetadata
public static BinaryMetadata mergeMetadata(@Nullable @Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta)
Merge old and new metas.- Parameters:
oldMeta- Old meta.newMeta- New meta.- Returns:
- New meta if old meta was null, old meta if no changes detected, merged meta otherwise.
- Throws:
BinaryObjectException- If merge failed due to metadata conflict.
-
mergeMetadata
public static BinaryMetadata mergeMetadata(@Nullable @Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta, @Nullable @Nullable Set<Integer> changedSchemas)
Merge old and new metas.- Parameters:
oldMeta- Old meta.newMeta- New meta.changedSchemas- Set for holding changed schemas.- Returns:
- New meta if old meta was null, old meta if no changes detected, merged meta otherwise.
- Throws:
BinaryObjectException- If merge failed due to metadata conflict.
-
mode
public static BinaryWriteMode mode(Class<?> cls)
- Parameters:
cls- Class.- Returns:
- Mode.
-
isSpecialCollection
public static boolean isSpecialCollection(Class cls)
Check if class represents a collection which must be treated specially.- Parameters:
cls- Class.- Returns:
Trueif this is a special collection class.
-
isSpecialMap
public static boolean isSpecialMap(Class cls)
Check if class represents a map which must be treated specially.- Parameters:
cls- Class.- Returns:
Trueif this is a special map class.
-
doReadByteArray
public static byte[] doReadByteArray(BinaryInputStream in)
- Returns:
- Value.
-
doReadBooleanArray
public static boolean[] doReadBooleanArray(BinaryInputStream in)
- Returns:
- Value.
-
doReadShortArray
public static short[] doReadShortArray(BinaryInputStream in)
- Returns:
- Value.
-
doReadCharArray
public static char[] doReadCharArray(BinaryInputStream in)
- Returns:
- Value.
-
doReadIntArray
public static int[] doReadIntArray(BinaryInputStream in)
- Returns:
- Value.
-
doReadLongArray
public static long[] doReadLongArray(BinaryInputStream in)
- Returns:
- Value.
-
doReadFloatArray
public static float[] doReadFloatArray(BinaryInputStream in)
- Returns:
- Value.
-
doReadDoubleArray
public static double[] doReadDoubleArray(BinaryInputStream in)
- Returns:
- Value.
-
doReadDecimal
public static BigDecimal doReadDecimal(BinaryInputStream in)
- Returns:
- Value.
-
doReadString
public static String doReadString(BinaryInputStream in)
- Returns:
- Value.
-
doReadUuid
public static UUID doReadUuid(BinaryInputStream in)
- Returns:
- Value.
-
doReadDate
public static Date doReadDate(BinaryInputStream in)
- Returns:
- Value.
-
doReadTimestamp
public static Timestamp doReadTimestamp(BinaryInputStream in)
- Returns:
- Value.
-
doReadTime
public static Time doReadTime(BinaryInputStream in)
- Returns:
- Value.
-
doReadDecimalArray
public static BigDecimal[] doReadDecimalArray(BinaryInputStream in) throws BinaryObjectException
- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
doReadStringArray
public static String[] doReadStringArray(BinaryInputStream in) throws BinaryObjectException
- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
doReadUuidArray
public static UUID[] doReadUuidArray(BinaryInputStream in) throws BinaryObjectException
- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
doReadDateArray
public static Date[] doReadDateArray(BinaryInputStream in) throws BinaryObjectException
- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
doReadTimestampArray
public static Timestamp[] doReadTimestampArray(BinaryInputStream in) throws BinaryObjectException
- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
doReadTimeArray
public static Time[] doReadTimeArray(BinaryInputStream in) throws BinaryObjectException
- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
doReadBinaryObject
public static BinaryObject doReadBinaryObject(BinaryInputStream in, BinaryContext ctx, boolean detach)
- Returns:
- Value.
-
doReadClass
public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr) throws BinaryObjectException
- Parameters:
in- Binary input stream.ctx- Binary context.ldr- Class loader.- Returns:
- Class object specified at the input stream.
- Throws:
BinaryObjectException- If failed.
-
doReadClass
public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, boolean deserialize) throws BinaryObjectException
- Parameters:
in- Binary input stream.ctx- Binary context.ldr- Class loader.deserialize- Doesn't load the class when the flag isfalse. Class information is skipped.- Returns:
- Class object specified at the input stream if
deserialize == true. Otherwise returnsnull - Throws:
BinaryObjectException- If failed.
-
doReadProxy
public static Object doReadProxy(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles)
- Returns:
- Value.
-
doReadClassName
public static String doReadClassName(BinaryInputStream in)
- Parameters:
in- Input stream.- Returns:
- Class name.
-
doReadClass
public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, int typeId) throws BinaryObjectException
- Parameters:
in- Binary input stream.ctx- Binary context.ldr- Class loader.typeId- Type id.- Returns:
- Class object specified at the input stream.
- Throws:
BinaryObjectException- If failed.
-
resolveClass
public static Class resolveClass(BinaryContext ctx, int typeId, @Nullable @Nullable String clsName, @Nullable @Nullable ClassLoader ldr, boolean registerMeta)
Resolve the class.- Parameters:
ctx- Binary context.typeId- Type ID.clsName- Class name.ldr- Class loaded.- Returns:
- Resovled class.
-
doReadBinaryEnum
public static BinaryEnumObjectImpl doReadBinaryEnum(BinaryInputStream in, BinaryContext ctx)
Read binary enum.- Parameters:
in- Input stream.ctx- Binary context.- Returns:
- Enum.
-
doReadEnum
public static Enum<?> doReadEnum(BinaryInputStream in, Class<?> cls, boolean useCache) throws BinaryObjectException
Having target class in place we simply read ordinal and create final representation.- Parameters:
cls- Enum class.useCache- True if class loader cache will be used, false otherwise.- Returns:
- Value.
- Throws:
BinaryObjectException
-
doReadEnumArray
public static Object[] doReadEnumArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, Class<?> cls) throws BinaryObjectException
- Parameters:
cls- Enum class.- Returns:
- Value.
- Throws:
BinaryObjectException
-
doReadOptimized
public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @Nullable @Nullable ClassLoader clsLdr)
Read object serialized using optimized marshaller.- Returns:
- Result.
-
doReadObject
@Nullable public static @Nullable Object doReadObject(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles) throws BinaryObjectException
- Returns:
- Object.
- Throws:
BinaryObjectException- In case of error.
-
unmarshal
@Nullable public static @Nullable Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr) throws BinaryObjectException
- Returns:
- Unmarshalled value.
- Throws:
BinaryObjectException- In case of error.
-
unmarshal
@Nullable public static @Nullable Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles) throws BinaryObjectException
- Returns:
- Unmarshalled value.
- Throws:
BinaryObjectException- In case of error.
-
unmarshal
@Nullable public static @Nullable Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach) throws BinaryObjectException
- Returns:
- Unmarshalled value.
- Throws:
BinaryObjectException- In case of error.
-
unmarshal
@Nullable public static @Nullable Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) throws BinaryObjectException
- Returns:
- Unmarshalled value.
- Throws:
BinaryObjectException- In case of error.
-
doReadObjectArray
public static Object[] doReadObjectArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize) throws BinaryObjectException
- Parameters:
in- Binary input stream.ctx- Binary context.ldr- Class loader.handles- Holder for handles.detach- Detach flag.deserialize- Deep flag.- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
doReadBinaryArray
public static BinaryArray doReadBinaryArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize, boolean isEnumArray)
- Parameters:
in- Binary input stream.ctx- Binary context.ldr- Class loader.handles- Holder for handles.detach- Detach flag.deserialize- Deep flag.- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
doReadCollection
public static Collection<?> doReadCollection(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize, BinaryCollectionFactory factory) throws BinaryObjectException
- Parameters:
deserialize- Deep flag.factory- Collection factory.- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
doReadMap
public static Map<?,?> doReadMap(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, BinaryReaderHandlesHolder handles, boolean detach, boolean deserialize, BinaryMapFactory factory) throws BinaryObjectException
- Parameters:
deserialize- Deep flag.factory- Map factory.- Returns:
- Value.
- Throws:
BinaryObjectException- In case of error.
-
positionForHandle
public static int positionForHandle(BinaryInputStream in)
Get position to be used for handle. We assume here that the hdr byte was read, hence subtract -1.- Returns:
- Position for handle.
-
isBinarylizable
public static boolean isBinarylizable(Class cls)
Check if class is binarylizable.- Parameters:
cls- Class.- Returns:
Trueif binarylizable.
-
isCustomJavaSerialization
public static boolean isCustomJavaSerialization(Class cls)
Determines whether class contains custom Java serialization logic.- Parameters:
cls- Class.- Returns:
trueif custom Java serialization logic exists,falseotherwise.
-
qualifiedFieldName
public static String qualifiedFieldName(Class cls, String fieldName)
Create qualified field name.- Parameters:
cls- Class.fieldName- Field name.- Returns:
- Qualified field name.
-
writeIgniteUuid
public static void writeIgniteUuid(BinaryRawWriter out, @Nullable @Nullable IgniteUuid val)
WriteIgniteUuidinstance.- Parameters:
out- Writer.val- Value.
-
readIgniteUuid
@Nullable public static @Nullable IgniteUuid readIgniteUuid(BinaryRawReader in)
ReadIgniteUuidinstance.- Parameters:
in- Reader.- Returns:
- Value.
-
utf8BytesToStr
public static String utf8BytesToStr(byte[] arr, int off, int len)
Reconstructs string from UTF-8 bytes.- Parameters:
arr- array Byte array.off- offset Offset in the array.len- length Byte array lenght.- Returns:
- string Resulting string.
-
strToUtf8Bytes
public static byte[] strToUtf8Bytes(String val)
Converts the string into UTF-8 byte array considering special symbols like the surrogates.- Parameters:
val- String to convert.- Returns:
- Resulting byte array.
-
typeProxy
public static BinaryType typeProxy(BinaryContext ctx, BinaryObjectEx obj)
Create binary type proxy.- Parameters:
ctx- Context.obj- Binary object.- Returns:
- Binary type proxy.
-
type
public static BinaryType type(BinaryContext ctx, BinaryObjectEx obj)
Create binary type which is used by users.- Parameters:
ctx- Context.obj- Binary object.- Returns:
- Binary type.
-
binaryMetaFileName
public static String binaryMetaFileName(int typeId)
- Parameters:
typeId- Type id.- Returns:
- Binary metadata file name.
-
mappedTypeId
public static int mappedTypeId(String fileName)
- Parameters:
fileName- Name of file with marshaller mapping information.
-
mappedFilePlatformId
public static byte mappedFilePlatformId(String fileName)
- Parameters:
fileName- Name of file with marshaller mapping information.
-
mappingFileName
public static String mappingFileName(byte platformId, int typeId)
- Parameters:
platformId- Platform id.typeId- Type id.
-
notTmpFile
public static boolean notTmpFile(File f)
- Parameters:
f- File.- Returns:
Trueif file is regular(not temporary).
-
typeId
public static int typeId(String fileName)
- Parameters:
fileName- File name.- Returns:
- Type id
- See Also:
binaryMetaFileName(int),METADATA_FILE_SUFFIX
-
writeReplacer
public static BinaryWriteReplacer writeReplacer(Class cls)
Get predefined write-replacer associated with class.- Parameters:
cls- Class.- Returns:
- Write replacer.
-
validateEnumValues
public static void validateEnumValues(String typeName, @Nullable @Nullable Map<String,Integer> enumValues) throws BinaryObjectException
Checks enum values mapping.- Parameters:
typeName- Name of the type.enumValues- Enum name to ordinal mapping.- Throws:
BinaryObjectException
-
mergeEnumValues
public static Map<String,Integer> mergeEnumValues(String typeName, @Nullable @Nullable Map<String,Integer> oldValues, Map<String,Integer> newValues) throws BinaryObjectException
Merges enum value mappings and checks for conflicts. Possible conflicts: - same name is used for different ordinal values. - ordinal value is used more than once.- Parameters:
typeName- Name of the type.oldValues- Old enum value mapping.newValues- New enum value mapping.- Throws:
BinaryObjectException- in case of name or value conflict.
-
rawArrayFromBinary
public static Object[] rawArrayFromBinary(Object obj)
- Parameters:
obj-BinaryArrayorObject[].- Returns:
- Objects array.
-
isObjectArray
public static boolean isObjectArray(Class<?> cls)
-
typeName
public static String typeName(Object obj)
- Returns:
- Type name of the specified object. If
BinaryObjectwas specified its type will be returned.
-
-