Here you can find the source of getInputStream(final Serializable obj)
public static ByteArrayInputStream getInputStream(final Serializable obj) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { public static ByteArrayInputStream getInputStream(final Serializable obj) throws Exception { byte[] bin = getBytes(obj); return new ByteArrayInputStream(bin); }/*from w ww . j av a 2 s.co m*/ public static byte[] getBytes(final Serializable obj) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(bos); try { oos.writeObject(obj); } finally { oos.close(); } } finally { bos.close(); } return bos.toByteArray(); } }