public class SerializationUtils extends Object
| Constructor and Description |
|---|
SerializationUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends Serializable> |
deserialize(String serialized,
Class<T> clazz)
Deserialize a String obtained via
serialize(Serializable) into an object, using
BaseEncoding.base64(). |
static <T extends Serializable> |
deserialize(String serialized,
Class<T> clazz,
com.google.common.io.BaseEncoding enc)
Deserialize a String obtained via
serialize(Serializable) into an object, using the
given BaseEncoding, which must be the same BaseEncoding used to serialize the object. |
static <T extends Serializable> |
deserializeFromBytes(byte[] serialized,
Class<T> clazz)
Deserialize a String obtained via
serializeIntoBytes(Serializable) into an object. |
static <T extends State> |
deserializeState(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path jobStateFilePath,
T state)
Deserialize/read a
State instance from a file. |
static <T extends State> |
deserializeStateFromInputStream(InputStream is,
T state)
Deserialize/read a
State instance from a file. |
static <T extends Serializable> |
serialize(T obj)
Serialize an object into a String.
|
static <T extends Serializable> |
serialize(T obj,
com.google.common.io.BaseEncoding enc)
Serialize an object into a String.
|
static <T extends Serializable> |
serializeIntoBytes(T obj)
Serialize an object into a byte array.
|
static <T extends State> |
serializeState(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path jobStateFilePath,
T state)
Serialize a
State instance to a file. |
static <T extends State> |
serializeState(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path jobStateFilePath,
T state,
short replication)
Serialize a
State instance to a file. |
public static <T extends Serializable> String serialize(T obj) throws IOException
BaseEncoding.base64().obj - A Serializable objectIOException - if it fails to serialize the objectpublic static <T extends Serializable> String serialize(T obj, com.google.common.io.BaseEncoding enc) throws IOException
BaseEncoding.obj - A Serializable objectenc - The BaseEncoding used to encode a byte array.IOException - if it fails to serialize the objectpublic static <T extends Serializable> byte[] serializeIntoBytes(T obj) throws IOException
obj - A Serializable objectIOException - if it fails to serialize the objectpublic static <T extends Serializable> T deserialize(String serialized, Class<T> clazz) throws IOException
serialize(Serializable) into an object, using
BaseEncoding.base64().serialized - The serialized Stringclazz - The class the deserialized object should be cast to.IOException - if it fails to deserialize the objectpublic static <T extends Serializable> T deserialize(String serialized, Class<T> clazz, com.google.common.io.BaseEncoding enc) throws IOException
serialize(Serializable) into an object, using the
given BaseEncoding, which must be the same BaseEncoding used to serialize the object.serialized - The serialized Stringclazz - The class the deserialized object should be cast to.enc - The BaseEncoding used to decode the String.IOException - if it fails to deserialize the objectpublic static <T extends Serializable> T deserializeFromBytes(byte[] serialized, Class<T> clazz) throws IOException
serializeIntoBytes(Serializable) into an object.serialized - The serialized bytesclazz - The class the deserialized object should be cast to.IOException - if it fails to deserialize the objectpublic static <T extends State> void serializeState(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path jobStateFilePath, T state) throws IOException
State instance to a file.T - the State object typefs - the FileSystem instance for creating the filejobStateFilePath - the path to the filestate - the State to serializeIOException - if it fails to serialize the State instancepublic static <T extends State> void serializeState(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path jobStateFilePath, T state, short replication) throws IOException
State instance to a file.T - the State object typefs - the FileSystem instance for creating the filejobStateFilePath - the path to the filestate - the State to serializereplication - replication of the serialized file.IOException - if it fails to serialize the State instancepublic static <T extends State> void deserializeState(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path jobStateFilePath, T state) throws IOException
State instance from a file.T - the State object typefs - the FileSystem instance for opening the filejobStateFilePath - the path to the filestate - an empty State instance to deserialize intoIOException - if it fails to deserialize the State instancepublic static <T extends State> void deserializeStateFromInputStream(InputStream is, T state) throws IOException
State instance from a file.T - the State object typeis - InputStream containing the state.state - an empty State instance to deserialize intoIOException - if it fails to deserialize the State instance