Java Utililty Methods ObjectOutputStream Write

List of utility methods to do ObjectOutputStream Write

Description

The list of methods to do ObjectOutputStream Write are organized into topic(s).

Method

voidsaveDate(String path, Object obj)
save Date
File file = new File(DEF_DATA_DIR + File.separator + path);
try {
    ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
    out.writeObject(obj);
    out.flush();
    out.close();
} catch (IOException e) {
    e.printStackTrace();
...
voidsaveFile(Object o, File file)
save File
try {
    FileOutputStream ostream = new FileOutputStream(file);
    BufferedOutputStream bostream = new BufferedOutputStream(ostream);
    ObjectOutputStream p = new ObjectOutputStream(bostream);
    p.writeObject(o);
    p.flush();
    ostream.close();
} catch (IOException e) {
...
booleansaveFile(Object o, String filename)
save File
FileOutputStream fos = null;
ObjectOutputStream oos = null;
boolean success = false;
try {
    fos = new FileOutputStream(DATA_DIR + filename);
    oos = new ObjectOutputStream(fos);
    oos.writeObject(o);
    success = true;
...
booleansaveGZipObject(Object toSave, File file)
save G Zip Object
FileOutputStream fos = null;
GZIPOutputStream gos = null;
ObjectOutputStream oos = null;
try {
    fos = new FileOutputStream(file);
    gos = new GZIPOutputStream(fos);
    oos = new ObjectOutputStream(gos);
    oos.writeObject(toSave);
...
booleansaveIndex(String path, Serializable obj)
save Index
path += "." + EXTENSION;
boolean res = true;
File file = new File(path);
if (file.exists() && file.isFile()) {
    if (file.delete()) {
        System.out.println("deleted ori index");
FileOutputStream fos = null;
try {
    fos = new FileOutputStream(path);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(obj);
    oos.close();
    if (OS.indexOf("win") >= 0) {
        Runtime.getRuntime().exec("attrib +H " + path);
} catch (IOException e) {
    e.printStackTrace();
    res = false;
} finally {
    try {
        if (fos != null)
            fos.close();
    } catch (IOException e) {
        e.printStackTrace();
return res;
voidsaveInSerFile(String filename, T object)
save In Ser File
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(new File(filename)));
try {
    output.writeObject(object);
} finally {
    output.close();
voidsaveObject(File file, Object o, boolean overwrite)
save Object
ObjectOutputStream oos = null;
if (file.exists() && !overwrite) {
    throw new IOException("file exists: " + file.getCanonicalPath());
try {
    oos = new ObjectOutputStream(new FileOutputStream(file));
    oos.writeObject(o);
} finally {
...
voidsaveObject(File file, Serializable obj)
save Object
objToStream(new BufferedOutputStream(new FileOutputStream(file)), obj);
voidsaveObject(Object o, File f)
save Object
try {
    FileOutputStream fout = new FileOutputStream(f);
    ObjectOutputStream oos = new ObjectOutputStream(fout);
    oos.writeObject(o);
    oos.close();
} catch (Exception e) {
    throw new RuntimeException(e);
voidsaveObject(Object obj, File file)
save Object
try {
    ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(file));
    stream.writeObject(obj);
    stream.close();
} catch (IOException e) {
    e.printStackTrace();