Java Object Serialize serializeObject(Object object)

Here you can find the source of serializeObject(Object object)

Description

serialize Object

License

Apache License

Declaration

public static byte[] serializeObject(Object object) 

Method Source Code


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

import java.io.*;

public class Main {

    public static byte[] serializeObject(Object object) {
        ObjectOutputStream objectOutputStream = null;
        ByteArrayOutputStream byteArrayOutputStream = null;

        try {// w  ww  .j av  a2  s .c  o m
            byteArrayOutputStream = new ByteArrayOutputStream();
            objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);

            objectOutputStream.writeObject(object);

            return byteArrayOutputStream.toByteArray();
        } catch (Exception e) {
            return null;
        } finally {
            try {
                if (null != byteArrayOutputStream) {
                    byteArrayOutputStream.close();
                }

                if (null != objectOutputStream) {
                    objectOutputStream.close();
                }
            } catch (Exception e) {

            }
        }
    }
}

Related

  1. serializeObject(Object o)
  2. serializeObject(Object obj)
  3. serializeObject(Object obj, String destPath)
  4. serializeObject(Object obj, String dir)
  5. serializeObject(Object object)
  6. serializeObject(Object object, File f)
  7. serializeObject(Object serializedObject)