Last active
December 8, 2015 18:54
-
-
Save ddmills/5a892c358e511b924c63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.io.ObjectInputStream; | |
import java.io.ObjectOutputStream; | |
public class DeepCopy { | |
private DeepCopy() { } | |
public static Object copy(Object orig) { | |
Object obj = null; | |
try { | |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); | |
ObjectOutputStream out = new ObjectOutputStream(bos); | |
out.writeObject(obj); | |
out.flush(); | |
out.close(); | |
ObjectInputStream in = new ObjectInputStream( | |
new ByteArrayInputStream(bos.toByteArray())); | |
obj = in.readObject(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
} | |
return obj; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment