Java Utililty Methods Object Serialize and Deserialize

List of utility methods to do Object Serialize and Deserialize

Description

The list of methods to do Object Serialize and Deserialize are organized into topic(s).

Method

Objectdeserialized(final byte[] data)
deserialized
if (data == null || data.length == 0)
    return null;
final ByteArrayInputStream bais = new ByteArrayInputStream(data);
ObjectInputStream ois = null;
try {
    ois = new ObjectInputStream(bais);
    return ois.readObject();
} catch (IOException e) {
...
ObjectdeserializeFromString(String obj)
deserialize From String
byte[] b = stringToBytes(obj);
ByteArrayInputStream bytes = new ByteArrayInputStream(b);
ObjectInputStream stream = new ObjectInputStream(bytes);
return stream.readObject();
voiddeserializeGZip(byte[] buf, T obj)
deserialize G Zip
try {
    deserializeGZipSafe(buf, obj);
} catch (Exception e) {
    throw new RuntimeException(e);
TdeserializeJdk(byte[] bytes)
Deserializes passed in bytes using provided class loader.
ObjectInputStream in = null;
try {
    in = new ObjectInputStream(new ByteArrayInputStream(bytes));
    return (T) in.readObject();
} finally {
    close(in);
ObjectdeSerializeObj(byte[] array)
de Serialize Obj
ByteArrayInputStream bis = new ByteArrayInputStream(array);
ObjectInputStream ois = null;
try {
    ois = new ObjectInputStream(bis);
    return ois.readObject();
} catch (Exception e) {
    throw new RuntimeException("deSerializeObj error", e);
SerializabledeSerializeObject(byte[] base64SerializedObject)
de Serialize Object
Serializable deserializedObject = null;
try {
    byte[] data = Base64.getDecoder().decode(base64SerializedObject);
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
    deserializedObject = (Serializable) ois.readObject();
    ois.close();
} catch (Exception ex) {
    ex.printStackTrace();
...
ObjectdeserializeObject(String dir)
deserialize Object
if (dir == null) {
    throw new NullPointerException();
FileInputStream fis = new FileInputStream(dir);
ObjectInputStream in;
if (dir.toLowerCase().endsWith(".gz")) {
    GZIPInputStream gzis = new GZIPInputStream(fis);
    in = new ObjectInputStream(gzis);
...
TdeSerializeObject(String str, Class cls)
Deserialize any object
T obj = null;
try {
    byte b[] = str.getBytes("ISO-8859-1");
    ByteArrayInputStream bi = new ByteArrayInputStream(b);
    ObjectInputStream si = new ObjectInputStream(bi);
    obj = cls.cast(si.readObject());
} catch (Exception e) {
    e.printStackTrace();
...
TdeserializeObjectFromByteArray(byte[] data)
Read the object from Base64 string.
if (data == null)
    return null;
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
Object o = ois.readObject();
ois.close();
return (T) o;
ObjectdeserializeObjectFromByteArray(byte[] theSerializedVersion)
Deserialize the object that was serialized into the given byte-array.
final ByteArrayInputStream bais = new ByteArrayInputStream(theSerializedVersion);
final ObjectInputStream input = new ObjectInputStream(bais);
return input.readObject();