public final class SerializationUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
deserialize(@NonNull byte[] objectData)
Deserializes a single
Object from an array of bytes. |
static <T> T |
deserialize(@NonNull InputStream inputStream)
Deserializes an
Object from the specified stream. |
static byte[] |
serialize(Serializable obj)
Serializes an
Object to a byte array for storage/serialization. |
static void |
serialize(Serializable object,
@NonNull OutputStream outputStream)
Serializes an
Object to the specified stream. |
public static void serialize(Serializable object, @NonNull @NonNull OutputStream outputStream)
Object to the specified stream.
The stream will be closed once the object is written. This avoids the need for a finally clause, and maybe also exception handling, in the application code.
The stream passed in is not buffered internally within this method. This is the responsibility of your application if desired.
object - the object to serialize to bytes, may be nulloutputStream - the stream to write to, must not be nullNullPointerException - if outputStream is nullSerializationException - (runtime) if the serialization failspublic static byte[] serialize(Serializable obj)
Object to a byte array for storage/serialization.obj - the object to serialize to bytesSerializationException - (runtime) if the serialization failspublic static <T> T deserialize(@NonNull
@NonNull InputStream inputStream)
Object from the specified stream.
The stream will be closed once the object is written. This avoids the need for a finally clause, and maybe also exception handling, in the application code.
The stream passed in is not buffered internally within this method. This is the responsibility of your application if desired.
If the call site incorrectly types the return value, a ClassCastException is thrown from the call site.
Without Generics in this declaration, the call site must type cast and can cause the same ClassCastException. Note
that in both cases, the ClassCastException is in the call site, not in this method.
T - the object type to be deserializedinputStream - the serialized object input stream, must not be nullNullPointerException - if inputStream is nullSerializationException - (runtime) if the serialization failspublic static <T> T deserialize(@NonNull
@NonNull byte[] objectData)
Object from an array of bytes.
If the call site incorrectly types the return value, a ClassCastException is thrown from the call site.
Without Generics in this declaration, the call site must type cast and can cause the same ClassCastException. Note
that in both cases, the ClassCastException is in the call site, not in this method.
T - the object type to be deserializedobjectData - the serialized object, must not be nullNullPointerException - if objectData is nullSerializationException - (runtime) if the serialization failsCopyright © 2019–2020 Appulse. All rights reserved.