Java Utililty Methods Object Serialize

List of utility methods to do Object Serialize

Description

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

Method

voidserialize(final String path, final Object object)

Convenience method for serializing an object into a file.

final ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(path));
stream.writeObject(object);
stream.close();
voidserialize(final String pFilename, final T pObject)
serialize
try {
    final FileOutputStream myFileOutputStream = new FileOutputStream(pFilename);
    final ObjectOutputStream myObjectOutputStream = new ObjectOutputStream(myFileOutputStream);
    myObjectOutputStream.writeObject(pObject);
    myObjectOutputStream.close();
    myFileOutputStream.close();
} catch (IOException e) {
    System.err.println("### ERROR @ serialize / " + e);
...
byte[]serialize(java.io.Serializable obj)
Serializes an object
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
    new ObjectOutputStream(out).writeObject(obj);
    return out.toByteArray();
} catch (IOException ex) {
    throw new IllegalArgumentException(ex);
byte[]serialize(Object c, ScriptableObject scope)
serialize
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ScriptableOutputStream sos = new ScriptableOutputStream(baos, scope);
sos.addExcludedName("org.cpcc.interpreter.runtime.TransientState");
sos.excludeStandardObjectNames();
sos.writeObject(c);
sos.close();
return baos.toByteArray();
byte[]serialize(Object o)
serialize
ByteArrayOutputStream array = new ByteArrayOutputStream();
ObjectOutputStream out = null;
try {
    out = new ObjectOutputStream(array);
    out.writeObject(o);
    out.close();
} catch (ObjectStreamException e) {
    throw e;
...
byte[]serialize(Object o)
Serializes an object.
if (o == null)
    return new byte[0];
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
try {
    ObjectOutputStream stream = new ObjectOutputStream(byteStream);
    try {
        stream.writeObject(o);
    } finally {
...
byte[]serialize(Object obj)
Serialize an object.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
try {
    oos = new ObjectOutputStream(baos);
    oos.writeObject(obj);
    oos.flush();
    baos.flush();
    return baos.toByteArray();
...
byte[]serialize(Object obj)
serialize
ByteArrayOutputStream b = new ByteArrayOutputStream();
ObjectOutputStream o;
try {
    o = new ObjectOutputStream(b);
    o.writeObject(obj);
} catch (IOException e) {
    e.printStackTrace();
return b.toByteArray();
byte[]serialize(Object obj)
serialize
ByteArrayOutputStream baos = null;
ObjectOutputStream oos = null;
try {
    baos = new ByteArrayOutputStream();
    oos = new ObjectOutputStream(baos);
    oos.writeObject(obj);
    return baos.toByteArray();
} catch (RuntimeException re) {
...
byte[]serialize(Object obj)
Serialize an object to make an MD5 hash after call getMd5Digest Method.
byte[] byteArray = null;
ByteArrayOutputStream baos;
ObjectOutputStream out = null;
try {
    baos = new ByteArrayOutputStream();
    out = new ObjectOutputStream(baos);
    out.writeObject(obj);
    byteArray = baos.toByteArray();
...