java.io

Class ObjectStreamClass

Implemented Interfaces:
Serializable

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

Field Summary

static ObjectStreamField[]
NO_FIELDS
serialPersistentFields value indicating no serializable fields

Method Summary

Class
forClass()
Return the class in the local VM that this version is mapped to.
ObjectStreamField
getField(String name)
Get the field of this class by name.
ObjectStreamField[]
getFields()
Return an array of the fields of this serializable class.
String
getName()
The name of the class described by this descriptor.
long
getSerialVersionUID()
Return the serialVersionUID for this class.
static ObjectStreamClass
lookup(Class cl)
Find the descriptor for a class that can be serialized.
String
toString()
Return a string describing this ObjectStreamClass.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

NO_FIELDS

public static final ObjectStreamField[] NO_FIELDS
serialPersistentFields value indicating no serializable fields
Usages and Demos :

View More Examples of NO_FIELDS
   1: import java.io.ObjectOutputStream;
   2: import java.io.ObjectStreamClass;
   3: import java.io.ObjectStreamField;
   4:         ...
   5:     private static final ObjectStreamField[] serialPersistentFields = 
   6:         ObjectStreamClass.NO_FIELDS;
   7:     private List<byte[]> hashes;
   8:     private SerialTorrentFileSystem fileSystem;
   9:     private byte[] infoHash;

View Full Code Here
   1: import java.io.ObjectOutput;
   2: import java.io.ObjectStreamClass;
   3: import java.io.ObjectStreamConstants;
   4:         ...
   5: 
   6:     private static final ObjectStreamField[] serialPersistentFields = ObjectStreamClass.NO_FIELDS;
   7: 
   8: 
   9:     protected ClassDescriptor(Class clazz, ClassDescriptor superdesc, boolean serializable, boolean externalizable){

View Full Code Here
   1: import java.io.ObjectOutputStream;
   2: import java.io.ObjectStreamClass;
   3: import java.io.ObjectStreamField;
   4:         ...
   5:     private static final ObjectStreamField[] serialPersistentFields = 
   6:         ObjectStreamClass.NO_FIELDS;
   7: 
   8:     private Object stealLock;

View Full Code Here

Method Details

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.
Returns:
the Class instance that this descriptor represents

getField

public ObjectStreamField getField(String name)
Get the field of this class by name.
Parameters:
name - the name of the data field to look for
Returns:
The ObjectStreamField object of the named field or null if there is no such named field.
Usages and Demos :

View More Examples of getField(String name)
   1: import java.io.ObjectInputValidation;
   2: import java.io.ObjectStreamClass;
   3: import java.io.ObjectStreamField;
   4:         ...
   5:             public void writeFieldsToStream(Map fields) {
   6:                 ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]);
   7: 
   8:         ...
   9:                     String name = (String) iterator.next();
  10:                     ObjectStreamField field = objectStreamClass.getField(name);
  11:                     Object value = fields.get(name);
  12:         ...
  13:                         } else {
  14:                             ObjectStreamField field = objectStreamClass.getField(name);

View Full Code Here

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:
1.2
Usages and Demos :

View More Examples of getFields()
   1: import java.io.ObjectOutput;
   2: import java.io.ObjectStreamClass;
   3: import java.io.ObjectStreamField;
   4:         ...
   5:     private final byte[] primVals;
   6:     PutField(ObjectStreamClass desc)
   7:     {
   8:         ...
   9: 
  10:         java.io.ObjectStreamField[] fields = desc.getFields();
  11:         int numPrimFields = fields.length - objVals.length;
  12:         ...
  13:         int firstObjIndex = -1;
  14:         java.io.ObjectStreamField[] fields = desc.getFields();

View Full Code Here
   1: 
   2:     static void print(ObjectStreamClass desc) {
   3:         System.out.println("Class name      : " + desc.getName());
   4:         ...
   5:         System.out.println("ObjectStreamFields");
   6:         ObjectStreamField[] fields = desc.getFields();
   7:         int numPrim = 0;
   8:         ...
   9:             if (verbose) {
  10:                 ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
  11:                 System.out.println("******************");

View Full Code Here
   1: 
   2:     GetField(ObjectStreamClass desc)
   3:     {
   4:         ...
   5:     
   6:     public ObjectStreamClass getObjectStreamClass()
   7:     {
   8:         ...
   9:         
  10:         java.io.ObjectStreamField[] fields = desc.getFields();
  11:         int numPrimFields = fields.length - objVals.length;
  12:         ...
  13:         int firstObjIndex = -1;
  14:         java.io.ObjectStreamField[] fields = desc.getFields();

View Full Code Here
   1: import java.io.ObjectInputValidation;
   2: import java.io.ObjectStreamClass;
   3: import java.io.ObjectStreamField;
   4:         ...
   5:             public void writeFieldsToStream(Map fields) {
   6:                 ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]);
   7: 
   8:         ...
   9: 
  10:                 ObjectStreamField[] fields = objectStreamClass.getFields();
  11:                 for (int i = 0; i < fields.length; i++) {

View Full Code Here

getName

public String getName()
The name of the class described by this descriptor.
Returns:
a String representing the fully qualified name of the class
Usages and Demos :

View More Examples of getName()
   1:     
   2:     protected Class resolveClass(ObjectStreamClass v)
   3:         throws IOException,    ClassNotFoundException
   4:         ...
   5:     {
   6:         return Class.forName(v.getName(),false,mCL);
   7:     }
   8: 
   9: }

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.ObjectStreamClass;
   3: import java.io.StreamCorruptedException;
   4:         ...
   5: 
   6:   protected Class resolveClass(ObjectStreamClass v)
   7:         throws IOException, ClassNotFoundException {
   8:         ...
   9:     return Class.forName(v.getName(), false, this.cl);
  10:   }

View Full Code Here
   1: import java.io.InputStream;
   2: import java.io.ObjectStreamClass;
   3: import java.io.ObjectInputStream;
   4:         ...
   5: 
   6:     protected Class resolveClass(ObjectStreamClass v)
   7:         throws IOException, ClassNotFoundException {
   8:         ...
   9:         ClassLoader loader = FixedObjectInputStream.class.getClassLoader();
  10:         return Class.forName(v.getName(), false, loader);
  11:     }

View Full Code Here
   1: 
   2: import java.io.ObjectStreamClass;
   3: import java.io.ObjectInputStream;
   4:         ...
   5:     protected ClassFactory cf;
   6:     protected ObjectStreamClass        initialClass;
   7: 
   8:         ...
   9: 
  10:     protected Class resolveClass(ObjectStreamClass v)
  11:         throws IOException, ClassNotFoundException {
  12:         ...
  13: 
  14:         throw new ClassNotFoundException(v.getName());

View Full Code Here
   1:     
   2:     protected final Class resolveClass(ObjectStreamClass v)
   3:     throws ClassNotFoundException {
   4:         ...
   5:     boolean debug = true;
   6:     return Class.forName(v.getName(), true,
   7:                  DaemonClassLoader.instance);
   8:     }
   9:     

View Full Code Here

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.
Returns:
the SUID of the class described by this descriptor
Usages and Demos :

View More Examples of getSerialVersionUID()
   1: 
   2:         ObjectStreamClass ocl = ObjectStreamClass.lookup(cl);
   3: 
   4:         System.out.println("For class " + cl);
   5:         System.out.println("static final long serialVersionUID = " +

View Full Code Here
   1: import java.io.ObjectStreamClass;
   2: 
   3:         ...
   4:         Class clz = Class.forName(args[i]);
   5:         ObjectStreamClass stream = ObjectStreamClass.lookup(clz);
   6:         if (stream != null) {
   7:         ...
   8:             System.out.println(args[i] + ": static final long serialVersionUID = " + stream.getSerialVersionUID() + "L;");
   9:         }

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.ObjectStreamClass;
   3: import java.io.OutputStreamWriter;
   4:         ...
   5:                             try {
   6:                                 final ObjectStreamClass clazz= ObjectStreamClass.lookup(Class.forName(arguments[i]));
   7:                                 if (clazz != null) {
   8:         ...
   9:                                     writer.write(new Long(clazz.getSerialVersionUID()).toString());
  10:                                     writer.write('\n');

View Full Code Here
   1: 
   2:     static void print(ObjectStreamClass desc) {
   3:         System.out.println("Class name      : " + desc.getName());
   4:         ...
   5:         System.out.println("SerialVersionUID: " + desc.getSerialVersionUID());
   6:         System.out.println("ObjectStreamFields");
   7:         ...
   8:             if (verbose) {
   9:                 ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
  10:                 System.out.println("******************");

View Full Code Here
   1: import java.io.ObjectOutputStream;
   2: import java.io.ObjectStreamClass;
   3: import java.io.Serializable;
   4:         ...
   5: 
   6:       ObjectStreamClass osClass = ObjectStreamClass.lookup(cls);
   7:       if (osClass != null) {
   8:         ...
   9:          long serialVersionUID = osClass.getSerialVersionUID();

View Full Code Here

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.
Parameters:
cl - class for which to get the descriptor
Returns:
the class descriptor for the specified class
Usages and Demos :

View More Examples of lookup(Class cl)
   1: 
   2:         ObjectStreamClass ocl = ObjectStreamClass.lookup(cl);
   3: 
   4:         System.out.println("For class " + cl);
   5:         System.out.println("static final long serialVersionUID = " +

View Full Code Here
   1: import java.io.ObjectInputStream;
   2: import java.io.ObjectStreamClass;
   3: 
   4:         ...
   5:      
   6:     protected ObjectStreamClass readClassDescriptor() throws 
   7:       IOException, ClassNotFoundException { 
   8:         ...
   9:         ObjectStreamClass read = super.readClassDescriptor(); 
  10:         String className = read.getName(); 
  11:         ...
  12:         className = "java.util" + className.substring(29); 
  13:         return ObjectStreamClass.lookup(Class.forName(className)); 

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.ObjectStreamClass;
   3: import java.util.HashMap;
   4:         ...
   5:                 Class cls = Class.forName(className);
   6:                 ObjectStreamClass desc = ObjectStreamClass.lookup(cls);
   7: 
   8:         ...
   9: 
  10:     public synchronized ObjectStreamClass getClassFormat(String className)
  11:         throws IOException {

View Full Code Here
   1: import java.io.ObjectInputStream;
   2: import java.io.ObjectStreamClass;
   3: 
   4:         ...
   5:    
   6:    protected ObjectStreamClass readClassDescriptor()
   7:       throws IOException, ClassNotFoundException
   8:         ...
   9:    {
  10:       return ObjectStreamClass.lookup(cl.loadClass(readUTF()));
  11:    }
  12:         ...
  13:    
  14:    protected Class resolveClass(ObjectStreamClass classdesc)

View Full Code Here
   1: import java.io.ObjectStreamClass;
   2: 
   3:         ...
   4:         Class clz = Class.forName(args[i]);
   5:         ObjectStreamClass stream = ObjectStreamClass.lookup(clz);
   6:         if (stream != null) {
   7:             System.out.println(args[i] + ": static final long serialVersionUID = " + stream.getSerialVersionUID() + "L;");
   8:         }

View Full Code Here

toString

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