@Test
public void testExample() throws IOException {

  byte[] oldBytes = new byte[] {
      (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F', (byte) 'G' };
  byte[] newBytes = new byte[] {
      (byte) 'A', (byte) 'B', (byte) 'X', (byte) 'Y', (byte) 'C', (byte) 'D',
      (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E' };
  byte[] patch = new byte[] {
      (byte) 0xd1, (byte) 0xff, (byte) 0xd1, (byte) 0xff, (byte) 4,  // magic+version
      (byte) 249, 0, 0, 2,                                           // COPY_USHORT_UBYTE 0, 2
      (byte) 2, (byte) 'X', (byte) 'Y',                              // DATA_2
      (byte) 249, 0, 2, 2,                                           // COPY_USHORT_UBYTE 2, 2
      (byte) 249, 0, 1, 4,                                           // COPY_USHORT_UBYTE 1, 4
      0 };                                                           // EOF
  // Create "input file".
  File inputFile = File.createTempFile("testExample", null);
  FileOutputStream writeInputFile = new FileOutputStream(inputFile);
  writeInputFile.write(oldBytes);
  writeInputFile.close();
  RandomAccessFile readInputFile = new RandomAccessFile(inputFile, "r");
  // Create "patch" file - this is just a stream
  ByteArrayInputStream patchStream = new ByteArrayInputStream(patch);
  // Create "output" file - this is just a stream
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream(newBytes.length);
  long outputLength = Gdiff.patch(readInputFile, patchStream, outputStream, newBytes.length);
  Assert.assertEquals(newBytes.length, outputLength);
  Assert.assertArrayEquals(newBytes, outputStream.toByteArray());
}