public class SerializationHelper
extends java.lang.Object
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 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 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
|
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 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 void main(java.lang.String[] args)
args
- the classnames to check