Package weka.core.xml
Class XStream
- java.lang.Object
-
- weka.core.xml.XStream
-
- All Implemented Interfaces:
RevisionHandler
public class XStream extends java.lang.Object implements RevisionHandler
This class is a helper class for XML serialization using XStream . XStream does not need to be present, since the class-calls are done generically via Reflection.- Version:
- $Revision: 5562 $
- Author:
- Mark Hall (mhall{[at]}pentaho{[dot]}org)
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFILE_EXTENSIONthe extension for XStream files (including '.')
-
Constructor Summary
Constructors Constructor Description XStream()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.ObjectdeSerialize(java.lang.String xmlString)Deserializes an object from the supplied XML stringjava.lang.StringgetRevision()Returns the revision string.static booleanisPresent()returns whether XStream is present or not, i.e.static java.lang.Objectread(java.io.File file)reads the XML-serialized object from the given filestatic java.lang.Objectread(java.io.InputStream stream)reads the XML-serialized object from the given input streamstatic java.lang.Objectread(java.io.Reader r)reads the XML-serialized object from the given Readerstatic java.lang.Objectread(java.lang.String filename)reads the XML-serialized object from the given filestatic java.lang.Stringserialize(java.lang.Object toSerialize)Serializes the supplied object xmlstatic booleanwrite(java.io.File file, java.lang.Object o)write the XML-serialized object to the given filestatic booleanwrite(java.io.OutputStream stream, java.lang.Object o)writes the XML-serialized object to the given output streamstatic booleanwrite(java.io.Writer writer, java.lang.Object toSerialize)writes the XML-serialized object to the given Writerstatic booleanwrite(java.lang.String filename, java.lang.Object o)writes the XML-serialized object to the given file
-
-
-
Field Detail
-
FILE_EXTENSION
public static final java.lang.String FILE_EXTENSION
the extension for XStream files (including '.')- See Also:
- Constant Field Values
-
-
Method Detail
-
isPresent
public static boolean isPresent()
returns whether XStream is present or not, i.e. whether the classes are in the classpath or not- Returns:
- whether XStream is available
-
serialize
public static java.lang.String serialize(java.lang.Object toSerialize) throws java.lang.ExceptionSerializes the supplied object xml- Parameters:
toSerialize- the object to serialize- Returns:
- the serialized object as an XML string
- Throws:
java.lang.Exception- if something goes wrong
-
write
public static boolean write(java.lang.String filename, java.lang.Object o) throws java.lang.Exceptionwrites the XML-serialized object to the given file- Parameters:
filename- the file to serialize the object too- the object to write to the file- Returns:
- whether writing was successful or not
- Throws:
java.lang.Exception- if something goes wrong while writing to the file
-
write
public static boolean write(java.io.File file, java.lang.Object o) throws java.lang.Exceptionwrite the XML-serialized object to the given file- Parameters:
file- the file to serialize the object too- the object to write to the file- Returns:
- whether writing was successful or not
- Throws:
java.lang.Exception- if something goes wrong while writing to the file
-
write
public static boolean write(java.io.OutputStream stream, java.lang.Object o) throws java.lang.Exceptionwrites the XML-serialized object to the given output stream- Parameters:
stream- the output streamo- the object to write- Returns:
- true if everything goes ok
- Throws:
java.lang.Exception
-
write
public static boolean write(java.io.Writer writer, java.lang.Object toSerialize) throws java.lang.Exceptionwrites the XML-serialized object to the given Writer- Parameters:
writer- the Writero- the object to write- Returns:
- true if everything goes ok
- Throws:
java.lang.Exception
-
read
public static java.lang.Object read(java.lang.String filename) throws java.lang.Exceptionreads the XML-serialized object from the given file- Parameters:
filename- the file to deserialize the object from- Returns:
- the deserialized object
- Throws:
java.lang.Exception- if something goes wrong while reading from the file
-
read
public static java.lang.Object read(java.io.File file) throws java.lang.Exceptionreads the XML-serialized object from the given file- Parameters:
file- the file to deserialize the object from- Returns:
- the deserialized object
- Throws:
java.lang.Exception- if something goes wrong while reading from the file
-
read
public static java.lang.Object read(java.io.InputStream stream) throws java.lang.Exceptionreads the XML-serialized object from the given input stream- Parameters:
stream- the input stream- Returns:
- the deserialized object
- Throws:
java.lang.Exception- if something goes wrong while reading from stream
-
read
public static java.lang.Object read(java.io.Reader r) throws java.lang.Exceptionreads the XML-serialized object from the given Reader- Parameters:
r- the reader- Returns:
- the deserialized object
- Throws:
java.lang.Exception- if something goes wrong while reading from stream
-
deSerialize
public static java.lang.Object deSerialize(java.lang.String xmlString) throws java.lang.ExceptionDeserializes an object from the supplied XML string- Parameters:
xmlString- the XML to deserialize from- Returns:
- the deserialized object
- Throws:
java.lang.Exception- if something goes wrong
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Returns:
- the revision
-
-