public static byte[] objectToByteBuffer(Object obj) throws Exception {
  byte[] result=null;
synchronized (outStream) {
    outStream.reset();
    ObjectOutputStream out=new ObjectOutputStream(outStream);
    out.writeObject(obj);
    out.flush();
    result=outStream.toByteArray();
    out.close();
  }
  return result;
}

public static byte [ ] objectToByteBuffer ( Object obj ) throws Exception { byte [ ] result = null ; synchronized ( outStream ) { outStream . reset ( ) ; ObjectOutputStream out = new ObjectOutputStream ( outStream ) ; out . writeObject ( obj ) ; out . flush ( ) ; result = outStream . toByteArray ( ) ; out . close ( ) ; } return result ; }
serializes an object into a byte buffer . the object has to implement interface serializable or externalizable .
