Java Object Serialize serialize(Serializable obj)

Here you can find the source of serialize(Serializable obj)

Description

serialize

License

Apache License

Declaration

public static byte[] serialize(Serializable obj) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Main {

    public static byte[] serialize(Serializable obj) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
        ObjectOutputStream out = null;
        try {/*  w ww  . ja v a  2 s. c  om*/
            out = new ObjectOutputStream(baos);
            out.writeObject(obj);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException ex) {
                // ignore close exception
            }
        }
        return baos.toByteArray();
    }
}

Related

  1. serialize(Object value)
  2. serialize(S value)
  3. serialize(Serializable jobSpec)
  4. serialize(Serializable o)
  5. serialize(Serializable obj)
  6. serialize(Serializable obj)
  7. serialize(Serializable obj)
  8. serialize(Serializable obj, String fileName)
  9. serialize(Serializable obj, String path)