org.apache.log4j.util
Class SerializationTestHelper

java.lang.Object
  extended by org.apache.log4j.util.SerializationTestHelper

public class SerializationTestHelper
extends java.lang.Object

Utiities for serialization tests.

Author:
Curt Arnold

Method Summary
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.
static void assertStreamEquals(java.lang.String witness, byte[] actual, int[] skip, int endCompare)
          Asserts the serialized form of an object.
static java.lang.Object deserializeStream(java.lang.String witness)
          Deserializes a specified file.
static java.lang.Object serializeClone(java.lang.Object obj)
          Creates a clone by serializing object and deserializing byte stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

serializeClone

public static java.lang.Object serializeClone(java.lang.Object obj)
                                       throws java.io.IOException,
                                              java.lang.ClassNotFoundException
Creates a clone by serializing object and deserializing byte stream.

Parameters:
obj - object to serialize and deserialize.
Returns:
clone
Throws:
java.io.IOException - on IO error.
java.lang.ClassNotFoundException - if class not found.

deserializeStream

public static java.lang.Object deserializeStream(java.lang.String witness)
                                          throws java.lang.Exception
Deserializes a specified file.

Parameters:
witness - serialization file, may not be null.
Returns:
deserialized object.
Throws:
java.lang.Exception - thrown on IO or deserialization exception.

assertSerializationEquals

public static void assertSerializationEquals(java.lang.String witness,
                                             java.lang.Object obj,
                                             int[] skip,
                                             int endCompare)
                                      throws java.lang.Exception
Checks the serialization of an object against an file containing the expected serialization.

Parameters:
witness - name of file containing expected serialization.
obj - object to be serialized.
skip - positions in serialized stream that should not be compared.
endCompare - position to stop comparison.
Throws:
java.lang.Exception - thrown on IO or serialization exception.

assertStreamEquals

public static void assertStreamEquals(java.lang.String witness,
                                      byte[] actual,
                                      int[] skip,
                                      int endCompare)
                               throws java.io.IOException
Asserts the serialized form of an object.

Parameters:
witness - file name of expected serialization.
actual - byte array of actual serialization.
skip - positions to skip comparison.
endCompare - position to stop comparison.
Throws:
java.io.IOException - thrown on IO or serialization exception.


Copyright © 2010 The Apache Software Foundation. Licensed under the Apache License, Version 2.0

Apache Extras Companion for Apache log4j, Apache log4j and Apache are trademarks of the Apache Software Foundation.