public static void assertStreamEquals(final String witness,
			final byte[] actual, final int[] skip, final int endCompare)
			throws IOException {
		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) {
				assertEquals(actual.length, bytesRead);
			}

			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]) {
						assertEquals("Difference at offset " + i, actual[i],
								expected[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();
			Assert.fail("Writing witness file " + witness);
		}
	}
Asserts the serialized form of an object.

@param witness
           file name of expected serialization.
@param actual
           byte array of actual serialization.
@param skip
           positions to skip comparison.
@param endCompare
           position to stop comparison.
@throws IOException
            thrown on IO or serialization exception.
olv-core/src/test/java/pl/otros/logview/accept/query/org/apache/log4j/util/SerializationTestHelper.java