|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
java.io.ObjectInputStream
rice.p2p.util.XMLObjectInputStream
public class XMLObjectInputStream
XMLObjectInputStreamm is an extension of ObjectInputStreamm which provides for deserialization for objects which have been converted to XML via a XMLObjectOutputStream. This class supports all of the features of the ObjectInputStreamm, including serialization support for any Java object graph implementing the Serializable interface, support for Externalizable classes, custom deserialization via the readObject() method, class evolution via the readObjectNoData() method, alternate field reading mechanisms via the readFields() method, support for the readUnshared method, and dynamic object replacement via the readResolve() method. The format of the XML data to be read in should conform to the JSX XML Schema, available online at http://www.jsx.org/jsx.xsd. This class is designed to be able to read objects serialized using JSX, however, this has not been fully tested and bugs may be encountered.
| Nested Class Summary | |
|---|---|
class |
XMLObjectInputStream.GetField
This class is an implementation of GetField which is compatible with the XMLObjectInputStreamm. |
| Field Summary | |
|---|---|
protected static SoftHashMap |
CONSTRUCTORS
A cache of constructors, mapping classes to serialization constructors |
protected Stack |
currentClasses
The stack of class types which are being read off of the stream |
protected Stack |
currentObjects
The stack of objects which are currently being read off of the stream |
protected int |
depth
The depth at which we are currently at in the object tree |
protected static SoftHashMap |
READ_OBJECTS
The hashmap of readObject methods, mapping Class->Method |
protected static SoftHashMap |
READ_RESOLVES
The hashmap of readResolve methods, mapping Class->Method |
protected XMLReader |
reader
The underlying reader, which parses the XML |
protected Hashtable |
references
The hashtable of references, which is updated each time a new object is read off of the stream. |
protected sun.reflect.ReflectionFactory |
reflFactory
The ReflectionFactory, which allows for prividged construction of objects |
protected rice.p2p.util.XMLObjectInputStream.ValidationList |
vlist
The list of validation objects waiting for the entire object graph to be read in |
| Constructor Summary | |
|---|---|
XMLObjectInputStream(InputStream in)
Constructor which reads data from the given input stream in order deserialize objects. |
|
| Method Summary | |
|---|---|
void |
close()
Method which closes the underlying input stream for reading. |
void |
defaultReadObject()
Method which can be called by objects if they have a readObject() method. |
protected Class |
getClass(String name)
Method which returns the class object for class names written to the stream. |
protected Object |
getReference(String reference)
Method which returns a previously stored reference. |
protected Constructor |
getSerializableConstructor(Class c)
Method which returns the Serializable constructor for the provided class. |
protected Object |
newInstance(Class c)
Method which returns a new instance of the provided class. |
protected void |
putReference(String reference,
Object o)
Method which adds a reference in the hashtable of references. |
int |
read()
Method which reads a byte from the underlying output stream. |
int |
read(byte[] b,
int offset,
int length)
Method which reads a array of bytes from the underlying output stream. |
protected Object |
readArray(boolean shared)
Method which reads an array off of the stream. |
boolean |
readBoolean()
Method which reads a boolean from the stream and returns the result. |
protected boolean |
readBooleanHelper()
Method which reads an boolean from the stream. |
byte |
readByte()
Method which reads a byte from the stream and returns the result. |
protected byte |
readByteHelper()
Method which reads an byte from the stream. |
char |
readChar()
Method which reads a char from the stream and returns the result. |
protected char |
readCharHelper()
Method which reads an char from the stream. |
protected Object |
readClass(Object o)
Method which reads the information for one class for a given object from the stream. |
double |
readDouble()
Method which reads a double from the stream and returns the result. |
protected double |
readDoubleHelper()
Method which reads an double from the stream. |
protected void |
readField(Object o,
Class c)
Method which reads a single field from the stream, and assignes it to the provided object. |
ObjectInputStream.GetField |
readFields()
Method which can be called by objects if they have a readObject() method. |
protected void |
readFields(Object o,
Class c)
Method which initiates the default field reading mechanism for the given object's class. |
float |
readFloat()
Method which reads a float from the stream and returns the result. |
protected float |
readFloatHelper()
Method which reads an float from the stream. |
void |
readFully(byte[] b)
Method which reads a byte from the underlying output stream. |
void |
readFully(byte[] b,
int offset,
int length)
Method which reads a byte from the underlying output stream. |
protected void |
readGetField(XMLObjectInputStream.GetField g)
Method which read a single field from the stream and places it in the provided GetField object. |
protected XMLObjectInputStream.GetField |
readGetFields()
Method which reads all of the field data from the stream, as readFields() does, but instead of assigning the fields to the object, it returns them as a GetField object. |
int |
readInt()
Method which reads an int from the stream and returns the result. |
protected int |
readIntHelper()
Method which reads an int from the stream. |
long |
readLong()
Method which reads a long from the stream and returns the result. |
protected long |
readLongHelper()
Method which reads an long from the stream. |
protected Object |
readNull()
Method which reads a null item off of the stream. |
protected Object |
readObjectHelper()
Method which reads an object from the stream. |
protected Object |
readObjectOverride()
Method which is called by ObjectInputStreamm.readObject(), and reads the next object from the stream, and returns the result. |
protected Object |
readOrdinaryObject(boolean shared)
Method which reads an ordinary object from the stream (not a String or Array). |
protected String |
readPrimitive(String type)
Method which reads a primitive value from the stream and returns the String representation to the callee for processing. |
protected void |
readPrimitiveField(Object o,
Field f)
Method which reads a primitive field from the stream, and places it in the given object. |
protected void |
readPrimitiveGetField(XMLObjectInputStream.GetField g)
Method which reads a primitive field from the stream, and places it in the provided GetField object. |
protected Object |
readReference()
Method which reads a reference off of the stream, and looks the reference up in the references table. |
short |
readShort()
Method which reads a short from the stream and returns the result. |
protected short |
readShortHelper()
Method which reads an short from the stream. |
protected void |
readStreamHeader()
Method which reads the XML header off of the stream. |
protected Object |
readString(boolean shared)
Method which reads a string item off of the stream. |
protected void |
readUnreadOptionalData()
Method which reads any extra data from the stream which was not read by the object. |
Object |
readUnshared()
Method which reads the next object from the stream and does not record a reference to the object. |
protected Object |
readUnsharedHelper(boolean shared)
Method which reads an object from the stream. |
int |
readUnsignedByte()
Method which reads an unsigned byte from the underlying output stream. |
int |
readUnsignedShort()
Method which reads an unsigned short from the underlying output stream. |
String |
readUTF()
Method which reads a UTF-encoded String from the stream and returns the result. |
void |
registerValidation(ObjectInputValidation obj,
int prio)
Register an object to be validated before the graph is returned. |
void |
reset()
Method which resets the input stream, which removes the binding of all previously stored references. |
| Methods inherited from class java.io.ObjectInputStream |
|---|
available, enableResolveObject, readClassDescriptor, readLine, readObject, resolveClass, resolveObject, resolveProxyClass, skipBytes |
| Methods inherited from class java.io.InputStream |
|---|
mark, markSupported, read, skip |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.io.ObjectInput |
|---|
read, skip |
| Field Detail |
|---|
protected static SoftHashMap READ_RESOLVES
protected static SoftHashMap READ_OBJECTS
protected static SoftHashMap CONSTRUCTORS
protected XMLReader reader
protected Hashtable references
protected Stack currentObjects
protected Stack currentClasses
protected sun.reflect.ReflectionFactory reflFactory
protected rice.p2p.util.XMLObjectInputStream.ValidationList vlist
protected int depth
| Constructor Detail |
|---|
public XMLObjectInputStream(InputStream in)
throws IOException
in - The input stream to read data from
IOException - If the stream header is corrupt| Method Detail |
|---|
protected void readStreamHeader()
throws IOException
readStreamHeader in class ObjectInputStreamIOException - If the stream header is corrupt
public void close()
throws IOException
close in interface Closeableclose in interface ObjectInputclose in class ObjectInputStreamIOException - If an error occurs
public void reset()
throws IOException
reset in class InputStreamIOException - If an error occurs
public int read()
throws IOException
read in interface ObjectInputread in class ObjectInputStreamIOException - If an error occurs
public int read(byte[] b,
int offset,
int length)
throws IOException
read in interface ObjectInputread in class ObjectInputStreamIOException - If an error occurs
public void readFully(byte[] b)
throws IOException
readFully in interface DataInputreadFully in class ObjectInputStreamIOException - If an error occurs
public void readFully(byte[] b,
int offset,
int length)
throws IOException
readFully in interface DataInputreadFully in class ObjectInputStreamIOException - If an error occurs
public int readUnsignedByte()
throws IOException
readUnsignedByte in interface DataInputreadUnsignedByte in class ObjectInputStreamIOException - If an error occurs
public int readUnsignedShort()
throws IOException
readUnsignedShort in interface DataInputreadUnsignedShort in class ObjectInputStreamIOException - If an error occurs
public int readInt()
throws IOException
readInt in interface DataInputreadInt in class ObjectInputStreamIOException - If an error occurs
public boolean readBoolean()
throws IOException
readBoolean in interface DataInputreadBoolean in class ObjectInputStreamIOException - If an error occurs
public byte readByte()
throws IOException
readByte in interface DataInputreadByte in class ObjectInputStreamIOException - If an error occurs
public char readChar()
throws IOException
readChar in interface DataInputreadChar in class ObjectInputStreamIOException - If an error occurs
public double readDouble()
throws IOException
readDouble in interface DataInputreadDouble in class ObjectInputStreamIOException - If an error occurs
public float readFloat()
throws IOException
readFloat in interface DataInputreadFloat in class ObjectInputStreamIOException - If an error occurs
public long readLong()
throws IOException
readLong in interface DataInputreadLong in class ObjectInputStreamIOException - If an error occurs
public short readShort()
throws IOException
readShort in interface DataInputreadShort in class ObjectInputStreamIOException - If an error occurs
public String readUTF()
throws IOException
readUTF in interface DataInputreadUTF in class ObjectInputStreamIOException - If an error occurs
protected Object readObjectOverride()
throws IOException,
ClassNotFoundException
readObjectOverride in class ObjectInputStreamIOException - If an error occurs
ClassNotFoundException - If a class in the stream cannot be found
public Object readUnshared()
throws IOException,
ClassNotFoundException
readUnshared in class ObjectInputStreamIOException - If an error occurs
ClassNotFoundException - If a class in the stream cannot be found
public void defaultReadObject()
throws IOException,
ClassNotFoundException
defaultReadObject in class ObjectInputStreamIOException - If an error occurs
ClassNotFoundException - If a class in the stream cannot be found
NotActiveException - If a object is not currently being read
public ObjectInputStream.GetField readFields()
throws IOException,
ClassNotFoundException
readFields in class ObjectInputStreamIOException - If an error occurs
ClassNotFoundException - If a class in the stream cannot be found
NotActiveException - If a object is not currently being read
public void registerValidation(ObjectInputValidation obj,
int prio)
throws NotActiveException,
InvalidObjectException
registerValidation in class ObjectInputStreamobj - the object to receive the validation callback.prio - controls the order of callbacks
NotActiveException - The stream is not currently reading objects
so it is invalid to register a callback.
InvalidObjectException - The validation object is null.
protected Constructor getSerializableConstructor(Class c)
throws IOException,
NoSuchMethodException
c - The class to fetch the constructor for
IOException - If an error occurs
NoSuchMethodException - If the first non-Serializable class does not have a no-arg
Constructor
protected Object newInstance(Class c)
throws IOException
c - The class to create a new instance of
IOException - If an error occurs
protected Class getClass(String name)
throws ClassNotFoundException
name - The name of the class to return
ClassNotFoundException - If the class cannot be found
protected void putReference(String reference,
Object o)
reference - The reference name to useo - The object to referenceprotected Object getReference(String reference)
reference - The reference to use
protected String readPrimitive(String type)
throws IOException
type - The type of primitive which should be next
IOException - If an error occurs
protected int readIntHelper()
throws IOException
type - The type of primitive which should be next
IOException - If an error occurs
protected boolean readBooleanHelper()
throws IOException
type - The type of primitive which should be next
IOException - If an error occurs
protected byte readByteHelper()
throws IOException
type - The type of primitive which should be next
IOException - If an error occurs
protected char readCharHelper()
throws IOException
type - The type of primitive which should be next
IOException - If an error occurs
protected double readDoubleHelper()
throws IOException
type - The type of primitive which should be next
IOException - If an error occurs
protected float readFloatHelper()
throws IOException
type - The type of primitive which should be next
IOException - If an error occurs
protected long readLongHelper()
throws IOException
type - The type of primitive which should be next
IOException - If an error occurs
protected short readShortHelper()
throws IOException
type - The type of primitive which should be next
IOException - If an error occurs
protected Object readObjectHelper()
throws IOException,
ClassNotFoundException
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected Object readUnsharedHelper(boolean shared)
throws IOException,
ClassNotFoundException
shared - Whether or not to record a reference to this object
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected Object readReference()
throws IOException,
ClassNotFoundException
IOException - If an error occurs or if a reference is not found
ClassNotFoundException - If the class cannot be found
protected Object readNull()
throws IOException,
ClassNotFoundException
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected Object readString(boolean shared)
throws IOException,
ClassNotFoundException
shared - Whether or not to add this string to the references table
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected Object readOrdinaryObject(boolean shared)
throws IOException,
ClassNotFoundException
shared - Whether or not to record a reference to this object
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
NotSerializableException - If the class to be deserialized is not Serializable
protected Object readClass(Object o)
throws IOException,
ClassNotFoundException
o - The object we are reading the the class for
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected void readUnreadOptionalData()
throws IOException,
ClassNotFoundException
o - The object we are reading the the class for
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected XMLObjectInputStream.GetField readGetFields()
throws IOException,
ClassNotFoundException
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected void readGetField(XMLObjectInputStream.GetField g)
throws IOException,
ClassNotFoundException
g - The GetField object into which the field should be put
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected void readPrimitiveGetField(XMLObjectInputStream.GetField g)
throws IOException,
ClassNotFoundException
g - The GetField object to put the primitive in
IOException - If an error occurs
ClassNotFoundException
protected void readFields(Object o,
Class c)
throws IOException,
ClassNotFoundException
o - The object which is currently being read inc - The class to read the fields for
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected void readField(Object o,
Class c)
throws IOException,
ClassNotFoundException
o - The object which is currently being read inc - The class to read the fields for
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected void readPrimitiveField(Object o,
Field f)
throws IOException,
IllegalAccessException
o - The object to put the primitive inf - The field representing the primitive about to be read
IOException - If an error occurs
IllegalAccessException
protected Object readArray(boolean shared)
throws IOException,
ClassNotFoundException
shared - Whether or not to add this array to the references table
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||