public class SerializationHelper extends java.lang.Object implements RevisionHandler
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
SERIAL_VERSION_UID
the field name of serialVersionUID.
|
| Constructor and Description |
|---|
SerializationHelper() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.ClassLoader |
checkForThirdPartyClass(java.lang.String className,
WekaPackageLibIsolatingClassLoader l)
Checks to see if the supplied package class loader (or any of its dependent
package class loaders) has the given third party class.
|
static java.io.ObjectInputStream |
getObjectInputStream(java.io.InputStream stream)
Get a (Weka package classloader aware)
ObjectInputStream instance
for reading objects from the supplied input stream |
java.lang.String |
getRevision()
Returns the revision string.
|
static long |
getUID(java.lang.Class<?> c)
reads or creates the serialVersionUID for the given class.
|
static long |
getUID(java.lang.String classname)
reads or creates the serialVersionUID for the given class.
|
static boolean |
hasUID(java.lang.Class<?> c)
checks whether the given class contains a serialVersionUID.
|
static boolean |
hasUID(java.lang.String classname)
checks whether the given class contains a serialVersionUID.
|
static boolean |
isSerializable(java.lang.Class<?> c)
checks whether a class is serializable.
|
static boolean |
isSerializable(java.lang.String classname)
checks whether a class is serializable.
|
static void |
main(java.lang.String[] args)
Outputs information about a class on the commandline, takes class name as
arguments.
|
static boolean |
needsUID(java.lang.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.
|
static boolean |
needsUID(java.lang.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 java.lang.Object |
read(java.io.InputStream stream)
deserializes from the given stream and returns the object from it.
|
static java.lang.Object |
read(java.lang.String filename)
deserializes the given file and returns the object from it.
|
static java.lang.Object[] |
readAll(java.io.InputStream stream)
deserializes from the given stream and returns the object from it.
|
static java.lang.Object[] |
readAll(java.lang.String filename)
deserializes the given file and returns the objects from it.
|
static void |
write(java.io.OutputStream stream,
java.lang.Object o)
serializes the given object to the specified stream.
|
static void |
write(java.lang.String filename,
java.lang.Object o)
serializes the given object to the specified file.
|
static void |
writeAll(java.io.OutputStream stream,
java.lang.Object[] o)
serializes the given objects to the specified stream.
|
static void |
writeAll(java.lang.String filename,
java.lang.Object[] o)
serializes the given objects to the specified file.
|
public static final java.lang.String SERIAL_VERSION_UID
public static boolean isSerializable(java.lang.String classname)
classname - the class to checkpublic static boolean isSerializable(java.lang.Class<?> c)
c - the class to checkpublic static boolean hasUID(java.lang.String classname)
classname - the class to checkpublic static boolean hasUID(java.lang.Class<?> c)
c - the class to checkpublic static boolean needsUID(java.lang.String classname)
classname - the class to checkpublic static boolean needsUID(java.lang.Class<?> c)
c - the class to checkpublic static long getUID(java.lang.String classname)
classname - the class to get the serialVersionUID forpublic static long getUID(java.lang.Class<?> c)
c - the class to get the serialVersionUID forpublic static void write(java.lang.String filename,
java.lang.Object o)
throws java.lang.Exception
filename - the file to write the object too - the object to serializejava.lang.Exception - if serialization failspublic static void write(java.io.OutputStream stream,
java.lang.Object o)
throws java.lang.Exception
stream - the stream to write the object too - the object to serializejava.lang.Exception - if serialization failspublic static void writeAll(java.lang.String filename,
java.lang.Object[] o)
throws java.lang.Exception
filename - the file to write the object too - the objects to serializejava.lang.Exception - if serialization failspublic static void writeAll(java.io.OutputStream stream,
java.lang.Object[] o)
throws java.lang.Exception
stream - the stream to write the object too - the objects to serializejava.lang.Exception - if serialization failspublic static java.lang.Object read(java.lang.String filename)
throws java.lang.Exception
filename - the file to deserialize fromjava.lang.Exception - if deserialization failspublic static java.lang.Object read(java.io.InputStream stream)
throws java.lang.Exception
stream - the stream to deserialize fromjava.lang.Exception - if deserialization failspublic static java.lang.ClassLoader checkForThirdPartyClass(java.lang.String className,
WekaPackageLibIsolatingClassLoader l)
className - the name of the third-party class to check forl - the third party class loaderpublic static java.io.ObjectInputStream getObjectInputStream(java.io.InputStream stream)
throws java.io.IOException
ObjectInputStream instance
for reading objects from the supplied input streamstream - the stream to wrapObjectInputStream instance that is aware of of Weka
package classloadersjava.io.IOException - if a problem occurspublic static java.lang.Object[] readAll(java.lang.String filename)
throws java.lang.Exception
filename - the file to deserialize fromjava.lang.Exception - if deserialization failspublic static java.lang.Object[] readAll(java.io.InputStream stream)
throws java.lang.Exception
stream - the stream to deserialize fromjava.lang.Exception - if deserialization failspublic java.lang.String getRevision()
getRevision in interface RevisionHandlerpublic static void main(java.lang.String[] args)
throws java.lang.Exception
args - the classnames to checkjava.lang.Exception - if something goes wrong