Here you can find the source of serializeSafe(T obj)
public static <T extends Externalizable> byte[] serializeSafe(T obj) throws IOException, ClassNotFoundException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static <T extends Externalizable> byte[] serializeSafe(T obj) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = null; try {//from w ww. j a v a 2s .c o m baos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(baos); obj.writeExternal(out); out.flush(); } finally { if (out != null) { try { out.close(); } catch (Exception e) { /* NOP */ } } } baos.flush(); return baos.toByteArray(); } finally { if (baos != null) { try { baos.close(); } catch (Exception e) { /* NOP */ } } } } }