Java Object Serialize serialize(Object obj, String fname, boolean gzipped)

Here you can find the source of serialize(Object obj, String fname, boolean gzipped)

Description

serialize

License

Open Source License

Declaration

public static void serialize(Object obj, String fname, boolean gzipped) 

Method Source Code

//package com.java2s;
// This software is released under the 2-clause BSD license.

import java.io.*;
import java.util.zip.*;

public class Main {
    public static void serialize(Object obj, String fname, boolean gzipped) {
        serialize(obj, new File(fname), gzipped);
    }/*from  ww  w  .  ja  va  2s . com*/

    public static void serialize(Object obj, String fname) {
        serialize(obj, new File(fname), false);
    }

    public static void serialize(Object obj, File f) {
        serialize(obj, f, false);
    }

    public static void serialize(Object obj, File f, boolean gzipped) {
        try {
            OutputStream os = new FileOutputStream(f);
            if (gzipped)
                os = new GZIPOutputStream(os);
            ObjectOutputStream oos = new ObjectOutputStream(os);
            oos.writeObject(obj);
            oos.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. serialize(Object obj)
  2. serialize(Object obj)
  3. serialize(Object obj, String file)
  4. serialize(Object obj, String fileName)
  5. serialize(Object obj, String fileName)
  6. serialize(Object objData, Class typeOfT)
  7. serialize(Object object)
  8. serialize(Object object)
  9. Serialize(Object object)