diff options
| author | Matt Rendina <mrendina@stsci.edu> | 2017-11-30 10:35:35 -0500 |
|---|---|---|
| committer | Matt Rendina <mrendina@stsci.edu> | 2017-11-30 10:35:35 -0500 |
| commit | dab47d3726bf12b646a2c6c39a6ff1dc1200edf5 (patch) | |
| tree | 80a011449ff60260514d7fe3b7d70b786d2f0c0b /vars/utils.groovy | |
| parent | 565ba56f50da4cd090f741c6b4b09948abb8a7af (diff) | |
| download | jscu_refactor-dab47d3726bf12b646a2c6c39a6ff1dc1200edf5.tar.gz | |
Add new clone function
Diffstat (limited to 'vars/utils.groovy')
| -rw-r--r-- | vars/utils.groovy | 19 |
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; + } +} |
