java.io
Class ObjectStreamClass

java.lang.Object
  |
  +--java.io.ObjectStreamClass

public class ObjectStreamClass
extends Object
implements Serializable

Serialization's descriptor for classes. It contains the name and serialVersionUID of the class.
The ObjectStreamClass for a specific class loaded in this Java VM can be found/created using the lookup method.

The algorithm to compute the SerialVersionUID is described in Object Serialization Specification, Section 4.4, Stream Unique Identifiers.

Since:
JDK1.1
See Also:
ObjectStreamField, Object Serialization Specification, Section 4, Class Descriptors, Serialized Form

Inner Class Summary
private static class ObjectStreamClass.CompareClassByName
           
private static class ObjectStreamClass.CompareMemberByName
           
private static class ObjectStreamClass.MethodSignature
           
private static class ObjectStreamClass.ObjectStreamClassEntry
           
 
Field Summary
private static Comparator compareClassByName
           
private static Comparator compareMemberByName
           
private static ObjectStreamClass.ObjectStreamClassEntry[] descriptorFor
           
private  boolean disableInstanceDeserialization
           
private  boolean externalizable
           
private  ObjectStreamField[] fields
           
private  boolean hasExternalizableBlockData
           
private  boolean hasWriteObjectMethod
           
private  ObjectStreamClass localClassDesc
           
private  String name
           
static ObjectStreamField[] NO_FIELDS
          Set serialPersistentFields of a Serializable class to this value to denote that the class has no Serializable fields.
private static Class[] NULL_ARGS
           
(package private)  int objFields
           
private  Class ofClass
           
private static Class[] OIS_ARGS
           
private static Class[] OOS_ARGS
           
(package private)  int primBytes
           
(package private)  java.lang.reflect.Method readObjectMethod
           
(package private)  java.lang.reflect.Method readResolveMethod
           
private  boolean serializable
           
private static ObjectStreamField[] serialPersistentFields
          Class ObjectStreamClass is special cased within the Serialization Stream Protocol.
private static long serialVersionUID
          use serialVersionUID from JDK 1.1.
private  long suid
           
private  ObjectStreamClass superclass
           
(package private)  java.lang.reflect.Method writeObjectMethod
           
(package private)  java.lang.reflect.Method writeReplaceMethod
           
 
Constructor Summary
private ObjectStreamClass(Class cl, ObjectStreamClass superdesc, boolean serial, boolean extern)
           
(package private) ObjectStreamClass(String n, long s)
           
 
Method Summary
private  boolean checkSuperMethodAccess(java.lang.reflect.Method scMethod)
           
(package private) static boolean compareClassNames(String streamName, String localName, char pkgSeparator)
           
private  void computeFieldInfo()
           
private static long computeSerialVersionUID(Class cl)
           
private static ObjectStreamClass findDescriptorFor(Class cl)
           
 Class forClass()
          Return the class in the local VM that this version is mapped to.
private  java.lang.reflect.Method getDeclaredMethod(String methodName, Class[] args, int requiredModifierMask, int disallowedModifierMask)
           
 ObjectStreamField getField(String name)
          Get the field of this class by name.
(package private)  ObjectStreamField getField(String name, Class fieldType)
          Get the field of this class by name and fieldType.
 ObjectStreamField[] getFields()
          Return an array of the fields of this serializable class.
(package private)  ObjectStreamField[] getFieldsNoCopy()
           
 String getName()
          The name of the class described by this descriptor.
 long getSerialVersionUID()
          Return the serialVersionUID for this class.
(package private) static String getSignature(Class clazz)
          Compute the JVM signature for the class.
(package private) static String getSignature(java.lang.reflect.Constructor cons)
           
(package private) static String getSignature(java.lang.reflect.Method meth)
           
(package private)  ObjectStreamClass getSuperclass()
           
(package private)  boolean hasExternalizableBlockDataMode()
           
private static boolean hasStaticInitializer(Class cl)
           
(package private)  boolean hasWriteObject()
           
private static void initStaticMethodArgs()
           
