@CodeReview(reviewer="Kevin R. Dixon",date="2008-12-02",changesNeeded=false,comments={"Minor cosmetic changes.","Otherwise, this wrapper class is fine."}) @CodeReview(reviewer="Kevin R. Dixon",date="2008-02-08",changesNeeded=false,comments={"Changed the read() method to close the stream it creates after reading.","Minor formatting change, and fixed a few typos.","Added PublicationReference for the Object Streams Tutorial.","Otherwise, looks fine."}) @PublicationReference(author="XStream Documentation", title="Object Streams Tutorial", type=WebPage, year=2008, url="http://xstream.codehaus.org/objectstream.html") @SoftwareReference(name="XStream", version="1.2.1", url="http://xstream.codehaus.org/", license=BSD, licenseURL="http://xstream.codehaus.org/") public class XStreamSerializationHandler extends java.lang.Object
KNOWN LIMITATION: The read() method will thrown an exception "java.io.IOException: com.thoughtworks.xstream.io.StreamException: : input contained no data" when trying to read the SECOND object from an XML InputStream/Reader. This is because XML files must have a single root node (which would be the FIRST object in the file), and anything after the close of the root node (the SECOND object) is considered invalid or nonexistent. To address the limitation, refer to http://xstream.codehaus.org/objectstream.html
Constructor and Description |
---|
XStreamSerializationHandler() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
convertFromString(java.lang.String string)
Attempts to read an Object from the given string.
|
static java.lang.String |
convertToString(java.io.Serializable object)
Writes the given object to a String.
|
static java.lang.Object |
read(java.io.InputStream stream)
Reads an Object from the given InputStream.
|
static java.lang.Object |
read(java.io.Reader reader)
Reads an Object from the given Reader.
|
static java.lang.Object |
readFromFile(java.io.File file)
Reads an Object from the given file name.
|
static java.lang.Object |
readFromFile(java.lang.String fileName)
Reads an Object from the given file name.
|
static boolean |
write(java.io.OutputStream stream,
java.io.Serializable object)
Writes the given object to the given OutputStream
|
static boolean |
write(java.io.Writer writer,
java.io.Serializable object)
Writes the given object to the given Writer
|
static void |
writeToFile(java.io.File file,
java.io.Serializable object)
Writes the given object to the given file using XStream serialization.
|
static void |
writeToFile(java.lang.String fileName,
java.io.Serializable object)
Writes the given object to the given file using XStream serialization.
|
public static boolean write(java.io.OutputStream stream, java.io.Serializable object) throws java.io.IOException
stream
- OutputStream to write the object toobject
- Object to write to the OutputStreamjava.io.IOException
- If there's a problem writingpublic static boolean write(java.io.Writer writer, java.io.Serializable object) throws java.io.IOException
writer
- Writer to write the object toobject
- Object to write to the Writerjava.io.IOException
- If there's a problem writingpublic static void writeToFile(java.lang.String fileName, java.io.Serializable object) throws java.io.IOException
fileName
- The file to write to.object
- The object to write.java.io.IOException
- If there is an error in writing.public static void writeToFile(java.io.File file, java.io.Serializable object) throws java.io.IOException
file
- The file to write to.object
- The object to write.java.io.IOException
- If there is an error in writing.public static java.lang.Object readFromFile(java.lang.String fileName) throws java.io.IOException
KNOWN LIMITATION: This method will thrown an exception "java.io.IOException: com.thoughtworks.xstream.io.StreamException: : input contained no data" when trying to read the SECOND object from an XML InputStream/Reader. This is because XML files must have a single root node (which would be the FIRST object in the file), and anything after the close of the root node (the SECOND object) is considered invalid or inexistent. To address the limitation, refer to http://xstream.codehaus.org/objectstream.html
fileName
- The name of the file to read from.java.io.IOException
- if an Object can't be deserialized from the reader (See LIMITATION above)public static java.lang.Object readFromFile(java.io.File file) throws java.io.IOException
KNOWN LIMITATION: This method will thrown an exception "java.io.IOException: com.thoughtworks.xstream.io.StreamException: : input contained no data" when trying to read the SECOND object from an XML InputStream/Reader. This is because XML files must have a single root node (which would be the FIRST object in the file), and anything after the close of the root node (the SECOND object) is considered invalid or inexistent. To address the limitation, refer to http://xstream.codehaus.org/objectstream.html
file
- The file to read from.java.io.IOException
- if an Object can't be deserialized from the reader (See LIMITATION above)public static java.lang.Object read(java.io.InputStream stream) throws java.io.IOException
KNOWN LIMITATION: This method will thrown an exception "java.io.IOException: com.thoughtworks.xstream.io.StreamException: : input contained no data" when trying to read the SECOND object from an XML InputStream/Reader. This is because XML files must have a single root node (which would be the FIRST object in the file), and anything after the close of the root node (the SECOND object) is considered invalid or inexistent. To address the limitation, refer to http://xstream.codehaus.org/objectstream.html
stream
- InputStream from which to readjava.io.IOException
- if an Object can't be deserialized from the reader (See LIMITATION above)public static java.lang.Object read(java.io.Reader reader) throws java.io.IOException
reader
- Reader from which to readjava.io.IOException
- if an Object can't be deserialized from the reader (See LIMITATION above)public static java.lang.String convertToString(java.io.Serializable object) throws java.io.IOException
object
- Object to write to the String.java.io.IOException
- If there's a problem writing.public static java.lang.Object convertFromString(java.lang.String string) throws java.io.IOException
string
- The String containing the XStream version of the object.java.io.IOException
- If there is a problem reading.