JSX
Class ObjectWriter

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.ObjectOutputStream
              |
              +--JSX.ObjectWriter
All Implemented Interfaces:
DataOutput, ObjectOutput, ObjectStreamConstants

public class ObjectWriter
extends ObjectOutputStream

ObjectWriter can be used in place of ObjectOutputStream, to serialize object graphs to XML, instead of the binary format. It implements all the core features of ObjectOutputStream. ObjectWriter does not require classes to implement java.io.Serialization, nor is serialVersionUID needed for class evolution.

See Also:
Object Serialization Specification, Section 2, Object Output Classes

Nested Class Summary
 class ObjectWriter.PutFieldImpl
           
 
Field Summary
 
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
ObjectWriter()
          Writes to System.out (convenient for testing)
ObjectWriter(JSX.DataWriterI dataWriter)
          For output other than XML (or to different XML formats)
ObjectWriter(OutputStream outputStream)
           
ObjectWriter(Writer writer)
           
 
Method Summary
protected  void annotateClass(Class cl)
          Not implemented
 void close()
           
 void defaultWriteObject()
           
 void disableExternalization()
           
protected  void drain()
          Not implemented
protected  boolean enableReplaceObject(boolean enable)
          Not implemented
 void flush()
           
 JSX.Alias getHash()
           
static void main(String[] args)
          USAGE: java JSX.ObjectWriter className (defaults to JSX.Person)
 ObjectOutputStream.PutField putFields()
           
protected  Object replaceObject(Object obj)
          now implemented
 void reset()
           
 void setAutoClose(boolean autoClose)
          (extension) For more than one writeObject() call in the one ObjectWriter, forming a single XML document.
 void setEmbedded(boolean embedded)
          (extension) For embedding within a SOAP envelope, or any other enclosing XML.
 void setPrettyPrint(boolean prettyPrint)
          (extension) Set to false to turn off indentation and newlines
 void useProtocolVersion(int version)
          Not implemented
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeBoolean(boolean v)
           
 void writeByte(int v)
           
 void writeBytes(String s)
           
 void writeChar(int v)
           
 void writeChars(String s)
           
protected  void writeClassDescriptor(ObjectStreamClass desc)
          Not implemented
 void writeDouble(double v)
           
 void writeFields()
           
 void writeFloat(float v)
           
 void writeInt(int v)
           
 void writeLong(long v)
           
 void writeObjectOverride(Object object)
           
 void writeShort(int v)
           
protected  void writeStreamHeader()
          Not implemented
 void writeUnshared(Object obj)
           
 void writeUTF(String str)
           
 
Methods inherited from class java.io.ObjectOutputStream
annotateProxyClass, writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectWriter

public ObjectWriter()
             throws IOException
Writes to System.out (convenient for testing)


ObjectWriter

public ObjectWriter(OutputStream outputStream)
             throws IOException

ObjectWriter

public ObjectWriter(JSX.DataWriterI dataWriter)
             throws IOException
For output other than XML (or to different XML formats)


ObjectWriter

public ObjectWriter(Writer writer)
             throws IOException
Method Detail

main

public static void main(String[] args)
                 throws Exception
USAGE: java JSX.ObjectWriter className (defaults to JSX.Person)

Exception

setPrettyPrint

public void setPrettyPrint(boolean prettyPrint)
(extension) Set to false to turn off indentation and newlines


flush

public void flush()
           throws IOException
Specified by:
flush in interface ObjectOutput
Overrides:
flush in class ObjectOutputStream
IOException

close

public void close()
           throws IOException
Specified by:
close in interface ObjectOutput
Overrides:
close in class ObjectOutputStream
IOException

reset

public void reset()
           throws IOException
Overrides:
reset in class ObjectOutputStream
IOException

writeBoolean

public void writeBoolean(boolean v)
                  throws IOException
Specified by:
writeBoolean in interface DataOutput
Overrides:
writeBoolean in class ObjectOutputStream
IOException

writeByte

public void writeByte(int v)
               throws IOException
Specified by:
writeByte in interface DataOutput
Overrides:
writeByte in class ObjectOutputStream
IOException

writeShort

public void writeShort(int v)
                throws IOException
Specified by:
writeShort in interface DataOutput
Overrides:
writeShort in class ObjectOutputStream
IOException

writeInt

public void writeInt(int v)
              throws IOException
