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

voidwriteObjectToFile(File file, Object o)
write Object To File
ObjectOutputStream oop = new ObjectOutputStream(new FileOutputStream(file));
oop.writeObject(o);
oop.close();
voidwriteObjectToFile(File file, Object obj)
write Object To File
FileOutputStream fOS = new FileOutputStream(file);
ObjectOutputStream oOS = new ObjectOutputStream(fOS);
oOS.writeObject(obj);
oOS.flush();
oOS.close();
voidwriteObjectToFile(final Object o, final File dir)
Utility function to serialize an object to a file in current checkpoint dir.
writeObjectToFile(o, null, dir);
FilewriteObjectToFile(Object o, File file, boolean append)
Write an object to a specified File.
ObjectOutputStream oos = new ObjectOutputStream(
        new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file, append))));
oos.writeObject(o);
oos.close();
return file;
FilewriteObjectToFile(Object o, String filename)
Write object to a file with the specified name.
return writeObjectToFile(o, new File(filename));
FilewriteObjectToFile(Object o, String fileName)
Serialize java object to a file.
File outFile = new File(fileName);
OutputStream outputStream = new FileOutputStream(outFile);
if (fileName.endsWith(".gz")) {
    outputStream = new GZIPOutputStream(outputStream);
outputStream = new BufferedOutputStream(outputStream);
ObjectOutputStream oos = new ObjectOutputStream(outputStream);
oos.writeObject(o);
...
booleanwriteObjectToFile(Object obj, File f)
Writes a generic object to a file
try {
    FileOutputStream fout = new FileOutputStream(f);
    ObjectOutputStream oos = new ObjectOutputStream(fout);
    oos.writeObject(obj);
    oos.close();
} catch (Exception e) {
    System.out.println("Error writing Object to file: " + e.getMessage());
    return false;
...
booleanwriteObjectToFile(Object obj, String fileName)
Writes an Object to a file.
return writeObjectToFile(obj, new File(fileName));
voidwriteObjectToFile(Object obj, String path)
write Object To File
writeObjectToFile(obj, new File(path));
voidwriteObjectToFile(Object object, File file)
write Object To File
if (!file.exists()) {
    file.createNewFile();
FileWriter writer = new FileWriter(file);
writer.write(gson.toJson(object));
writer.close();