Package weka.core.xml

Class XStream

java.lang.Object
weka.core.xml.XStream
All Implemented Interfaces:
RevisionHandler

public class XStream extends 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: 10203 $
Author:
Mark Hall (mhall{[at]}pentaho{[dot]}org)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    the extension for XStream files (including '.')
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    deSerialize(String xmlString)
    Deserializes an object from the supplied XML string
    Returns the revision string.
    static boolean
    returns whether XStream is present or not, i.e.
    static Object
    read(File file)
    reads the XML-serialized object from the given file
    static Object
    read(InputStream stream)
    reads the XML-serialized object from the given input stream
    static Object
    reads the XML-serialized object from the given Reader
    static Object
    read(String filename)
    reads the XML-serialized object from the given file
    static String
    serialize(Object toSerialize)
    Serializes the supplied object xml
    static boolean
    write(File file, Object o)
    write the XML-serialized object to the given file
    static boolean
    writes the XML-serialized object to the given output stream
    static boolean
    write(Writer writer, Object toSerialize)
    writes the XML-serialized object to the given Writer.
    static boolean
    write(String filename, Object o)
    writes the XML-serialized object to the given file

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FILE_EXTENSION

      public static final String FILE_EXTENSION
      the extension for XStream files (including '.')
      See Also:
  • Constructor Details

    • XStream

      public XStream()
  • Method Details

    • 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 String serialize(Object toSerialize) throws Exception
      Serializes the supplied object xml
      Parameters:
      toSerialize - the object to serialize
      Returns:
      the serialized object as an XML string
      Throws:
      Exception - if something goes wrong
    • write

      public static boolean write(String filename, Object o) throws Exception
      writes the XML-serialized object to the given file
      Parameters:
      filename - the file to serialize the object to
      o - the object to write to the file
      Returns:
      whether writing was successful or not
      Throws:
      Exception - if something goes wrong while writing to the file
    • write

      public static boolean write(File file, Object o) throws Exception
      write the XML-serialized object to the given file
      Parameters:
      file - the file to serialize the object to
      o - the object to write to the file
      Returns:
      whether writing was successful or not
      Throws:
      Exception - if something goes wrong while writing to the file
    • write

      public static boolean write(OutputStream stream, Object o) throws Exception
      writes the XML-serialized object to the given output stream
      Parameters:
      stream - the output stream
      o - the object to write
      Returns:
      true if everything goes ok
      Throws:
      Exception
    • write

      public static boolean write(Writer writer, Object toSerialize) throws Exception
      writes the XML-serialized object to the given Writer.
      Parameters:
      writer - the Writer
      toSerialize - the object to write
      Returns:
      true if everything goes ok
      Throws:
      Exception - if something goes wrong
    • read

      public static Object read(String filename) throws Exception
      reads the XML-serialized object from the given file
      Parameters:
      filename - the file to deserialize the object from
      Returns:
      the deserialized object
      Throws:
      Exception - if something goes wrong while reading from the file
    • read

      public static Object read(File file) throws Exception
      reads the XML-serialized object from the given file
      Parameters:
      file - the file to deserialize the object from
      Returns:
      the deserialized object
      Throws:
      Exception - if something goes wrong while reading from the file
    • read

      public static Object read(InputStream stream) throws Exception
      reads the XML-serialized object from the given input stream
      Parameters:
      stream - the input stream
      Returns:
      the deserialized object
      Throws:
      Exception - if something goes wrong while reading from stream
    • read

      public static Object read(Reader r) throws Exception
      reads the XML-serialized object from the given Reader
      Parameters:
      r - the reader
      Returns:
      the deserialized object
      Throws:
      Exception - if something goes wrong while reading from stream
    • deSerialize

      public static Object deSerialize(String xmlString) throws Exception
      Deserializes an object from the supplied XML string
      Parameters:
      xmlString - the XML to deserialize from
      Returns:
      the deserialized object
      Throws:
      Exception - if something goes wrong
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Returns:
      the revision