Here you can find the source of encode(T obj)
public static final <T extends Serializable> byte[] encode(T obj)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { public static final <T extends Serializable> byte[] encode(T obj) { byte[] bytes = null; try {//from w w w.j a v a 2s . co m ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bout); out.writeObject(obj); bytes = bout.toByteArray(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("Error serializing object" + obj + " => " + e); } return bytes; } }