250 |
break; |
break; |
251 |
} |
} |
252 |
|
|
253 |
|
Class clazz = obj.getClass(); |
254 |
|
ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz); |
255 |
|
if (osc == null) |
256 |
|
throw new NotSerializableException(clazz.getName()); |
257 |
|
|
258 |
if ((replacementEnabled || obj instanceof Serializable) |
if ((replacementEnabled || obj instanceof Serializable) |
259 |
&& ! replaceDone) |
&& ! replaceDone) |
260 |
{ |
{ |
262 |
|
|
263 |
if (obj instanceof Serializable) |
if (obj instanceof Serializable) |
264 |
{ |
{ |
|
Method m = null; |
|
265 |
try |
try |
266 |
{ |
{ |
267 |
Class classArgs[] = {}; |
Method m = osc.writeReplaceMethod; |
268 |
m = getMethod(obj.getClass(), "writeReplace", |
if (m != null) |
269 |
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) |
|
|
{ |
|
270 |
} |
} |
271 |
catch (IllegalAccessException ignore) |
catch (IllegalAccessException ignore) |
272 |
{ |
{ |
291 |
break; |
break; |
292 |
} |
} |
293 |
|
|
|
Class clazz = obj.getClass(); |
|
|
ObjectStreamClass osc = ObjectStreamClass.lookupForClassObject(clazz); |
|
|
if (osc == null) |
|
|
throw new NotSerializableException(clazz.getName()); |
|
|
|
|
294 |
if (clazz.isArray ()) |
if (clazz.isArray ()) |
295 |
{ |
{ |
296 |
realOutput.writeByte(TC_ARRAY); |
realOutput.writeByte(TC_ARRAY); |
1253 |
private void callWriteMethod(Object obj, ObjectStreamClass osc) |
private void callWriteMethod(Object obj, ObjectStreamClass osc) |
1254 |
throws IOException |
throws IOException |
1255 |
{ |
{ |
|
Class klass = osc.forClass(); |
|
1256 |
currentPutField = null; |
currentPutField = null; |
1257 |
try |
try |
1258 |
{ |
{ |
1259 |
Class classArgs[] = {ObjectOutputStream.class}; |
Object args[] = {this}; |
1260 |
Method m = getMethod(klass, "writeObject", classArgs); |
osc.writeObjectMethod.invoke(obj, args); |
|
Object args[] = {this}; |
|
|
m.invoke(obj, args); |
|
|
} |
|
|
catch (NoSuchMethodException nsme) |
|
|
{ |
|
|
// Nothing. |
|
1261 |
} |
} |
1262 |
catch (InvocationTargetException x) |
catch (InvocationTargetException x) |
1263 |
{ |
{ |
1268 |
if (exception instanceof IOException) |
if (exception instanceof IOException) |
1269 |
throw (IOException) exception; |
throw (IOException) exception; |
1270 |
|
|
1271 |
IOException ioe |
IOException ioe |
1272 |
= new IOException("Exception thrown from writeObject() on " + |
= new IOException("Exception thrown from writeObject() on " + |
1273 |
klass + ": " + exception.getClass().getName()); |
osc.forClass().getName() + ": " + |
1274 |
|
exception.getClass().getName()); |
1275 |
ioe.initCause(exception); |
ioe.initCause(exception); |
1276 |
throw ioe; |
throw ioe; |
1277 |
} |
} |
1279 |
{ |
{ |
1280 |
IOException ioe |
IOException ioe |
1281 |
= new IOException("Failure invoking writeObject() on " + |
= new IOException("Failure invoking writeObject() on " + |
1282 |
klass + ": " + x.getClass().getName()); |
osc.forClass().getName() + ": " + |
1283 |
|
x.getClass().getName()); |
1284 |
ioe.initCause(x); |
ioe.initCause(x); |
1285 |
throw ioe; |
throw ioe; |
1286 |
} |
} |
1522 |
} |
} |
1523 |
} |
} |
1524 |
|
|
|
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; |
|
|
} |
|
|
|
|
1525 |
private void dumpElementln (String msg) |
private void dumpElementln (String msg) |
1526 |
{ |
{ |
1527 |
for (int i = 0; i < depth; i++) |
for (int i = 0; i < depth; i++) |