org.prevayler.foundation.serialization
Class XStreamSerializer

java.lang.Object
  extended by org.prevayler.foundation.serialization.XStreamSerializer
All Implemented Interfaces:
Serializer

public class XStreamSerializer
extends Object
implements Serializer

Writes and reads objects using XML. This serializer can be used for snapshots, journals or both.

This implementation requires the XStream Java and XML language binding framework which provides for Java object XML serialization.

Note that XStream has some dependencies of its own. It requires the standard XML API's (xml-apis.jar from the Apache Xerces2-j project or j2sdk1.4+) and an XML implementation (again, provided by Xerces2 or j2sdk1.4+).

To make XStream up to 10x faster, add XPP3 to the classpath. XStream has the concept of a HierarchicalStreamDriver and the default implementation for XStream is the highly performant XppDriver. However, XStream will fall back to the DomDriver if XPP3 is not found in the classpath making the XPP3 library entirely optional... well, not quite. See XSTR-71. The current decision in that issue forces XPP3 to be a required runtime dependency when using XStream unless one specifically configures another driver, such as the DomDriver.


Constructor Summary
XStreamSerializer()
          Use the default character encoding for XML serialization.
XStreamSerializer(String encoding)
          Use the specified character encoding for XML serialization.
 
Method Summary
protected  com.thoughtworks.xstream.XStream createXStream()
          Create a new XStream instance.
 Object readObject(InputStream stream)
          Read an object from a stream.
 void writeObject(OutputStream stream, Object object)
          Write an object to a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XStreamSerializer

public XStreamSerializer()
Use the default character encoding for XML serialization.


XStreamSerializer

public XStreamSerializer(String encoding)
Use the specified character encoding for XML serialization.

Method Detail

writeObject

public void writeObject(OutputStream stream,
                        Object object)
                 throws IOException
Description copied from interface: Serializer
Write an object to a stream. An implementation must ensure that the object is written completely before returning. An implementation is free to flush or close the given stream as it sees fit, but is not required to do either. An implementation can expect that the stream is already buffered, so additional buffering is not required for performance.

Specified by:
writeObject in interface Serializer
Throws:
IOException

readObject

public Object readObject(InputStream stream)
                  throws IOException,
                         ClassNotFoundException
Description copied from interface: Serializer
Read an object from a stream. An implementation is free to close the given stream as it sees fit, but is not required to do so. An implementation can expect that the stream is already buffered, so additional buffering is not required for performance.

Specified by:
readObject in interface Serializer
Throws:
IOException
ClassNotFoundException

createXStream

protected com.thoughtworks.xstream.XStream createXStream()
Create a new XStream instance. This must be a new instance because XStream instances are not threadsafe.



Copyright © 2001-2013. All Rights Reserved.