Here you can find the source of toData(Serializable o)
public static byte[] toData(Serializable o) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /** Write the object to a data. */ public static byte[] toData(Serializable o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o);/*from w w w . ja v a 2 s. c o m*/ oos.close(); return baos.toByteArray(); } }