List of utility methods to do Object Deep Copy
void | deepCopy(File fromDir, File toDir) Copy the contents of fromDir into toDir (if the latter is missing it will be created) if (!fromDir.isDirectory() || !fromDir.exists()) throw new IllegalArgumentException( "Invalid source directory " + "(it's either not a directory, or does not exist"); if (toDir.exists() && toDir.isFile()) throw new IllegalArgumentException( "Invalid destination directory, " + "it happens to be a file instead"); if (!toDir.exists()) if (!toDir.mkdir()) ... |
V | deepCopy(final Class deep Copy if (c == null || s == null) throw new NullPointerException(); final ByteArrayOutputStream bs = new ByteArrayOutputStream(); new ObjectOutputStream(bs).writeObject(s); final ByteArrayInputStream bi = new ByteArrayInputStream(bs.toByteArray()); final V v = c.cast(new ObjectInputStream(bi).readObject()); bs.close(); bi.close(); ... |
Object | deepCopy(final Object oldObj) deep Copy ObjectOutputStream oos = null; ObjectInputStream ois = null; try { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(oldObj); oos.flush(); final ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); ... |
List | deepCopy(List deep Copy ByteArrayOutputStream byteOut = null; ObjectOutputStream out = null; try { byteOut = new ByteArrayOutputStream(); out = new ObjectOutputStream(byteOut); out.writeObject(src); ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); ... |
List | deepCopy(List deep Copy ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(src); ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); ObjectInputStream in = new ObjectInputStream(byteIn); @SuppressWarnings("unchecked") List<T> dest = (List<T>) in.readObject(); return dest; ... |
Object | deepCopy(Object o) deep Copy byte[] bytes = serializeToByteArray(o); return deserializeFromByteArray(bytes); |
Object[] | deepCopy(Object obj1, Object obj2) Method obtains deep copies for provided instances. Object obj[] = { null, null }; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(obj2); out.writeObject(obj1); out.flush(); out.close(); ... |
Object | deepCopy(Object oldObj) deep Copy ObjectOutputStream oos = null; ObjectInputStream ois = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(oldObj); oos.flush(); ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); ... |
Object | deepCopy(Object orig) NOTE: when updating the cloned object, the cloned associated collection in particular, Before persist using Hibernate, need to create a new collection using the cloned collection otherwise Hibernate complains. Object obj = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(orig); out.flush(); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); ... |
Object | deepCopy(Object original) deep Copy ObjectInputStream ois; ObjectOutputStream oos; ByteArrayInputStream bais; ByteArrayOutputStream baos; byte[] data; Object copy; baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); ... |