Methods Summary |
---|
public static void | assertSerializationEquals(java.lang.String witness, java.lang.Object obj, int[] skip, int endCompare)Checks the serialization of an object against an file
containing the expected serialization.
ByteArrayOutputStream memOut = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(memOut);
objOut.writeObject(obj);
objOut.close();
assertStreamEquals(witness, memOut.toByteArray(), skip, endCompare);
|
public static void | assertStreamEquals(java.lang.String witness, byte[] actual, int[] skip, int endCompare)Asserts the serialized form of an object.
File witnessFile = new File(witness);
if (witnessFile.exists()) {
int skipIndex = 0;
byte[] expected = new byte[actual.length];
FileInputStream is = new FileInputStream(witnessFile);
int bytesRead = is.read(expected);
is.close();
if(bytesRead < endCompare) {
TestCase.assertEquals(bytesRead, actual.length);
}
int endScan = actual.length;
if (endScan > endCompare) {
endScan = endCompare;
}
for (int i = 0; i < endScan; i++) {
if ((skipIndex < skip.length) && (skip[skipIndex] == i)) {
skipIndex++;
} else {
if (expected[i] != actual[i]) {
TestCase.assertEquals(
"Difference at offset " + i, expected[i], actual[i]);
}
}
}
} else {
//
// if the file doesn't exist then
// assume that we are setting up and need to write it
FileOutputStream os = new FileOutputStream(witnessFile);
os.write(actual);
os.close();
TestCase.fail("Writing witness file " + witness);
}
|
public static java.lang.Object | deserializeStream(java.lang.String witness)Deserializes a specified file.
FileInputStream fileIs = new FileInputStream(witness);
ObjectInputStream objIs = new ObjectInputStream(fileIs);
return objIs.readObject();
|
public static java.lang.Object | serializeClone(java.lang.Object obj)Creates a clone by serializing object and
deserializing byte stream.
ByteArrayOutputStream memOut = new ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(memOut);
objOut.writeObject(obj);
objOut.close();
ByteArrayInputStream src = new ByteArrayInputStream(memOut.toByteArray());
ObjectInputStream objIs = new ObjectInputStream(src);
return objIs.readObject();
|