public final class SerializationUtil extends Object
Modifier and Type | Method and Description |
---|---|
static void |
checkSerializable(Object object,
String objectName)
Checks that the
object implements Serializable and is
correctly serializable by actually trying to serialize it. |
static InputStream |
convertToInputStream(DataInput in,
int offset) |
static ObjectDataInputStream |
createObjectDataInputStream(InputStream in,
InternalSerializationService ss) |
static ObjectDataOutputStream |
createObjectDataOutputStream(OutputStream out,
InternalSerializationService ss) |
static int |
getPortableVersion(Portable portable,
int defaultVersion) |
static <T> Collection<T> |
readCollection(ObjectDataInput in)
Reads a collection from the given
ObjectDataInput . |
static <T> List<T> |
readList(ObjectDataInput in)
Reads a list from the given
ObjectDataInput . |
static <K,V> Map<K,V> |
readMap(ObjectDataInput in) |
static <T> Collection<T> |
readNullableCollection(ObjectDataInput in)
Reads a collection from the given
ObjectDataInput . |
static <T> List<T> |
readNullableList(ObjectDataInput in)
Reads a list from the given
ObjectDataInput . |
static <K,V> Map<K,V> |
readNullableMap(ObjectDataInput in)
Reads a map written by
writeNullableMap(Map, ObjectDataOutput) . |
static PartitionIdSet |
readNullablePartitionIdSet(ObjectDataInput in) |
static <T> void |
writeCollection(Collection<T> items,
ObjectDataOutput out)
Writes a collection to an
ObjectDataOutput . |
static <T> void |
writeList(List<T> items,
ObjectDataOutput out)
Writes a list to an
ObjectDataOutput . |
static <K,V> void |
writeMap(Map<K,V> map,
ObjectDataOutput out) |
static <T> void |
writeNullableCollection(Collection<T> items,
ObjectDataOutput out)
Writes a collection to an
ObjectDataOutput . |
static <T> void |
writeNullableList(List<T> items,
ObjectDataOutput out)
Writes a list to an
ObjectDataOutput . |
static <K,V> void |
writeNullableMap(Map<K,V> map,
ObjectDataOutput out)
Writes a map to given
ObjectDataOutput . |
static void |
writeNullablePartitionIdSet(PartitionIdSet partitionIds,
ObjectDataOutput out)
Writes a nullable
PartitionIdSet to the given data output. |
public static void checkSerializable(Object object, String objectName)
object
implements Serializable
and is
correctly serializable by actually trying to serialize it. This will
reveal some non-serializable field early.object
- object to checkobjectName
- object description for the exceptionIllegalArgumentException
- if object
is not serializablepublic static int getPortableVersion(Portable portable, int defaultVersion)
public static ObjectDataOutputStream createObjectDataOutputStream(OutputStream out, InternalSerializationService ss)
public static ObjectDataInputStream createObjectDataInputStream(InputStream in, InternalSerializationService ss)
public static InputStream convertToInputStream(DataInput in, int offset)
public static <K,V> void writeNullableMap(Map<K,V> map, ObjectDataOutput out) throws IOException
ObjectDataOutput
.map
- the map to serialize, can be null
out
- the output to write the map toIOException
public static <K,V> void writeMap(@Nonnull Map<K,V> map, ObjectDataOutput out) throws IOException
IOException
public static <K,V> Map<K,V> readNullableMap(ObjectDataInput in) throws IOException
writeNullableMap(Map, ObjectDataOutput)
. The map itself
may be null
. No guarantee is provided about the type of Map returned or its suitability
to be used in a thread-safe manner.K
- type of key classV
- type of value classin
- the ObjectDataInput
input to read fromMap
containing the keys & values read from the input or null
if the original serialized map was null
IOException
- when an error occurs while reading from the input@Nonnull public static <K,V> Map<K,V> readMap(ObjectDataInput in) throws IOException
IOException
public static <T> void writeNullableCollection(Collection<T> items, ObjectDataOutput out) throws IOException
ObjectDataOutput
. The collection's size is written
to the data output, then each object in the collection is serialized.
The collection is allowed to be null.T
- type of itemsitems
- collection of items to be serializedout
- data output to write toIOException
- when an error occurs while writing to the outputpublic static <T> void writeNullableList(List<T> items, ObjectDataOutput out) throws IOException
ObjectDataOutput
. The list's size is written
to the data output, then each object in the list is serialized.
The list is allowed to be null.T
- type of itemsitems
- list of items to be serializedout
- data output to write toIOException
- when an error occurs while writing to the outputpublic static <T> void writeCollection(Collection<T> items, ObjectDataOutput out) throws IOException
ObjectDataOutput
. The collection's size is written
to the data output, then each object in the collection is serialized.T
- type of itemsitems
- collection of items to be serializedout
- data output to write toNullPointerException
- if items
or out
is null
IOException
- when an error occurs while writing to the outputpublic static <T> void writeList(List<T> items, ObjectDataOutput out) throws IOException
ObjectDataOutput
. The list's size is written
to the data output, then each object in the list is serialized.T
- type of itemsitems
- list of items to be serializedout
- data output to write toNullPointerException
- if items
or out
is null
IOException
- when an error occurs while writing to the outputpublic static void writeNullablePartitionIdSet(PartitionIdSet partitionIds, ObjectDataOutput out) throws IOException
PartitionIdSet
to the given data output.partitionIds
- out
- IOException
public static <T> Collection<T> readNullableCollection(ObjectDataInput in) throws IOException
ObjectDataInput
. It is expected that
the next int read from the data input is the collection's size, then that
many objects are read from the data input and returned as a collection.T
- type of itemsin
- data input to read fromIOException
- when an error occurs while reading from the inputpublic static <T> List<T> readNullableList(ObjectDataInput in) throws IOException
ObjectDataInput
. It is expected that
the next int read from the data input is the list's size, then that
many objects are read from the data input and returned as a list.T
- type of itemsin
- data input to read fromIOException
- when an error occurs while reading from the inputpublic static <T> Collection<T> readCollection(ObjectDataInput in) throws IOException
ObjectDataInput
. It is expected that
the next int read from the data input is the collection's size, then that
many objects are read from the data input and returned as a collection.T
- type of itemsin
- data input to read fromIOException
- when an error occurs while reading from the inputpublic static <T> List<T> readList(ObjectDataInput in) throws IOException
ObjectDataInput
. It is expected that
the next int read from the data input is the list's size, then that
many objects are read from the data input and returned as a list.T
- type of itemsin
- data input to read fromIOException
- when an error occurs while reading from the inputpublic static PartitionIdSet readNullablePartitionIdSet(ObjectDataInput in) throws IOException
IOException
Copyright © 2019 Hazelcast, Inc.. All rights reserved.