List of utility methods to do Object Deep Copy
Object | deepCopy(Object toCopy) Creates a deep copy of an object using serialization. ByteArrayOutputStream ostream = new ByteArrayOutputStream(); byte[] storedObjectArray; try (ObjectOutputStream p = new ObjectOutputStream(new BufferedOutputStream(ostream))) { p.writeObject(toCopy); p.flush(); } catch (IOException e) { throw new RuntimeException(e); ... |
Serializable | deepCopy(Serializable source) Utility for making deep copies (vs. Object copy = null; try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(source); out.flush(); out.close(); ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); ... |
T | deepCopy(T item) deep Copy if (item == null) return null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(item); oos.flush(); byte[] rawData = baos.toByteArray(); ... |
T | deepCopy(T originalObject) Copies a file into another one Object clone = null; ObjectOutputStream oos = null; ObjectInputStream ois = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(originalObject); oos.flush(); ... |
T | deepCopy(T src) deep Copy if (!(src instanceof Serializable)) { throw new CloneNotSupportedException("src is not Serializable class"); ByteArrayOutputStream bout = null; ObjectOutputStream oout = null; ByteArrayInputStream bin = null; ObjectInputStream oin = null; try { ... |
T | deepCopy(T t) deep Copy ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(t); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bis); return (T) ois.readObject(); |
Serializable | deeplyCopy(Serializable serializable) deeply Copy try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(serializable); objectOutputStream.close(); byteArrayOutputStream.close(); byte[] bytes = byteArrayOutputStream.toByteArray(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); ... |