Java Utililty Methods Object Save

List of utility methods to do Object Save

Description

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

Method

byte[]writeObject(Object i)
Returns the byte value of i in a new byte array.
byte[] retVal = null;
try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream dos = new ObjectOutputStream(bos);
    dos.writeObject(i);
    dos.close();
    dos.flush();
    retVal = bos.toByteArray();
...
voidwriteObject(Object o, File f)
write Object
try {
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
    oos.writeObject(o);
    oos.close();
} catch (FileNotFoundException e) {
    System.err.println("Cannot find " + f);
    e.printStackTrace();
} catch (IOException e) {
...
voidwriteObject(Object o, File path)
write Object
try {
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(path));
    try {
        out.writeObject(o);
    } finally {
        out.close();
} catch (Exception e) {
...
voidwriteObject(Object o, ObjectOutput dos)
write Object
dos.writeObject(o);
voidwriteObject(Object obj, File path)
write Object
ObjectOutputStream out = null;
try {
    out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(path)));
    out.writeObject(obj);
    out.close();
} catch (IOException e) {
    System.err.println("Failed to write filename " + path);
} finally {
...
voidwriteObject(Object obj, ObjectOutput out)
write Object
if (obj == null) {
    out.writeObject(NULL);
} else {
    out.writeObject(NOTNULL);
    out.writeObject(obj);
byte[]writeObject(Object object)
Serialize an Object to a ByteArray
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(object);
out.close();
return buffer.toByteArray();
voidwriteObject(Object object, File destinationFile)
Writes an object to the destination file.
FileOutputStream fos = new FileOutputStream(destinationFile.getAbsoluteFile());
try {
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    try {
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        try {
            oos.writeObject(object);
        } finally {
...
voidwriteObject(Object object, String path)
write Object
FileOutputStream fileOut = null;
BufferedOutputStream bufferedOut = null;
ObjectOutputStream objectOut = null;
try {
    fileOut = new FileOutputStream(path);
    bufferedOut = new BufferedOutputStream(fileOut);
    objectOut = new ObjectOutputStream(bufferedOut);
    objectOut.writeObject(object);
...
booleanwriteObject(Object p_object, File p_outFile)
Writes an object to a file using object serialization.
try {
    FileOutputStream fStream = new FileOutputStream(p_outFile);
    ObjectOutputStream oObject = new ObjectOutputStream(fStream);
    oObject.writeObject(p_object);
    oObject.close();
    fStream.close();
    return true;
} catch (IOException e) {
...