public static byte[] objectToBytes(Object obj) throws java.io.IOException {
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  ObjectOutputStream oos=new ObjectOutputStream(bos);
  oos.writeObject(obj);
  oos.flush();
  oos.close();
  bos.close();
  byte[] data=bos.toByteArray();
  return data;
}

public static byte [ ] objectToBytes ( Object obj ) throws java . io . IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos = new ObjectOutputStream ( bos ) ; oos . writeObject ( obj ) ; oos . flush ( ) ; oos . close ( ) ; bos . close ( ) ; byte [ ] data = bos . toByteArray ( ) ; return data ; }
convert an object into byte array .
