aboutsummaryrefslogtreecommitdiff
path: root/vars/utils.groovy
diff options
context:
space:
mode:
Diffstat (limited to 'vars/utils.groovy')
-rw-r--r--vars/utils.groovy19
1 files changed, 19 insertions, 0 deletions
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;
+ }
+}