Here you can find the source of getBytes(Object obj)
private static byte[] getBytes(Object obj) throws java.io.IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; public class Main { private static byte[] getBytes(Object obj) throws java.io.IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(obj);/*from w w w . j a va2s . co m*/ oos.flush(); oos.close(); bos.close(); byte[] data = bos.toByteArray(); return data; } }