Java Object Serialize serialize(T t, String path)

Here you can find the source of serialize(T t, String path)

Description

Serialize object.

License

Mozilla Public License

Parameter

Parameter Description
T type of object
t object
path path of the file

Exception

Parameter Description
IOException when IO error

Declaration

public static <T> void serialize(T t, String path) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Mozilla Public License 

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;
import java.io.OutputStream;

import java.util.zip.GZIPOutputStream;

public class Main {
    /**/*from w  w w  .  ja v a  2  s .c om*/
     * Serialize object.
     *
     * @param <T> type of object
     * @param t object
     * @param path path of the file
     * @throws IOException when IO error
     */
    public static <T> void serialize(T t, String path) throws IOException {
        serialize(t, new FileOutputStream(path));
    }

    /**
     * Serialize object.
     *
     * @param <T> type of object
     * @param t object
     * @param out output stream
     * @throws IOException when IO error
     */
    public static <T> void serialize(T t, OutputStream out) throws IOException {
        try (ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(out))) {
            oos.writeObject(t);
        }
    }
}

Related

  1. serialize(T object)
  2. serialize(T object)
  3. serialize(T object)
  4. serialize(T t)
  5. serialize(T t, String filename)
  6. serialize(T toSerialize)
  7. serialized(final Object item)
  8. serialized(Object o)
  9. serialized(Serializable original)