44 |
import java.lang.reflect.Member; |
import java.lang.reflect.Member; |
45 |
import java.lang.reflect.Method; |
import java.lang.reflect.Method; |
46 |
import java.lang.reflect.Modifier; |
import java.lang.reflect.Modifier; |
47 |
|
import java.lang.reflect.Proxy; |
48 |
import java.security.DigestOutputStream; |
import java.security.DigestOutputStream; |
49 |
import java.security.MessageDigest; |
import java.security.MessageDigest; |
50 |
import java.security.NoSuchAlgorithmException; |
import java.security.NoSuchAlgorithmException; |
75 |
if (! (Serializable.class).isAssignableFrom (cl)) |
if (! (Serializable.class).isAssignableFrom (cl)) |
76 |
return null; |
return null; |
77 |
|
|
78 |
|
return lookupForClassObject (cl); |
79 |
|
} |
80 |
|
|
81 |
|
/** |
82 |
|
* This lookup for internal use by ObjectOutputStream. Suppose |
83 |
|
* we have a java.lang.Class object C for class A, though A is not |
84 |
|
* serializable, but it's okay to serialize C. |
85 |
|
*/ |
86 |
|
static ObjectStreamClass lookupForClassObject (Class cl) |
87 |
|
{ |
88 |
|
if (cl == null) |
89 |
|
return null; |
90 |
|
|
91 |
ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (cl); |
ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (cl); |
92 |
|
|
93 |
if (osc != null) |
if (osc != null) |
260 |
} |
} |
261 |
|
|
262 |
|
|
263 |
|
final boolean isProxyClass() |
264 |
|
{ |
265 |
|
return _isProxyClass; |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
ObjectStreamClass (String name, long uid, byte flags, |
ObjectStreamClass (String name, long uid, byte flags, |
270 |
ObjectStreamField[] fields) |
ObjectStreamField[] fields) |
271 |
{ |
{ |
278 |
|
|
279 |
void setClass (Class clazz) |
void setClass (Class clazz) |
280 |
{ |
{ |
281 |
|
_isProxyClass = Proxy.isProxyClass(clazz); |
282 |
this.clazz = clazz; |
this.clazz = clazz; |
283 |
|
ObjectStreamClass osc = (ObjectStreamClass)classLookupTable.get (clazz); |
284 |
|
if (osc == null) |
285 |
|
classLookupTable.put (clazz, this); |
286 |
|
superClass = lookupForClassObject (clazz.getSuperclass ()); |
287 |
|
calculateOffsets (); |
288 |
} |
} |
289 |
|
|
290 |
|
|
338 |
{ |
{ |
339 |
uid = 0; |
uid = 0; |
340 |
flags = 0; |
flags = 0; |
341 |
|
_isProxyClass = Proxy.isProxyClass (cl); |
342 |
|
|
343 |
clazz = cl; |
clazz = cl; |
344 |
name = cl.getName (); |
name = cl.getName (); |
345 |
setFlags (cl); |
setFlags (cl); |
346 |
setFields (cl); |
setFields (cl); |
347 |
setUID (cl); |
// to those class nonserializable, its uid field is 0 |
348 |
|
if ( (Serializable.class).isAssignableFrom (cl) ) |
349 |
|
setUID (cl); |
350 |
superClass = lookup (cl.getSuperclass ()); |
superClass = lookup (cl.getSuperclass ()); |
351 |
} |
} |
352 |
|
|
426 |
if (all_fields[from] != null) |
if (all_fields[from] != null) |
427 |
{ |
{ |
428 |
Field f = all_fields[from]; |
Field f = all_fields[from]; |
429 |
fields[to] = new ObjectStreamField (f.getName (), f.getType ()); |
String name = f.getName(); |
430 |
|
// here is a hack to interoperate with JDK |
431 |
|
/* if Throwable is not align with serialized form of Java API spec, |
432 |
|
you should uncomment the following two line. |
433 |
|
if (name.equals("message") && getName().equals("java.lang.Throwable")) |
434 |
|
name = "detailMessage"; |
435 |
|
*/ |
436 |
|
fields[to] = new ObjectStreamField (name, f.getType ()); |
437 |
to++; |
to++; |
438 |
} |
} |
439 |
|
|
638 |
|
|
639 |
try |
try |
640 |
{ |
{ |
641 |
|
/* |
642 |
|
* There exists a problem here, JDK run of |
643 |
|
* clazz.getDeclaredMethod ("<clinit>", classArgs); |
644 |
|
* will always throw NoSuchMethodException, even the static |
645 |
|
* intializer does exist. |
646 |
|
*/ |
647 |
Class classArgs[] = {}; |
Class classArgs[] = {}; |
648 |
m = clazz.getDeclaredMethod ("<clinit>", classArgs); |
m = clazz.getDeclaredMethod ("<clinit>", classArgs); |
649 |
} |
} |
677 |
// these are accessed by ObjectIn/OutputStream |
// these are accessed by ObjectIn/OutputStream |
678 |
int primFieldSize = -1; // -1 if not yet calculated |
int primFieldSize = -1; // -1 if not yet calculated |
679 |
int objectFieldCount; |
int objectFieldCount; |
680 |
|
|
681 |
|
boolean _isProxyClass = false; |
682 |
|
|
683 |
// This is probably not necessary because this class is special cased already |
// This is probably not necessary because this class is special cased already |
684 |
// but it will avoid showing up as a discrepancy when comparing SUIDs. |
// but it will avoid showing up as a discrepancy when comparing SUIDs. |
685 |
private static final long serialVersionUID = -6120832682080437368L; |
private static final long serialVersionUID = -6120832682080437368L; |