1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.util;
18
19 import java.io.ByteArrayInputStream;
20 import java.io.ByteArrayOutputStream;
21 import java.io.ObjectInputStream;
22 import java.io.ObjectOutputStream;
23
24 /***
25 * Utility for object cloning
26 *
27 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
28 */
29 public class CloneUtil
30 {
31 /***
32 * Provides a deep clone serializing/de-serializng <code>objToClone</code>
33 *
34 * @param objToClone The object to be cloned
35 * @return The cloned object
36 */
37 public static final Object deepClone(Object objToClone)
38 {
39 try
40 {
41 ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(100);
42 ObjectOutputStream objectoutputstream = new ObjectOutputStream(bytearrayoutputstream);
43 objectoutputstream.writeObject(objToClone);
44 byte abyte0[] = bytearrayoutputstream.toByteArray();
45 objectoutputstream.close();
46 ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(abyte0);
47 ObjectInputStream objectinputstream = new ObjectInputStream(bytearrayinputstream);
48 Object clone = objectinputstream.readObject();
49 objectinputstream.close();
50 return clone;
51 }
52 catch (Exception exception)
53 {
54
55 }
56 return null;
57 }
58
59 }