private static void insertDescriptorFor(ObjectStreamClass desc)
           
(package private) static Object invokeMethod(java.lang.reflect.Method method, Object obj, Object[] args)
           
(package private)  boolean isExternalizable()
           
(package private)  boolean isNonSerializable()
           
(package private)  boolean isReplaceable()
           
(package private)  boolean isResolvable()
           
private static boolean isSameClassPackage(Class cl1, Class cl2)
           
(package private)  boolean isSerializable()
           
(package private)  ObjectStreamClass localClassDescriptor()
           
static ObjectStreamClass lookup(Class cl)
          Find the descriptor for a class that can be serialized.
(package private) static ObjectStreamClass lookupInternal(Class cl)
           
(package private)  void read(ObjectInputStream s)
           
(package private)  void setClass(Class cl)
           
(package private)  void setSuperclass(ObjectStreamClass s)
           
 String toString()
          Return a string describing this ObjectStreamClass.
(package private)  boolean typeEquals(ObjectStreamClass other)
           
private  void validateLocalClass(Class localCl)
           
(package private)  void verifyInstanceDeserialization()
           
(package private)  void write(ObjectOutputStream s)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

descriptorFor

private static ObjectStreamClass.ObjectStreamClassEntry[] descriptorFor

name

private String name

superclass

private ObjectStreamClass superclass

serializable

private boolean serializable

externalizable

private boolean externalizable

fields

private ObjectStreamField[] fields

ofClass

private Class ofClass

suid

private long suid

primBytes

int primBytes

objFields

int objFields

hasWriteObjectMethod

private boolean hasWriteObjectMethod

hasExternalizableBlockData

private boolean hasExternalizableBlockData

writeObjectMethod

java.lang.reflect.Method writeObjectMethod

readObjectMethod

java.lang.reflect.Method readObjectMethod

readResolveMethod

java.lang.reflect.Method readResolveMethod

writeReplaceMethod

java.lang.reflect.Method writeReplaceMethod

localClassDesc

private ObjectStreamClass localClassDesc

disableInstanceDeserialization

private boolean disableInstanceDeserialization

serialVersionUID

private static final long serialVersionUID
use serialVersionUID from JDK 1.1. for interoperability

NO_FIELDS

public static final ObjectStreamField[] NO_FIELDS
Set serialPersistentFields of a Serializable class to this value to denote that the class has no Serializable fields.

serialPersistentFields

private static final ObjectStreamField[] serialPersistentFields
Class ObjectStreamClass is special cased within the Serialization Stream Protocol. An ObjectStreamClass is written intially into an ObjectOutputStream in the following format:
      TC_CLASSDESC className, serialVersionUID, flags, 
                   length, list of field descriptions.

 FIELDNAME        TYPES
                  DESCRIPTION
 --------------------------------------
 className        primitive data String
                  Fully qualified class name.

 serialVersionUID long
                  Stream Unique Identifier for compatible classes
                  with same base class name.

 flags            byte
                  Attribute bit fields defined in 
                  java.io.ObjectStreamConstants.SC_*.

 length           short
                  The number of field descriptions to follow.

 fieldDescription (byte, primitive data String, String Object)
                  A pseudo-externalized format of class
                  java.io.ObjectStreamField.
                  Consists of typeCode, fieldName, and,
                  if a nonPrimitive typecode, a fully qualified
                  class name. See Class.getName method 
                  for the typecode byte encodings.
 
The first time the class descriptor is written into the stream, a new handle is generated. Future references to the class descriptor are written as references to the initial class descriptor instance.
See Also:
ObjectOutputStream.writeUTF(java.lang.String)

compareClassByName

private static Comparator compareClassByName

compareMemberByName

private static Comparator compareMemberByName

NULL_ARGS

private static final Class[] NULL_ARGS

OIS_ARGS

private static Class[] OIS_ARGS

OOS_ARGS

private static Class[] OOS_ARGS
Constructor Detail

ObjectStreamClass

private ObjectStreamClass(Class cl,
                          ObjectStreamClass superdesc,
                          boolean serial,
                          boolean extern)

