ObjectOutputStream out=new ObjectOutputStream(out_stream); out.writeObject(obj);
if(obj instanceof Streamable) { DataOutputStream out=new DataOutputStream(out_stream); writeGenericStreamable((Streamable)obj, out); out.close(); } else { ObjectOutputStream out=new ObjectOutputStream(out_stream); out.writeObject(obj); out.close(); }
    public static byte[] objectToByteBuffer(Object obj) throws Exception {        byte[] result=null;        synchronized(out_stream) {            out_stream.reset();            ObjectOutputStream out=new ObjectOutputStream(out_stream);            out.writeObject(obj);            result=out_stream.toByteArray();            out.close();        }        return result;    }