Here you can find the source of getBytesFromObject(Serializable data)
public static byte[] getBytesFromObject(Serializable data) throws IOException
//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[] getBytesFromObject(Serializable data) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); ObjectOutputStream objos = new ObjectOutputStream(os); objos.writeObject(data);//from w ww . j a va 2 s. c o m objos.flush(); byte[] result = os.toByteArray(); os.close(); objos.close(); return result; } }