org.metasyntactic.io
Class XMLOutputStream
java.lang.Object
|
+--java.io.OutputStream
|
+--java.io.ObjectOutputStream
|
+--org.metasyntactic.io.XMLOutputStream
- All Implemented Interfaces:
- java.io.DataOutput, java.io.ObjectOutput, java.io.ObjectStreamConstants, XMLStreamConstants
- public class XMLOutputStream
- extends java.io.ObjectOutputStream
- implements XMLStreamConstants
An XMLOutputStream writes primitive data types and graphs of Java objects to
an OutputStream as well-formed, valid XML. Included in the DOCTYPE is a
reference to Stream.dtd. This DTD is not necessary, but does allow a
XML Parser to make sure that the XML was not damaged in a valid-breaking
manner.
The objects can be read (reconstituted) using an
XMLInputStream. Persistent storage of objects can be accomplished by using a
file for the stream. If the stream is a network socket stream, the objects
can be reconsituted on another host or in another process.
Only objects that support the java.io.Serializable interface can be written
to streams. The class of each serializable object is encoded including the
class name and signature of the class, the values of the object's fields and
arrays, and the closure of any other objects referenced from the initial
objects.
The method writeObject is used to write an object to the stream. Any object,
including Strings and arrays, is written with writeObject. Multiple objects
or primitives can be written to the stream. The objects must be read back
from the corresponding XMLInputstream with the same types and in the same
order as they were written.
Primitive data types can also be written to the stream using the appropriate
methods from DataOutput.
The default serialization mechanism for an object writes the class of the
object, the class signature, and the values of all non-transient and
non-static fields. References to other objects (except in transient or static
fields) cause those objects to be written also. Multiple references to a
single object are encoded using a reference sharing mechanism so that graphs
of objects can be restored to the same shape as when the original was
written.
Classes that require special handling during the serialization and
deserialization process must implement special methods with these exact
signatures:
private void readObject(java.io.ObjectInputStream stream)
throws IOException, ClassNotFoundException;
private void writeObject(java.io.ObjectOutputStream stream)
throws IOException
The writeObject method is responsible for writing the state of the object for
its particular class so that the corresponding readObject method can restore
it. The method does not need to concern itself with the state belonging to
the object's superclasses or subclasses. State is saved by writing the
individual fields to the XMLOutputStream using the writeObject method or by
using the methods for primitive data types supported by DataOutput.
Serialization does not write out the fields of any object that does not
implement the java.io.Serializable interface. Subclasses of Objects that are
not serializable can be serializable. In this case the non-serializable class
must have a no-arg constructor to allow its fields to be initialized. In this
case it is the responsibility of the subclass to save and restore the state
of the non-serializable class. It is frequently the case that the fields of
that class are accessible (public, package, or protected) or that there are
get and set methods that can be used to restore the state.
| Nested classes inherited from class java.io.ObjectOutputStream |
java.io.ObjectOutputStream.PutField |
| Fields inherited from interface org.metasyntactic.io.XMLStreamConstants |
ARRAY_ELEMENT, CLASS_DESCRIPTOR_ELEMENT, CLASS_ELEMENT, FIELD_ELEMENT, FIELDS_ELEMENT, ID_ATTRIBUTE, IDREF_ATTRIBUTE, LENGTH_ATTRIBUTE, NAME_ATTRIBUTE, NAME_SPACE_URI, NULL_ELEMENT, OBJECT_ELEMENT, PRIMITIVE_ARRAY_ELEMENT_SEPARATOR, PRIMITIVE_ELEMENT, REFERENCE_ELEMENT, RESET_ELEMENT, SERIAL_VERSION_UID_ATTRIBUTE, STREAM_ELEMENT, STRING_ELEMENT, TYPE_ATTRIBUTE, VALUE_ATTRIBUTE, VERSION_ATTRIBUTE |
| 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 |
| Methods inherited from class java.io.ObjectOutputStream |
annotateClass, annotateProxyClass, defaultWriteObject, drain, enableReplaceObject, putFields, replaceObject, useProtocolVersion, writeChar, writeClassDescriptor, writeFields, writeObject, writeShort, writeStreamHeader, writeUnshared |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
handleTable
protected final HandleTable handleTable
document
protected final org.w3c.dom.Document document
currentNode
protected org.w3c.dom.Node currentNode
out
protected final java.io.PrintStream out
domSerializer
protected final DOMSerializer domSerializer
VERSION
public static final java.lang.String VERSION
- See Also:
- Constant Field Values
VERSION_STRING
public static final java.lang.String VERSION_STRING
- See Also:
- Constant Field Values
EMPTY_CLASS_ARRAY
protected static final java.lang.Class[] EMPTY_CLASS_ARRAY
EMPTY_OBJECT_ARRAY
protected static final java.lang.Object[] EMPTY_OBJECT_ARRAY
replaceObjects
protected java.lang.Object[] replaceObjects
nextReplaceOffset
protected int nextReplaceOffset
WRITE_OBJECT_ARGS
protected static final java.lang.Class[] WRITE_OBJECT_ARGS
XMLOutputStream
public XMLOutputStream(java.io.OutputStream out)
throws java.io.IOException
XMLOutputStream
public XMLOutputStream(java.io.OutputStream out,
boolean indent)
throws java.io.IOException
getDocument
public org.w3c.dom.Document getDocument()
writeUTF
public void writeUTF(java.lang.String str)
throws java.io.IOException
- Specified by:
writeUTF in interface java.io.DataOutput- Overrides:
writeUTF in class java.io.ObjectOutputStream
java.io.IOException
writeChars
public void writeChars(java.lang.String s)
throws java.io.IOException
- Specified by:
writeChars in interface java.io.DataOutput- Overrides:
writeChars in class java.io.ObjectOutputStream
java.io.IOException
writeBytes
public void writeBytes(java.lang.String s)
throws java.io.IOException
- Specified by:
writeBytes in interface java.io.DataOutput- Overrides:
writeBytes in class java.io.ObjectOutputStream
java.io.IOException
writeDouble
public void writeDouble(double v)
throws java.io.IOException
- Specified by:
writeDouble in interface java.io.DataOutput- Overrides:
writeDouble in class java.io.ObjectOutputStream
java.io.IOException
writeDoubleInternal
protected org.w3c.dom.Element writeDoubleInternal(double v)
throws java.io.IOException
java.io.IOException
writeFloat
public void writeFloat(float v)
throws java.io.IOException
- Specified by:
writeFloat in interface java.io.DataOutput- Overrides:
writeFloat in class java.io.ObjectOutputStream
java.io.IOException
writeFloatInternal
protected org.w3c.dom.Element writeFloatInternal(float v)
throws java.io.IOException
java.io.IOException
writeLong
public void writeLong(long v)
throws java.io.IOException
- Specified by:
writeLong in interface java.io.DataOutput- Overrides:
writeLong in class java.io.ObjectOutputStream
java.io.IOException
writeLongInternal
protected org.w3c.dom.Element writeLongInternal(long v)
throws java.io.IOException
java.io.IOException
writeInt
public void writeInt(int v)
throws java.io.IOException
- Specified by:
writeInt in interface java.io.DataOutput- Overrides:
writeInt in class java.io.ObjectOutputStream
java.io.IOException
writeIntInternal
protected org.w3c.dom.Element writeIntInternal(int v)
throws java.io.IOException
java.io.IOException
writeChar
public void writeChar(long v)
writeChar
public void writeChar(char v)
throws java.io.IOException
java.io.IOException
writeCharInternal
protected org.w3c.dom.Element writeCharInternal(char v)
throws java.io.IOException
java.io.IOException
writeShort
public void writeShort(short v)
throws java.io.IOException
java.io.IOException
writeShortInternal
protected org.w3c.dom.Element writeShortInternal(int v)
throws java.io.IOException
java.io.IOException
writeByte
public void writeByte(int v)
throws java.io.IOException
- Specified by:
writeByte in interface java.io.DataOutput- Overrides:
writeByte in class java.io.ObjectOutputStream
java.io.IOException
writeByteInternal
protected org.w3c.dom.Element writeByteInternal(int v)
throws java.io.IOException
java.io.IOException
writeBoolean
public void writeBoolean(boolean v)
throws java.io.IOException
- Specified by:
writeBoolean in interface java.io.DataOutput- Overrides:
writeBoolean in class java.io.ObjectOutputStream
java.io.IOException
writeBooleanInternal
protected org.w3c.dom.Element writeBooleanInternal(boolean v)
throws java.io.IOException
java.io.IOException
close
public void close()
throws java.io.IOException
- Specified by:
close in interface java.io.ObjectOutput- Overrides:
close in class java.io.ObjectOutputStream
java.io.IOException
flush
public void flush()
throws java.io.IOException
- Specified by:
flush in interface java.io.ObjectOutput- Overrides:
flush in class java.io.ObjectOutputStream
java.io.IOException
reset
public void reset()
throws java.io.IOException
- Overrides:
reset in class java.io.ObjectOutputStream
java.io.IOException
resetInternal
protected org.w3c.dom.Element resetInternal()
write
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
- Specified by:
write in interface java.io.ObjectOutput- Overrides:
write in class java.io.ObjectOutputStream
java.io.IOException
write
public void write(byte[] b)
throws java.io.IOException
- Specified by:
write in interface java.io.ObjectOutput- Overrides:
write in class java.io.ObjectOutputStream
java.io.IOException
write
public void write(int b)
throws java.io.IOException
- Specified by:
write in interface java.io.ObjectOutput- Overrides:
write in class java.io.ObjectOutputStream
java.io.IOException
writeNullOrReferenceToRepeat
protected org.w3c.dom.Element writeNullOrReferenceToRepeat(java.lang.Object obj)
throws java.io.IOException
java.io.IOException
writeReference
protected org.w3c.dom.Element writeReference(int handle)
throws java.io.IOException
java.io.IOException
previouslyReplaced
protected int previouslyReplaced(java.lang.Object o)
addReplacement
protected void addReplacement(java.lang.Object orig,
java.lang.Object replacement)
previouslyWritten
protected int previouslyWritten(java.lang.Object o)
writeObjectInternal
protected org.w3c.dom.Element writeObjectInternal(java.lang.Object obj)
throws java.io.IOException
java.io.IOException
writeObjectOverride
protected void writeObjectOverride(java.lang.Object obj)
throws java.io.IOException
- Overrides:
writeObjectOverride in class java.io.ObjectOutputStream
java.io.IOException
writeNewClass
protected org.w3c.dom.Element writeNewClass(java.lang.Class clazz)
throws java.io.IOException
java.io.IOException
writeClassDescriptor
protected org.w3c.dom.Element writeClassDescriptor(ClassDescriptor desc)
throws java.io.IOException
java.io.IOException
writeSuperclassDescriptor
protected void writeSuperclassDescriptor(ClassDescriptor desc)
throws java.io.IOException
java.io.IOException
writeNewClassDescriptor
protected org.w3c.dom.Element writeNewClassDescriptor(ClassDescriptor desc)
throws java.io.IOException
java.io.IOException
writeFields
protected void writeFields(java.lang.reflect.Field[] fields)
throws java.io.IOException
java.io.IOException
writeFieldDescriptor
protected void writeFieldDescriptor(java.lang.reflect.Field field)
throws java.io.IOException
java.io.IOException
writeNewArray
protected org.w3c.dom.Element writeNewArray(java.lang.Object array)
throws java.io.IOException
java.io.IOException
writeNewObject
protected org.w3c.dom.Element writeNewObject(java.lang.Object obj)
throws java.io.IOException
java.io.IOException
defaultWriteObject
protected void defaultWriteObject(java.lang.Object obj,
ClassDescriptor currentClassDesc)
throws java.io.IOException
java.io.IOException
outputClassFields
protected void outputClassFields(java.lang.Object obj,
java.lang.Class clazz,
java.lang.reflect.Field[] fields)
throws java.io.IOException
java.io.IOException
hasWriteObjectMethod
protected boolean hasWriteObjectMethod(ClassDescriptor desc)
throws java.io.IOException
java.io.IOException
invokeObjectWriter
protected void invokeObjectWriter(java.lang.Object obj,
ClassDescriptor desc)
throws java.io.IOException
java.io.IOException
writeNewString
protected org.w3c.dom.Element writeNewString(java.lang.String string)
throws java.io.IOException
java.io.IOException
writeNull
protected org.w3c.dom.Element writeNull(java.lang.Object o)
throws java.io.IOException
java.io.IOException
main
public static void main(java.lang.String[] args)