/** Create a deep copy/clone of any serializable object */ public static <T> T deepCopy(Serializable object) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { serialize(object, outputStream); return deserialize(new ByteArrayInputStream(outputStream.toByteArray())); } catch (Throwable e) { throw new RuntimeException("Failed in performing a deep copy", e); } } }
public static void serializeToFile(Serializable object, String fileName) throws IOException { OutputStream outputStream = FileUtils.getOutputStream(fileName); serialize(object, outputStream); }