1853 |
|
} |
1854 |
|
|
1855 |
|
/** |
1856 |
+ |
* A version of serialClone that leaves error handling (for |
1857 |
+ |
* e.g. NotSerializableException) up to the caller. |
1858 |
+ |
*/ |
1859 |
+ |
@SuppressWarnings("unchecked") |
1860 |
+ |
<T> T serialClonePossiblyFailing(T o) |
1861 |
+ |
throws ReflectiveOperationException, java.io.IOException { |
1862 |
+ |
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1863 |
+ |
ObjectOutputStream oos = new ObjectOutputStream(bos); |
1864 |
+ |
oos.writeObject(o); |
1865 |
+ |
oos.flush(); |
1866 |
+ |
oos.close(); |
1867 |
+ |
ObjectInputStream ois = new ObjectInputStream |
1868 |
+ |
(new ByteArrayInputStream(bos.toByteArray())); |
1869 |
+ |
T clone = (T) ois.readObject(); |
1870 |
+ |
if (o == clone) assertImmutable(o); |
1871 |
+ |
assertSame(o.getClass(), clone.getClass()); |
1872 |
+ |
return clone; |
1873 |
+ |
} |
1874 |
+ |
|
1875 |
+ |
/** |
1876 |
|
* If o implements Cloneable and has a public clone method, |
1877 |
|
* returns a clone of o, else null. |
1878 |
|
*/ |