From dab47d3726bf12b646a2c6c39a6ff1dc1200edf5 Mon Sep 17 00:00:00 2001 From: Matt Rendina Date: Thu, 30 Nov 2017 10:35:35 -0500 Subject: Add new clone function --- vars/utils.groovy | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'vars') diff --git a/vars/utils.groovy b/vars/utils.groovy index fe76bca..793b24c 100644 --- a/vars/utils.groovy +++ b/vars/utils.groovy @@ -99,3 +99,22 @@ def concurrent(configs) { parallel(tasks) } } //end concurrent + + +/** + * This method makes a "deep clone" of any object it is given. + */ +public static Object deepClone(Object object) { + try { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(object); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bais); + return ois.readObject(); + } + catch (Exception e) { + e.printStackTrace(); + return null; + } +} -- cgit