Specified by:
writeInt in interface DataOutput
Overrides:
writeInt in class ObjectOutputStream
IOException

writeLong

public void writeLong(long v)
               throws IOException
Specified by:
writeLong in interface DataOutput
Overrides:
writeLong in class ObjectOutputStream
IOException

writeFloat

public void writeFloat(float v)
                throws IOException
Specified by:
writeFloat in interface DataOutput
Overrides:
writeFloat in class ObjectOutputStream
IOException

writeDouble

public void writeDouble(double v)
                 throws IOException
Specified by:
writeDouble in interface DataOutput
Overrides:
writeDouble in class ObjectOutputStream
IOException

writeChar

public void writeChar(int v)
               throws IOException
Specified by:
writeChar in interface DataOutput
Overrides:
writeChar in class ObjectOutputStream
IOException

writeUTF

public void writeUTF(String str)
              throws IOException
Specified by:
writeUTF in interface DataOutput
Overrides:
writeUTF in class ObjectOutputStream
IOException

writeBytes

public void writeBytes(String s)
                throws IOException
Specified by:
writeBytes in interface DataOutput
Overrides:
writeBytes in class ObjectOutputStream
IOException

writeChars

public void writeChars(String s)
                throws IOException
Specified by:
writeChars in interface DataOutput
Overrides:
writeChars in class ObjectOutputStream
IOException

write

public void write(int b)
           throws IOException
Specified by:
write in interface ObjectOutput
Overrides:
write in class ObjectOutputStream
IOException

write

public void write(byte[] b)
           throws IOException
Specified by:
write in interface ObjectOutput
Overrides:
write in class ObjectOutputStream
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Specified by:
write in interface ObjectOutput
Overrides:
write in class ObjectOutputStream
IOException

writeUnshared

public void writeUnshared(Object obj)
                   throws IOException
Overrides:
writeUnshared in class ObjectOutputStream
IOException

replaceObject

protected Object replaceObject(Object obj)
                        throws IOException
now implemented

Overrides:
replaceObject in class ObjectOutputStream
IOException

enableReplaceObject

protected boolean enableReplaceObject(boolean enable)
                               throws SecurityException
Not implemented

Overrides:
enableReplaceObject in class ObjectOutputStream
SecurityException

annotateClass

protected void annotateClass(Class cl)
                      throws IOException
Not implemented

Overrides:
annotateClass in class ObjectOutputStream
IOException

writeClassDescriptor

protected void writeClassDescriptor(ObjectStreamClass desc)
                             throws IOException
Not implemented

Overrides:
writeClassDescriptor in class ObjectOutputStream
IOException

writeStreamHeader

protected void writeStreamHeader()
                          throws IOException
Not implemented

Overrides:
writeStreamHeader in class ObjectOutputStream
IOException

drain

protected void drain()
              throws IOException
Not implemented

Overrides:
drain in class ObjectOutputStream
IOException

useProtocolVersion

public void useProtocolVersion(int version)
                        throws IOException
Not implemented

Overrides:
useProtocolVersion in class ObjectOutputStream
IOException

setAutoClose

public void setAutoClose(boolean autoClose)
(extension) For more than one writeObject() call in the one ObjectWriter, forming a single XML document. by default, JSX only allows one writeObject() call, and it automatically closes the XML document with a </jsx> close tag. If you need more than one writeObject() call in the one document (eg for streaming over a socket), then use setAutoClose(false) to switch off this feature. Note that you will need to explicitly call close() yourself when you have made the last writeObject(), and you need a close tag, which is necessary for a "well-formed" XML document


setEmbedded

public void setEmbedded(boolean embedded)
(extension) For embedding within a SOAP envelope, or any other enclosing XML. It causes the XML declaration ( <?xml ... ?> ) to be omitted.


writeObjectOverride

public void writeObjectOverride(Object object)
                         throws IOException
Overrides:
writeObjectOverride in class ObjectOutputStream
IOException

getHash

public JSX.Alias getHash()

disableExternalization

public void disableExternalization()

defaultWriteObject

public void defaultWriteObject()
                        throws IOException
Overrides:
defaultWriteObject in class ObjectOutputStream
IOException

putFields

public ObjectOutputStream.PutField putFields()
                                      throws IOException
Overrides:
putFields in class ObjectOutputStream
IOException

writeFields

public void writeFields()
                 throws IOException
Overrides:
writeFields in class ObjectOutputStream
IOException