Here you can find the source of serializeObject(Externalizable object)
public static byte[] serializeObject(Externalizable object) throws Exception
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.io.ByteArrayOutputStream; import java.io.Externalizable; import java.io.ObjectOutputStream; public class Main { public static byte[] serializeObject(Externalizable object) throws Exception { ByteArrayOutputStream baos; ObjectOutputStream oos = null; byte[] res = null; try {//from ww w . j av a 2 s . com baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); object.writeExternal(oos); oos.flush(); res = baos.toByteArray(); } catch (Exception ex) { System.out.println("Error serializing object" + ex); throw ex; } finally { try { if (oos != null) oos.close(); } catch (Exception e) { e.printStackTrace(); } } return res; } }