Package java.io
Class ObjectStreamClass
- java.lang.Object
-
- java.io.ObjectStreamClass
-
- All Implemented Interfaces:
Serializable
public class ObjectStreamClass extends Object implements Serializable
Represents a descriptor for identifying a class during serialization and deserialization. Information contained in the descriptor includes the name and SUID of the class as well as field names and types. Information inherited from the superclasses is also taken into account.- See Also:
ObjectOutputStream,ObjectInputStream,Class, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ObjectStreamField[]NO_FIELDSConstant indicating that the class has no Serializable fields.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Class<?>checkAndGetTcEnumClass()Checks the local class to make sure it is valid forObjectStreamConstants.TC_ENUMdeserialization.Class<?>checkAndGetTcObjectClass()Checks the local class to make sure it is valid forObjectStreamConstants.TC_OBJECTdeserialization.Class<?>forClass()Returns the class (java.lang.Class) for this descriptor.ObjectStreamFieldgetField(String name)Gets a field descriptor of the class represented by this class descriptor.ObjectStreamField[]getFields()Returns a collection of field descriptors for the serialized fields of the class represented by this class descriptor.StringgetName()Returns the name of the class represented by this descriptor.longgetSerialVersionUID()Returns the Serial Version User ID of the class represented by this descriptor.static ObjectStreamClasslookup(Class<?> cl)Returns the descriptor for a serializable class.static ObjectStreamClasslookupAny(Class<?> cl)Returns the descriptor for any class, whether or not the class implements Serializable or Externalizable.StringtoString()Returns a string containing a concise, human-readable description of this descriptor.
-
-
-
Field Detail
-
NO_FIELDS
public static final ObjectStreamField[] NO_FIELDS
Constant indicating that the class has no Serializable fields.
-
-
Method Detail
-
forClass
public Class<?> forClass()
Returns the class (java.lang.Class) for this descriptor.- Returns:
- the class in the local VM that this descriptor represents;
nullif there is no corresponding class.
-
getField
public ObjectStreamField getField(String name)
Gets a field descriptor of the class represented by this class descriptor.- Parameters:
name- the name of the desired field.- Returns:
- the field identified by
nameornullif there is no such field.
-
getFields
public ObjectStreamField[] getFields()
Returns a collection of field descriptors for the serialized fields of the class represented by this class descriptor.- Returns:
- an array of field descriptors or an array of length zero if there are no fields in this descriptor's class.
-
getName
public String getName()
Returns the name of the class represented by this descriptor.- Returns:
- the fully qualified name of the class this descriptor represents.
-
getSerialVersionUID
public long getSerialVersionUID()
Returns the Serial Version User ID of the class represented by this descriptor.- Returns:
- the SUID for the class represented by this descriptor.
-
lookup
public static ObjectStreamClass lookup(Class<?> cl)
Returns the descriptor for a serializable class. Returns null if the class doesn't implementSerializableorExternalizable.- Parameters:
cl- a java.lang.Class for which to obtain the corresponding descriptor- Returns:
- the corresponding descriptor if the class is serializable or externalizable; null otherwise.
-
lookupAny
public static ObjectStreamClass lookupAny(Class<?> cl)
Returns the descriptor for any class, whether or not the class implements Serializable or Externalizable.- Parameters:
cl- a java.lang.Class for which to obtain the corresponding descriptor- Returns:
- the descriptor
- Since:
- 1.6
-
toString
public String toString()
Returns a string containing a concise, human-readable description of this descriptor.
-
checkAndGetTcObjectClass
public Class<?> checkAndGetTcObjectClass() throws InvalidClassException
Checks the local class to make sure it is valid forObjectStreamConstants.TC_OBJECTdeserialization. Also performs some sanity checks of the stream data. This method is used during deserialization to confirm the local class is likely to be compatible with the coming stream data, but before an instance is instantiated.- Throws:
InvalidClassException
-
checkAndGetTcEnumClass
public Class<?> checkAndGetTcEnumClass() throws InvalidClassException
Checks the local class to make sure it is valid forObjectStreamConstants.TC_ENUMdeserialization. This method is used during deserialization to confirm the local class is likely to be compatible with the coming stream data, but before an instance is instantiated.- Throws:
InvalidClassException
-
-