Here you can find the source of getBytes(Object o)
static public final byte[] getBytes(Object o) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { static public final byte[] getBytes(Object o) throws IOException { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(5000); ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(byteStream)); os.flush();//from w w w .j a v a 2 s . c o m os.writeObject(o); os.flush(); return byteStream.toByteArray(); } }