|
Rice Pastry API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream java.io.ObjectOutputStream rice.p2p.util.XMLObjectOutputStream
XMLObjectOutputStream is an extension of ObjectOutputStream which provides for serialization for arbitrary Java objects, in the same manner as the ObjectOutputStream class. This class supports all of the features of the ObjectOutputStream, including serialization support for any Java object graph implementing the Serializable interface, maintenance of references in the object graph, support for Externalizable classes, custom serialization via the writeObject() method, alternate field writing mechanisms via the putFields() and writeFields() methods, support for the writeUnshared() method, custom serializable field specification via the serialPersistentFields field, and dynamic object replacement via the writeReplace() method. The format of the XML data written does conform to the JSX XML Schema, available online at http://www.jsx.org/jsx.xsd. This class is designed to be able to write objects which can then be deserialized using JSX, however, this has not been fully tested and bugs may be encountered.
Nested Class Summary | |
class |
XMLObjectOutputStream.PutField
This class is an implementation of PutField which is compatible with the XMLObjectOutputStream. |
Field Summary | |
protected java.util.Stack |
currentClasses
The stack of classes which are currently being written to the stream |
protected java.util.Stack |
currentObjects
The stack of objects which are currently being written to the stream |
protected java.util.Stack |
currentPutFields
The stack of putFields which are currently being written to the stream |
protected int |
next
A counter used to generate unique references |
protected static SoftHashMap |
PERSISTENT_FIELDS
A cache of the persistentFields, mapping class->Field[] |
protected java.util.Hashtable |
references
The collection of references stored in the stream so far, maps Integer(hash) -> reference name. |
protected static SoftHashMap |
WRITE_OBJECTS
A cache of the writeObject() methods, mapping class->writeObject() |
protected static SoftHashMap |
WRITE_REPLACES
A cache of the writeReplace() methods, mapping class->writeReplace() |
protected XMLWriter |
writer
The underlying XML writing engine |
Fields inherited from interface java.io.ObjectStreamConstants |
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING |
Constructor Summary | |
XMLObjectOutputStream(java.io.OutputStream out)
Constructor which writes data from the given output stream in order serialize objects. |
Method Summary | |
protected java.lang.String |
assignReference()
Method which assigns a new unique reference. |
void |
close()
Method which closes the underlying output stream for writing. |
void |
defaultWriteObject()
Method which can be called by objects if they have a writeObject() method. |
void |
flush()
Method which flushes all buffered data to the output stream. |
protected java.lang.Class |
getComponentType(java.lang.Class array)
Method which returns the component type of the given array class. |
protected int |
getDimension(java.lang.Class array)
Method which returns the dimension of the given array class. |
protected java.lang.reflect.Field[] |
getPersistentFields(java.lang.Class cl)
Method which returns the serializable fields of the provided class. |
protected java.lang.String |
getReference(java.lang.Object o)
Method which returns a previously stored reference. |
protected java.lang.reflect.Field[] |
getSerialPersistentFields(java.lang.Class c)
Method which returns the serializablePersistenFields field of the provided class. |
protected java.lang.Class[] |
getSuperClasses(java.lang.Class c)
Method which returns an array of classes representing the class hierarchy of the provided class, exempting the Object class. |
protected int |
hash(java.lang.Object o)
Method which determines a unique hash value for each object. |
java.io.ObjectOutputStream.PutField |
putFields()
Method which can be called by objects if they have a writeObject() method. |
protected void |
putReference(java.lang.Object o,
java.lang.String reference)
Method which adds a reference in the hashtable of references. |
void |
reset()
Method which resets the output stream, which removes the binding of all previously stored references. |
void |
write(byte b)
Method which writes a byte to the underlying output stream. |
void |
write(byte[] b)
Method which writes a array of bytes to the underlying output stream. |
void |
write(byte[] b,
int offset,
int length)
Method which writes a array of bytes to the underlying output stream. |
protected void |
writeArray(java.lang.Object o,
java.lang.String field,
boolean shared)
Method which writes an array to the stream. |
void |
writeBoolean(boolean b)
Method which writes an boolean to the stream. |
void |
writeByte(byte b)
Method which writes an byte to the stream. |
void |
writeByte(int i)
Method which writes an byte to the stream. |
void |
writeBytes(java.lang.String s)
Method which writes a String as a sequence of chars to the stream. |
void |
writeChar(char c)
Method which writes an char to the stream. |
void |
writeChar(int i)
Method which writes an char to the stream. |
void |
writeChars(java.lang.String s)
Method which writes a String as a sequence of chars to the stream. |
protected void |
writeClass(java.lang.Object o,
java.lang.Class c)
Method which writes the information for one class for a given object to the stream. |
void |
writeDouble(double d)
Method which writes an double to the stream. |
void |
writeFields()
Method which writes the current state of the PutField object to the stream as this object's fields. |
protected void |
writeFields(java.lang.Object o,
java.lang.Class c)
Method which initiates the default field writing mechanism for the given object's class. |
void |
writeFloat(float f)
Method which writes an float to the stream. |
void |
writeInt(int i)
Method which writes an int to the stream. |
void |
writeLong(long l)
Method which writes an long to the stream. |
protected void |
writeNull(java.lang.String field)
Method which writes a null item to the stream as the provided field. |
protected void |
writeObject(java.lang.Object o,
java.lang.String field)
Method which writes an object to the stream as the given field name If the next object represents a reference or null, then the appropriate helper is called. |
void |
writeObjectOverride(java.lang.Object o)
Method which is called by ObjectOutputStream.writeObject(), and writes the given object to the stream. |
protected void |
writeObjectUnshared(java.lang.Object o,
java.lang.String field,
boolean shared)
Method which writes an object to the stream. |
protected void |
writeOrdinaryObject(java.lang.Object o,
java.lang.String field,
boolean shared)
Method which writes an ordinary object to the stream (not a String or Array). |
protected void |
writePrimitive(boolean b,
java.lang.String field)
Method which writes a boolean to the stream, as the given field name. |
protected void |
writePrimitive(byte b,
java.lang.String field)
Method which writes a byte to the stream, as the given field name. |
protected void |
writePrimitive(char c,
java.lang.String field)
Method which writes a char to the stream, as the given field name. |
protected void |
writePrimitive(double d,
java.lang.String field)
Method which writes a double to the stream, as the given field name. |
protected void |
writePrimitive(float f,
java.lang.String field)
Method which writes a float to the stream, as the given field name. |
protected void |
writePrimitive(int i,
java.lang.String field)
Method which writes a int to the stream, as the given field name. |
protected void |
writePrimitive(long l,
java.lang.String field)
Method which writes a long to the stream, as the given field name. |
protected void |
writePrimitive(short s,
java.lang.String field)
Method which writes a short to the stream, as the given field name. |
protected void |
writePrimitiveField(java.lang.Object o,
java.lang.reflect.Field f)
Method which writes a primitive field to the stream. |
protected void |
writePutFields(XMLObjectOutputStream.PutField p)
Method which writes out the data from the given PutField class as the data for the given class. |
protected void |
writeReference(java.lang.Object o,
java.lang.String field)
Method which writes a reference to the stream, determined from the references table. |
protected void |
writeReset()
Method which writes a reset command to the stream. |
void |
writeShort(int i)
Method which writes an short to the stream. |
void |
writeShort(short s)
Method which writes an short to the stream. |
protected void |
writeStreamHeader()
Method which writes the XML header to the stream. |
protected void |
writeString(java.lang.String s,
java.lang.String field,
boolean shared)
Method which writes a string to the stream as the provided field. |
void |
writeUnshared(java.lang.Object o)
Method which writes the given object to the stream and does not record a reference to the object. |
void |
writeUTF(java.lang.String s)
Method which writes a UTF-encoded String to the stream. |
Methods inherited from class java.io.ObjectOutputStream |
annotateClass, annotateProxyClass, drain, enableReplaceObject, replaceObject, useProtocolVersion, write, writeClassDescriptor, writeObject |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected XMLWriter writer
protected java.util.Hashtable references
protected int next
protected java.util.Stack currentObjects
protected java.util.Stack currentClasses
protected java.util.Stack currentPutFields
protected static SoftHashMap WRITE_REPLACES
protected static SoftHashMap WRITE_OBJECTS
protected static SoftHashMap PERSISTENT_FIELDS
Constructor Detail |
public XMLObjectOutputStream(java.io.OutputStream out) throws java.io.IOException
out
- The output stream to write data to
java.io.IOException
- DESCRIBE THE EXCEPTION
java.io.IOException
- If the an error occursMethod Detail |
protected java.lang.reflect.Field[] getPersistentFields(java.lang.Class cl)
cl
- DESCRIBE THE PARAMETER
protected java.lang.reflect.Field[] getSerialPersistentFields(java.lang.Class c)
c
- The class to return the fields for
protected java.lang.Class getComponentType(java.lang.Class array)
array
- DESCRIBE THE PARAMETER
protected int getDimension(java.lang.Class array)
array
- DESCRIBE THE PARAMETER
protected java.lang.Class[] getSuperClasses(java.lang.Class c)
c
- The class to return the heirarchy for
protected java.lang.String getReference(java.lang.Object o)
o
- The object to look up
protected void writeStreamHeader() throws java.io.IOException
java.io.IOException
- If an error occurspublic void flush() throws java.io.IOException
java.io.IOException
- if an error occurspublic void close() throws java.io.IOException
java.io.IOException
- DESCRIBE THE EXCEPTIONpublic void reset() throws java.io.IOException
java.io.IOException
- If an error occurs, or an object is currently being
writtenpublic void write(byte b) throws java.io.IOException
b
- DESCRIBE THE PARAMETER
java.io.IOException
- If an error occurspublic void write(byte[] b) throws java.io.IOException
b
- DESCRIBE THE PARAMETER
java.io.IOException
- If an error occurspublic void write(byte[] b, int offset, int length) throws java.io.IOException
b
- DESCRIBE THE PARAMETERoffset
- DESCRIBE THE PARAMETERlength
- DESCRIBE THE PARAMETER
java.io.IOException
- If an error occurspublic void writeInt(int i) throws java.io.IOException
i
- The value to write to the stream
java.io.IOException
- If an error occurspublic void writeBoolean(boolean b) throws java.io.IOException
b
- The value to write to the stream
java.io.IOException
- If an error occurspublic void writeByte(int i) throws java.io.IOException
i
- The value to write to the stream, casted to a byte
java.io.IOException
- If an error occurspublic void writeByte(byte b) throws java.io.IOException
b
- The value to write to the stream
java.io.IOException
- If an error occurspublic void writeChar(int i) throws java.io.IOException
i
- The value to write to the stream, casted to an int
java.io.IOException
- If an error occurspublic void writeChar(char c) throws java.io.IOException
c
- The value to write to the stream
java.io.IOException
- If an error occurspublic void writeDouble(double d) throws java.io.IOException
d
- The value to write to the stream
java.io.IOException
- If an error occurspublic void writeFloat(float f) throws java.io.IOException
f
- The value to write to the stream
java.io.IOException
- If an error occurspublic void writeLong(long l) throws java.io.IOException
l
- The value to write to the stream
java.io.IOException
- If an error occurspublic void writeShort(int i) throws java.io.IOException
i
- The value to write to the stream, casted to a short
java.io.IOException
- If an error occurspublic void writeShort(short s) throws java.io.IOException
s
- The value to write to the stream
java.io.IOException
- If an error occurspublic void writeUTF(java.lang.String s) throws java.io.IOException
s
- DESCRIBE THE PARAMETER
java.io.IOException
- If an error occurspublic void writeChars(java.lang.String s) throws java.io.IOException
s
- DESCRIBE THE PARAMETER
java.io.IOException
- If an error occurspublic void writeBytes(java.lang.String s) throws java.io.IOException
s
- DESCRIBE THE PARAMETER
java.io.IOException
- If an error occurspublic void writeObjectOverride(java.lang.Object o) throws java.io.IOException
o
- The value to write to the stream
java.io.IOException
- If an error occurspublic void writeUnshared(java.lang.Object o) throws java.io.IOException
o
- The value to write to the stream
java.io.IOException
- If an error occurspublic void defaultWriteObject() throws java.io.IOException
java.io.IOException
- If an error occurs
java.io.NotActiveException
- If a object is not currently being writtenpublic java.io.ObjectOutputStream.PutField putFields() throws java.io.IOException
java.io.IOException
- If an error occurs
java.io.NotActiveException
- If a object is not currently being readpublic void writeFields() throws java.io.IOException
java.io.IOException
- If an error occurs
java.io.NotActiveException
- If a object is not currently being readprotected int hash(java.lang.Object o)
o
- DESCRIBE THE PARAMETER
protected void putReference(java.lang.Object o, java.lang.String reference)
o
- The object to referencereference
- The reference name to useprotected java.lang.String assignReference()
protected void writeReset() throws java.io.IOException
java.io.IOException
- If an error occursprotected void writeObject(java.lang.Object o, java.lang.String field) throws java.io.IOException
o
- The object to write to the streamfield
- The field name to write the object as
java.io.IOException
- If an error occurs
java.lang.ClassNotFoundException
- If the class cannot be foundprotected void writeObjectUnshared(java.lang.Object o, java.lang.String field, boolean shared) throws java.io.IOException
o
- The object to write to the streamfield
- The field name to write the object asshared
- Whether or not to record a reference to this object
java.io.IOException
- If an error occursprotected void writeNull(java.lang.String field) throws java.io.IOException
field
- The field name to write the object as
java.io.IOException
- If an error occursprotected void writeString(java.lang.String s, java.lang.String field, boolean shared) throws java.io.IOException
field
- The field name to write the object asshared
- Whether or not to record a reference to this objects
- DESCRIBE THE PARAMETER
java.io.IOException
- If an error occursprotected void writeArray(java.lang.Object o, java.lang.String field, boolean shared) throws java.io.IOException
o
- The object to write to the streamfield
- The field name to write the object asshared
- Whether or not to record a reference to this object
java.io.IOException
- If an error occursprotected void writeReference(java.lang.Object o, java.lang.String field) throws java.io.IOException
o
- The object to write to the streamfield
- The field name to write the object as
java.io.IOException
- If an error occursprotected void writeOrdinaryObject(java.lang.Object o, java.lang.String field, boolean shared) throws java.io.IOException
o
- The object to write to the streamfield
- The field name to write the object asshared
- Whether or not to record a reference to this object
java.io.IOException
- If an error occurs
java.io.NotSerializableException
- If the object is not serializableprotected void writeClass(java.lang.Object o, java.lang.Class c) throws java.io.IOException
o
- The object to write to the streamc
- The class of the object to write
java.io.IOException
- If an error occursprotected void writeFields(java.lang.Object o, java.lang.Class c) throws java.io.IOException
o
- The object to write to the streamc
- The class of the object to write
java.io.IOException
- If an error occursprotected void writePutFields(XMLObjectOutputStream.PutField p) throws java.io.IOException
p
- The fields to write to the stream
java.io.IOException
- If an error occursprotected void writePrimitiveField(java.lang.Object o, java.lang.reflect.Field f) throws java.io.IOException
o
- The object get the primitive fromf
- The field representing the primitive about to be written
java.io.IOException
- If an error occursprotected void writePrimitive(int i, java.lang.String field) throws java.io.IOException
i
- The value to write to the streamfield
- The field name to use
java.io.IOException
- If an error occursprotected void writePrimitive(boolean b, java.lang.String field) throws java.io.IOException
b
- The value to write to the streamfield
- The field name to use
java.io.IOException
- If an error occursprotected void writePrimitive(byte b, java.lang.String field) throws java.io.IOException
b
- The value to write to the streamfield
- The field name to use
java.io.IOException
- If an error occursprotected void writePrimitive(char c, java.lang.String field) throws java.io.IOException
c
- The value to write to the streamfield
- The field name to use
java.io.IOException
- If an error occursprotected void writePrimitive(double d, java.lang.String field) throws java.io.IOException
d
- The value to write to the streamfield
- The field name to use
java.io.IOException
- If an error occursprotected void writePrimitive(float f, java.lang.String field) throws java.io.IOException
f
- The value to write to the streamfield
- The field name to use
java.io.IOException
- If an error occursprotected void writePrimitive(long l, java.lang.String field) throws java.io.IOException
l
- The value to write to the streamfield
- The field name to use
java.io.IOException
- If an error occursprotected void writePrimitive(short s, java.lang.String field) throws java.io.IOException
s
- The value to write to the streamfield
- The field name to use
java.io.IOException
- If an error occurs
|
Rice Pastry API | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |