程序包 weka.core

类 SerializationHelper

java.lang.Object
weka.core.SerializationHelper
所有已实现的接口:
RevisionHandler

public class SerializationHelper extends Object implements RevisionHandler
A helper class for determining serialVersionUIDs and checking whether classes contain one and/or need one. One can also serialize and deserialize objects to and fro files or streams.
版本:
$Revision: 8597 $
作者:
fracpete (fracpete at waikato dot ac dot nz)
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final String
    the field name of serialVersionUID.
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    Returns the revision string.
    static long
    reads or creates the serialVersionUID for the given class.
    static long
    getUID(String classname)
    reads or creates the serialVersionUID for the given class.
    static boolean
    checks whether the given class contains a serialVersionUID.
    static boolean
    hasUID(String classname)
    checks whether the given class contains a serialVersionUID.
    static boolean
    checks whether a class is serializable.
    static boolean
    checks whether a class is serializable.
    static void
    main(String[] args)
    Outputs information about a class on the commandline, takes class name as arguments.
    static boolean
    checks whether a class needs to declare a serialVersionUID, i.e., it implements the java.io.Serializable interface but doesn't declare a serialVersionUID.
    static boolean
    needsUID(String classname)
    checks whether a class needs to declare a serialVersionUID, i.e., it implements the java.io.Serializable interface but doesn't declare a serialVersionUID.
    static Object
    read(InputStream stream)
    deserializes from the given stream and returns the object from it.
    static Object
    read(String filename)
    deserializes the given file and returns the object from it.
    static Object[]
    deserializes from the given stream and returns the object from it.
    static Object[]
    readAll(String filename)
    deserializes the given file and returns the objects from it.
    static void
    serializes the given object to the specified stream.
    static void
    write(String filename, Object o)
    serializes the given object to the specified file.
    static void
    serializes the given objects to the specified stream.
    static void
    writeAll(String filename, Object[] o)
    serializes the given objects to the specified file.

    从类继承的方法 java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • SERIAL_VERSION_UID

      public static final String SERIAL_VERSION_UID
      the field name of serialVersionUID.
      另请参阅:
  • 构造器详细资料

    • SerializationHelper

      public SerializationHelper()
  • 方法详细资料

    • isSerializable

      public static boolean isSerializable(String classname)
      checks whether a class is serializable.
      参数:
      classname - the class to check
      返回:
      true if the class or one of its ancestors implements the Serializable interface, otherwise false (also if the class cannot be loaded)
    • isSerializable

      public static boolean isSerializable(Class c)
      checks whether a class is serializable.
      参数:
      c - the class to check
      返回:
      true if the class or one of its ancestors implements the Serializable interface, otherwise false
    • hasUID

      public static boolean hasUID(String classname)
      checks whether the given class contains a serialVersionUID.
      参数:
      classname - the class to check
      返回:
      true if the class contains a serialVersionUID, otherwise false (also if the class is not implementing serializable or cannot be loaded)
    • hasUID

      public static boolean hasUID(Class c)
      checks whether the given class contains a serialVersionUID.
      参数:
      c - the class to check
      返回:
      true if the class contains a serialVersionUID, otherwise false (also if the class is not implementing serializable)
    • needsUID

      public static boolean needsUID(String classname)
      checks whether a class needs to declare a serialVersionUID, i.e., it implements the java.io.Serializable interface but doesn't declare a serialVersionUID.
      参数:
      classname - the class to check
      返回:
      true if the class needs to declare one, false otherwise (also if the class cannot be loaded!)
    • needsUID

      public static boolean needsUID(Class c)
      checks whether a class needs to declare a serialVersionUID, i.e., it implements the java.io.Serializable interface but doesn't declare a serialVersionUID.
      参数:
      c - the class to check
      返回:
      true if the class needs to declare one, false otherwise
    • getUID

      public static long getUID(String classname)
      reads or creates the serialVersionUID for the given class.
      参数:
      classname - the class to get the serialVersionUID for
      返回:
      the UID, 0L for non-serializable classes (or if the class cannot be loaded)
    • getUID

      public static long getUID(Class c)
      reads or creates the serialVersionUID for the given class.
      参数:
      c - the class to get the serialVersionUID for
      返回:
      the UID, 0L for non-serializable classes
    • write

      public static void write(String filename, Object o) throws Exception
      serializes the given object to the specified file.
      参数:
      filename - the file to write the object to
      o - the object to serialize
      抛出:
      Exception - if serialization fails
    • write

      public static void write(OutputStream stream, Object o) throws Exception
      serializes the given object to the specified stream.
      参数:
      stream - the stream to write the object to
      o - the object to serialize
      抛出:
      Exception - if serialization fails
    • writeAll

      public static void writeAll(String filename, Object[] o) throws Exception
      serializes the given objects to the specified file.
      参数:
      filename - the file to write the object to
      o - the objects to serialize
      抛出:
      Exception - if serialization fails
    • writeAll

      public static void writeAll(OutputStream stream, Object[] o) throws Exception
      serializes the given objects to the specified stream.
      参数:
      stream - the stream to write the object to
      o - the objects to serialize
      抛出:
      Exception - if serialization fails
    • read

      public static Object read(String filename) throws Exception
      deserializes the given file and returns the object from it.
      参数:
      filename - the file to deserialize from
      返回:
      the deserialized object
      抛出:
      Exception - if deserialization fails
    • read

      public static Object read(InputStream stream) throws Exception
      deserializes from the given stream and returns the object from it.
      参数:
      stream - the stream to deserialize from
      返回:
      the deserialized object
      抛出:
      Exception - if deserialization fails
    • readAll

      public static Object[] readAll(String filename) throws Exception
      deserializes the given file and returns the objects from it.
      参数:
      filename - the file to deserialize from
      返回:
      the deserialized objects
      抛出:
      Exception - if deserialization fails
    • readAll

      public static Object[] readAll(InputStream stream) throws Exception
      deserializes from the given stream and returns the object from it.
      参数:
      stream - the stream to deserialize from
      返回:
      the deserialized object
      抛出:
      Exception - if deserialization fails
    • getRevision

      public String getRevision()
      Returns the revision string.
      指定者:
      getRevision 在接口中 RevisionHandler
      返回:
      the revision
    • main

      public static void main(String[] args) throws Exception
      Outputs information about a class on the commandline, takes class name as arguments.
      参数:
      args - the classnames to check
      抛出:
      Exception - if something goes wrong