public static byte [ ] objectToByteArray ( final Object obj ) throws IOException { FastByteArrayOutputStream bos = new FastByteArrayOutputStream ( ) ; ObjectOutputStream oos = null ; try { oos = new ObjectOutputStream ( bos ) ; oos . writeObject ( obj ) ; } finally { StreamUtil . close ( oos ) ; } return bos . toByteArray ( ) ; }
Serialize an object to byte array .