ObjectStreamClass

ObjectStreamClass(String n,
                  long s)
Method Detail

lookup

public static ObjectStreamClass lookup(Class cl)
Find the descriptor for a class that can be serialized. Creates an ObjectStreamClass instance if one does not exist yet for class. Null is returned if the specified class does not implement java.io.Serializable or java.io.Externalizable.

lookupInternal

static ObjectStreamClass lookupInternal(Class cl)

getName

public String getName()
The name of the class described by this descriptor.

getSerialVersionUID

public long getSerialVersionUID()
Return the serialVersionUID for this class. The serialVersionUID defines a set of classes all with the same name that have evolved from a common root class and agree to be serialized and deserialized using a common format. NonSerializable classes have a serialVersionUID of 0L.

forClass

public Class forClass()
Return the class in the local VM that this version is mapped to. Null is returned if there is no corresponding local class.

getFields

public ObjectStreamField[] getFields()
Return an array of the fields of this serializable class.
Returns:
an array containing an element for each persistent field of this class. Returns an array of length zero if there are no fields.
Since:
JDK1.2

getFieldsNoCopy

final ObjectStreamField[] getFieldsNoCopy()

getField

public ObjectStreamField getField(String name)
Get the field of this class by name.
Returns:
The ObjectStreamField object of the named field or null if there is no such named field.

getField

ObjectStreamField getField(String name,
                           Class fieldType)
Get the field of this class by name and fieldType.
Returns:
The ObjectStreamField object of the named field, type or null if there is no such named field of fieldType.

toString

public String toString()
Return a string describing this ObjectStreamClass.
Overrides:
toString in class Object

validateLocalClass

private void validateLocalClass(Class localCl)
                         throws InvalidClassException

setClass

void setClass(Class cl)
        throws InvalidClassException

compareClassNames

static boolean compareClassNames(String streamName,
                                 String localName,
                                 char pkgSeparator)

typeEquals

boolean typeEquals(ObjectStreamClass other)

setSuperclass

void setSuperclass(ObjectStreamClass s)

getSuperclass

ObjectStreamClass getSuperclass()

hasWriteObject

boolean hasWriteObject()

hasExternalizableBlockDataMode

boolean hasExternalizableBlockDataMode()

localClassDescriptor

ObjectStreamClass localClassDescriptor()

isSerializable

boolean isSerializable()

isExternalizable

boolean isExternalizable()

isNonSerializable

boolean isNonSerializable()

computeFieldInfo

private void computeFieldInfo()

computeSerialVersionUID

private static long computeSerialVersionUID(Class cl)

getSignature

static String getSignature(Class clazz)
Compute the JVM signature for the class.

getSignature

static String getSignature(java.lang.reflect.Method meth)

getSignature

static String getSignature(java.lang.reflect.Constructor cons)

write

void write(ObjectOutputStream s)
     throws IOException

read

void read(ObjectInputStream s)
    throws IOException,
           ClassNotFoundException

verifyInstanceDeserialization

void verifyInstanceDeserialization()
                             throws InvalidClassException

findDescriptorFor

private static ObjectStreamClass findDescriptorFor(Class cl)

insertDescriptorFor

private static void insertDescriptorFor(ObjectStreamClass desc)

hasStaticInitializer

private static boolean hasStaticInitializer(Class cl)

isResolvable

boolean isResolvable()

isReplaceable

boolean isReplaceable()

invokeMethod

static Object invokeMethod(java.lang.reflect.Method method,
                           Object obj,
                           Object[] args)
                    throws IOException

getDeclaredMethod

private java.lang.reflect.Method getDeclaredMethod(String methodName,
                                                   Class[] args,
                                                   int requiredModifierMask,
                                                   int disallowedModifierMask)

checkSuperMethodAccess

private boolean checkSuperMethodAccess(java.lang.reflect.Method scMethod)

isSameClassPackage

private static boolean isSameClassPackage(Class cl1,
                                          Class cl2)

initStaticMethodArgs

private static void initStaticMethodArgs()