Here you can find the source of serialize(Object state)
public static byte[] serialize(Object state)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static byte[] serialize(Object state) { ObjectOutputStream oos = null; try {//w w w .jav a 2s . co m ByteArrayOutputStream bos = new ByteArrayOutputStream(512); oos = new ObjectOutputStream(bos); oos.writeObject(state); oos.flush(); return bos.toByteArray(); } catch (IOException e) { throw new IllegalArgumentException(e); } finally { if (oos != null) { try { oos.close(); } catch (IOException e) { // eat it } } } } }