256 |
break; |
break; |
257 |
} |
} |
258 |
|
|
259 |
|
Class clazz = obj.getClass(); |
260 |
|
ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz); |
261 |
|
if (osc == null) |
262 |
|
throw new NotSerializableException(clazz.getName()); |
263 |
|
|
264 |
if ((replacementEnabled || obj instanceof Serializable) |
if ((replacementEnabled || obj instanceof Serializable) |
265 |
&& ! replaceDone) |
&& ! replaceDone) |
266 |
{ |
{ |
268 |
|
|
269 |
if (obj instanceof Serializable) |
if (obj instanceof Serializable) |
270 |
{ |
{ |
|
Method m = null; |
|
271 |
try |
try |
272 |
{ |
{ |
273 |
Class classArgs[] = {}; |
Method m = osc.writeReplaceMethod; |
274 |
m = getMethod(obj.getClass(), "writeReplace", |
if (m != null) |
275 |
classArgs); |
obj = m.invoke(obj, new Object[0]); |
|
// m can't be null by definition since an |
|
|
// exception would have been thrown so a check |
|
|
// for null is not needed. |
|
|
obj = m.invoke(obj, new Object[] {}); |
|
|
} |
|
|
catch (NoSuchMethodException ignore) |
|
|
{ |
|
276 |
} |
} |
277 |
catch (IllegalAccessException ignore) |
catch (IllegalAccessException ignore) |
278 |
{ |
{ |
297 |
break; |
break; |
298 |
} |
} |
299 |
|
|
|
Class clazz = obj.getClass(); |
|
|
ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz); |
|
|
if (osc == null) |
|
|
throw new NotSerializableException(clazz.getName()); |
|
|
|
|
300 |
if (clazz.isArray ()) |
if (clazz.isArray ()) |
301 |
{ |
{ |
302 |
realOutput.writeByte(TC_ARRAY); |
realOutput.writeByte(TC_ARRAY); |
1259 |
private void callWriteMethod(Object obj, ObjectStreamClass osc) |
private void callWriteMethod(Object obj, ObjectStreamClass osc) |
1260 |
throws IOException |
throws IOException |
1261 |
{ |
{ |
|
Class klass = osc.forClass(); |
|
1262 |
currentPutField = null; |
currentPutField = null; |
1263 |
try |
try |
1264 |
{ |
{ |
1265 |
Class classArgs[] = {ObjectOutputStream.class}; |
Object args[] = {this}; |
1266 |
Method m = getMethod(klass, "writeObject", classArgs); |
osc.writeObjectMethod.invoke(obj, args); |
|
Object args[] = {this}; |
|
|
m.invoke(obj, args); |
|
|
} |
|
|
catch (NoSuchMethodException nsme) |
|
|
{ |
|
|
// Nothing. |
|
1267 |
} |
} |
1268 |
catch (InvocationTargetException x) |
catch (InvocationTargetException x) |
1269 |
{ |
{ |
1274 |
if (exception instanceof IOException) |
if (exception instanceof IOException) |
1275 |
throw (IOException) exception; |
throw (IOException) exception; |
1276 |
|
|
1277 |
IOException ioe |
IOException ioe |
1278 |
= new IOException("Exception thrown from writeObject() on " + |
= new IOException("Exception thrown from writeObject() on " + |
1279 |
klass + ": " + exception.getClass().getName()); |
osc.forClass().getName() + ": " + |
1280 |
|
exception.getClass().getName()); |
1281 |
ioe.initCause(exception); |
ioe.initCause(exception); |
1282 |
throw ioe; |
throw ioe; |
1283 |
} |
} |
1285 |
{ |
{ |
1286 |
IOException ioe |
IOException ioe |
1287 |
= new IOException("Failure invoking writeObject() on " + |
= new IOException("Failure invoking writeObject() on " + |
1288 |
klass + ": " + x.getClass().getName()); |
osc.forClass().getName() + ": " + |
1289 |
|
x.getClass().getName()); |
1290 |
ioe.initCause(x); |
ioe.initCause(x); |
1291 |
throw ioe; |
throw ioe; |
1292 |
} |
} |
1528 |
} |
} |
1529 |
} |
} |
1530 |
|
|
|
private Method getMethod (Class klass, String name, Class[] args) |
|
|
throws java.lang.NoSuchMethodException |
|
|
{ |
|
|
final Method m = klass.getDeclaredMethod(name, args); |
|
|
setAccessible.setMember(m); |
|
|
AccessController.doPrivileged(setAccessible); |
|
|
return m; |
|
|
} |
|
|
|
|
1531 |
private void dumpElementln (String msg) |
private void dumpElementln (String msg) |
1532 |
{ |
{ |
1533 |
for (int i = 0; i < depth; i++) |
for (int i = 0; i < depth; i++) |