Java Object to Byte Array serializeToBytes(Serializable object)

Here you can find the source of serializeToBytes(Serializable object)

Description

serialize To Bytes

License

Open Source License

Declaration

public static byte[] serializeToBytes(Serializable object) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static byte[] serializeToBytes(Serializable object) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutput out = null;/*from  ww w  .ja v  a2 s.  c o  m*/
        try {
            out = new ObjectOutputStream(bos);
            out.writeObject(object);
            return bos.toByteArray();
        } finally {
            try {
                if (out != null) {
                    out.close();
                }
            } catch (IOException ex) {
                // ignore close exception
            }
            try {
                bos.close();
            } catch (IOException ex) {
                // ignore close exception
            }
        }
    }
}

Related

  1. serializeToByteArray(Object obj)
  2. serializeToByteArray(Object object)
  3. serializeToByteArray(Serializable object)
  4. serializeToByteArray(Serializable value)
  5. serializeToByteArrayNoHeader(Serializable o)
  6. serializeToBytes(Serializable object)
  7. serializeToBytes(T input)