|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
java.io.ObjectOutputStream
rice.p2p.util.XMLObjectOutputStream
public class 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 Stack |
currentClasses
The stack of classes which are currently being written to the stream |
protected Stack |
currentObjects
The stack of objects which are currently being written to the stream |
protected 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 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 |
| Constructor Summary | |
|---|---|
XMLObjectOutputStream(OutputStream out)
Constructor which writes data from the given output stream in order serialize objects. |
|
| Method Summary | |
|---|---|
protected 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 Class |
getComponentType(Class array)
Method which returns the component type of the given array class. |
protected int |
getDimension(Class array)
Method which returns the dimension of the given array class. |
protected Field[] |
getPersistentFields(Class cl)
Method which returns the serializable fields of the provided class. |
protected String |
getReference(Object o)
Method which returns a previously stored reference. |
protected Field[] |
getSerialPersistentFields(Class c)
Method which returns the serializablePersistenFields field of the provided class. |
protected Class[] |
getSuperClasses(Class c)
Method which returns an array of classes representing the class hierarchy of the provided class, exempting the Object class. |
protected int |
hash(Object o)
Method which determines a unique hash value for each object. |
ObjectOutputStream.PutField |
putFields()
Method which can be called by objects if they have a writeObject() method. |
protected void |
putReference(Object o,
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(Object o,
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(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(String s)
Method which writes a String as a sequence of chars to the stream. |
protected void |
writeClass(Object o,
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(Object o,
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(String field)
Method which writes a null item to the stream as the provided field. |
protected void |
writeObject(Object o,
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(Object o)
Method which is called by ObjectOutputStream.writeObject(), and writes the given object to the stream. |
protected void |
writeObjectUnshared(Object o,
String field,
boolean shared)
Method which writes an object to the stream. |
protected void |
writeOrdinaryObject(Object o,
String field,
boolean shared)
Method which writes an ordinary object to the stream (not a String or Array). |
protected void |
writePrimitive(boolean b,
String field)
Method which writes a boolean to the stream, as the given field name. |
protected void |
writePrimitive(byte b,
String field)
Method which writes a byte to the stream, as the given field name. |
protected void |
writePrimitive(char c,
String field)
Method which writes a char to the stream, as the given field name. |
protected void |
writePrimitive(double d,
String field)
Method which writes a double to the stream, as the given field name. |
protected void |
writePrimitive(float f,
String field)
Method which writes a float to the stream, as the given field name. |
protected void |
writePrimitive(int i,
String field)
Method which writes a int to the stream, as the given field name. |
protected void |
writePrimitive(long l,
String field)
Method which writes a long to the stream, as the given field name. |
protected void |
writePrimitive(short s,
String field)
Method which writes a short to the stream, as the given field name. |
protected void |
writePrimitiveField(Object o,
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(Object o,
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(String s,
String field,
boolean shared)
Method which writes a string to the stream as the provided field. |
void |
writeUnshared(Object o)
Method which writes the given object to the stream and does not record a reference to the object. |
void |
writeUTF(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 static SoftHashMap WRITE_REPLACES
protected static SoftHashMap WRITE_OBJECTS
protected static SoftHashMap PERSISTENT_FIELDS
protected XMLWriter writer
protected Hashtable references
protected int next
protected Stack currentObjects
protected Stack currentClasses
protected Stack currentPutFields
| Constructor Detail |
|---|
public XMLObjectOutputStream(OutputStream out)
throws IOException
out - The output stream to write data to
IOException - If the an error occurs| Method Detail |
|---|
protected void writeStreamHeader()
throws IOException
writeStreamHeader in class ObjectOutputStreamIOException - If an error occurs
public void flush()
throws IOException
flush in interface Flushableflush in interface ObjectOutputflush in class ObjectOutputStreamIOException - if an error occurs
public void close()
throws IOException
close in interface Closeableclose in interface ObjectOutputclose in class ObjectOutputStreamIOException
public void reset()
throws IOException
reset in class ObjectOutputStreamIOException - If an error occurs, or an object is currently being written
public void write(byte b)
throws IOException
IOException - If an error occurs
public void write(byte[] b)
throws IOException
write in interface DataOutputwrite in interface ObjectOutputwrite in class ObjectOutputStreamIOException - If an error occurs
public void write(byte[] b,
int offset,
int length)
throws IOException
write in interface DataOutputwrite in interface ObjectOutputwrite in class ObjectOutputStreamIOException - If an error occurs
public void writeInt(int i)
throws IOException
writeInt in interface DataOutputwriteInt in class ObjectOutputStreami - The value to write to the stream
IOException - If an error occurs
public void writeBoolean(boolean b)
throws IOException
writeBoolean in interface DataOutputwriteBoolean in class ObjectOutputStreamb - The value to write to the stream
IOException - If an error occurs
public void writeByte(int i)
throws IOException
writeByte in interface DataOutputwriteByte in class ObjectOutputStreami - The value to write to the stream, casted to a byte
IOException - If an error occurs
public void writeByte(byte b)
throws IOException
b - The value to write to the stream
IOException - If an error occurs
public void writeChar(int i)
throws IOException
writeChar in interface DataOutputwriteChar in class ObjectOutputStreami - The value to write to the stream, casted to an int
IOException - If an error occurs
public void writeChar(char c)
throws IOException
c - The value to write to the stream
IOException - If an error occurs
public void writeDouble(double d)
throws IOException
writeDouble in interface DataOutputwriteDouble in class ObjectOutputStreamd - The value to write to the stream
IOException - If an error occurs
public void writeFloat(float f)
throws IOException
writeFloat in interface DataOutputwriteFloat in class ObjectOutputStreamf - The value to write to the stream
IOException - If an error occurs
public void writeLong(long l)
throws IOException
writeLong in interface DataOutputwriteLong in class ObjectOutputStreaml - The value to write to the stream
IOException - If an error occurs
public void writeShort(int i)
throws IOException
writeShort in interface DataOutputwriteShort in class ObjectOutputStreami - The value to write to the stream, casted to a short
IOException - If an error occurs
public void writeShort(short s)
throws IOException
s - The value to write to the stream
IOException - If an error occurs
public void writeUTF(String s)
throws IOException
writeUTF in interface DataOutputwriteUTF in class ObjectOutputStreamIOException - If an error occurs
public void writeChars(String s)
throws IOException
writeChars in interface DataOutputwriteChars in class ObjectOutputStreamIOException - If an error occurs
public void writeBytes(String s)
throws IOException
writeBytes in interface DataOutputwriteBytes in class ObjectOutputStreamIOException - If an error occurs
public void writeObjectOverride(Object o)
throws IOException
writeObjectOverride in class ObjectOutputStreamo - The value to write to the stream
IOException - If an error occurs
public void writeUnshared(Object o)
throws IOException
writeUnshared in class ObjectOutputStreamo - The value to write to the stream
IOException - If an error occurs
public void defaultWriteObject()
throws IOException
defaultWriteObject in class ObjectOutputStreamIOException - If an error occurs
NotActiveException - If a object is not currently being written
public ObjectOutputStream.PutField putFields()
throws IOException
putFields in class ObjectOutputStreamIOException - If an error occurs
NotActiveException - If a object is not currently being read
public void writeFields()
throws IOException
writeFields in class ObjectOutputStreamIOException - If an error occurs
NotActiveException - If a object is not currently being readprotected Field[] getPersistentFields(Class cl)
c - The class to return the fields forprotected Field[] getSerialPersistentFields(Class c)
c - The class to return the fields forprotected Class getComponentType(Class array)
protected int getDimension(Class array)
protected Class[] getSuperClasses(Class c)
c - The class to return the heirarchy for
protected int hash(Object o)
protected void putReference(Object o,
String reference)
o - The object to referencereference - The reference name to useprotected String getReference(Object o)
o - The object to look up
protected String assignReference()
protected void writeReset()
throws IOException
IOException - If an error occurs
protected void writeObject(Object o,
String field)
throws IOException
o - The object to write to the streamfield - The field name to write the object as
IOException - If an error occurs
ClassNotFoundException - If the class cannot be found
protected void writeObjectUnshared(Object o,
String field,
boolean shared)
throws 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
IOException - If an error occurs
protected void writeNull(String field)
throws IOException
field - The field name to write the object as
IOException - If an error occurs
protected void writeString(String s,
String field,
boolean shared)
throws 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
IOException - If an error occurs
protected void writeArray(Object o,
String field,
boolean shared)
throws 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
IOException - If an error occurs
protected void writeReference(Object o,
String field)
throws IOException
o - The object to write to the streamfield - The field name to write the object as
IOException - If an error occurs
protected void writeOrdinaryObject(Object o,
String field,
boolean shared)
throws 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
IOException - If an error occurs
NotSerializableException - If the object is not serializable
protected void writeClass(Object o,
Class c)
throws IOException
o - The object to write to the streamc - The class of the object to write
IOException - If an error occurs
protected void writeFields(Object o,
Class c)
throws IOException
o - The object to write to the streamc - The class of the object to write
IOException - If an error occurs
protected void writePutFields(XMLObjectOutputStream.PutField p)
throws IOException
p - The fields to write to the stream
IOException - If an error occurs
protected void writePrimitiveField(Object o,
Field f)
throws IOException
o - The object get the primitive fromf - The field representing the primitive about to be written
IOException - If an error occurs
protected void writePrimitive(int i,
String field)
throws IOException
i - The value to write to the streamfield - The field name to use
IOException - If an error occurs
protected void writePrimitive(boolean b,
String field)
throws IOException
b - The value to write to the streamfield - The field name to use
IOException - If an error occurs
protected void writePrimitive(byte b,
String field)
throws IOException
b - The value to write to the streamfield - The field name to use
IOException - If an error occurs
protected void writePrimitive(char c,
String field)
throws IOException
c - The value to write to the streamfield - The field name to use
IOException - If an error occurs
protected void writePrimitive(double d,
String field)
throws IOException
d - The value to write to the streamfield - The field name to use
IOException - If an error occurs
protected void writePrimitive(float f,
String field)
throws IOException
f - The value to write to the streamfield - The field name to use
IOException - If an error occurs
protected void writePrimitive(long l,
String field)
throws IOException
l - The value to write to the streamfield - The field name to use
IOException - If an error occurs
protected void writePrimitive(short s,
String field)
throws IOException
s - The value to write to the streamfield - The field name to use
IOException - If an error occurs
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||