Methods Summary |
---|
public static boolean | assertCompabilityEquals(java.lang.Object obj, java.lang.String fileName)Tests the serialization compatibility with reference for instance
objects.
return obj.equals(readObject(obj, fileName));
|
public static boolean | assertCompabilitySame(java.lang.Object obj, java.lang.String fileName)Tests the serialization compatibility with reference const objects.
return obj == readObject(obj, fileName);
|
public static boolean | assertEquals(java.lang.Object inputObject)Tests the serialization and deserialization of instance objects.
return inputObject.equals(getDeserilizedObject(inputObject));
|
public static boolean | assertSame(java.lang.Object inputObject)Tests the serialization and deserialization of const objects.
return inputObject == getDeserilizedObject(inputObject);
|
public static java.lang.Object | getDeserilizedObject(java.lang.Object inputObject)Serialize an object and then deserialize it.
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(inputObject);
oos.close();
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
Object outputObject = ois.readObject();
lastOutput = outputObject;
ois.close();
return outputObject;
|
public static java.lang.Object | getLastOutput()Gets the last deserialized object.
return lastOutput;
|
public static void | main(java.lang.String[] args)
|
public static java.lang.Object | readObject(java.lang.Object obj, java.lang.String fileName)Deserialize an object from a file.
InputStream input = null;
ObjectInputStream oinput = null;
URL url = SerializationTester.class.getResource(
fileName);
if (null == url) {
// serialization file does not exist, create one in the current dir
writeObject(obj, new File(fileName).getName());
throw new Error(
"Serialization file does not exist, created in the current dir.");
}
input = url.openStream();
try {
oinput = new ObjectInputStream(input);
Object newObj = oinput.readObject();
return newObj;
} finally {
try {
if (null != oinput) {
oinput.close();
}
} catch (Exception e) {
// ignore
}
try {
if (null != input) {
input.close();
}
} catch (Exception e) {
// ignore
}
}
|
public static void | writeObject(java.lang.Object obj, java.lang.String fileName)
// String path = SerializationTester.class.getResource(".").getPath();
// if (path.endsWith(".")) {
// path = path.substring(0, path.length() - 1);
// }
// if (!path.endsWith("/")) {
// path += "/";
// }
// path += fileName;
// System.out.println(path);
OutputStream output = null;
ObjectOutputStream ooutput = null;
try {
output = new FileOutputStream(fileName);
ooutput = new ObjectOutputStream(output);
ooutput.writeObject(obj);
} finally {
try {
if (null != ooutput) {
ooutput.close();
}
} catch (Exception e) {
// ignore
}
try {
if (null != output) {
output.close();
}
} catch (Exception e) {
// ignore
}
}
|