@Test public void testTransformBytes() throws IOException { final byte[] patchInput = "this is a sample string to read".getBytes("US-ASCII"); final ByteArrayInputStream patchInputStream = new ByteArrayInputStream(patchInput); copyToOldFile("bsdifftest_partial_a.txt"); RandomAccessFile oldData = new RandomAccessFile(oldFile, "r"); final byte[] expectedNewData = readTestData("bsdifftest_partial_b.bin"); ByteArrayOutputStream newData = new ByteArrayOutputStream(); BsPatch.transformBytes(patchInput.length, patchInputStream, oldData, newData, buffer1, buffer2); byte[] actual = newData.toByteArray(); Assert.assertArrayEquals(expectedNewData, actual); }
static void transformBytes( final int diffLength, final InputStream patchData, final RandomAccessFile oldData, final OutputStream newData, final byte[] buffer1, final byte[] buffer2) throws IOException { int numBytesLeft = diffLength; while (numBytesLeft > 0) { final int numBytesThisRound = Math.min(numBytesLeft, buffer1.length); oldData.readFully(buffer1, 0, numBytesThisRound); readFully(patchData, buffer2, 0, numBytesThisRound); for (int i = 0; i < numBytesThisRound; i++) { buffer1[i] += buffer2[i]; } newData.write(buffer1, 0, numBytesThisRound); numBytesLeft -= numBytesThisRound; } }
BsPatch { static void transformBytes( final int diffLength, final InputStream patchData, final RandomAccessFile oldData, final OutputStream newData, final byte[] buffer1, final byte[] buffer2) throws IOException { int numBytesLeft = diffLength; while (numBytesLeft > 0) { final int numBytesThisRound = Math.min(numBytesLeft, buffer1.length); oldData.readFully(buffer1, 0, numBytesThisRound); readFully(patchData, buffer2, 0, numBytesThisRound); for (int i = 0; i < numBytesThisRound; i++) { buffer1[i] += buffer2[i]; } newData.write(buffer1, 0, numBytesThisRound); numBytesLeft -= numBytesThisRound; } } }
BsPatch { static void transformBytes( final int diffLength, final InputStream patchData, final RandomAccessFile oldData, final OutputStream newData, final byte[] buffer1, final byte[] buffer2) throws IOException { int numBytesLeft = diffLength; while (numBytesLeft > 0) { final int numBytesThisRound = Math.min(numBytesLeft, buffer1.length); oldData.readFully(buffer1, 0, numBytesThisRound); readFully(patchData, buffer2, 0, numBytesThisRound); for (int i = 0; i < numBytesThisRound; i++) { buffer1[i] += buffer2[i]; } newData.write(buffer1, 0, numBytesThisRound); numBytesLeft -= numBytesThisRound; } }  }
BsPatch { static void transformBytes( final int diffLength, final InputStream patchData, final RandomAccessFile oldData, final OutputStream newData, final byte[] buffer1, final byte[] buffer2) throws IOException { int numBytesLeft = diffLength; while (numBytesLeft > 0) { final int numBytesThisRound = Math.min(numBytesLeft, buffer1.length); oldData.readFully(buffer1, 0, numBytesThisRound); readFully(patchData, buffer2, 0, numBytesThisRound); for (int i = 0; i < numBytesThisRound; i++) { buffer1[i] += buffer2[i]; } newData.write(buffer1, 0, numBytesThisRound); numBytesLeft -= numBytesThisRound; } }  static void applyPatch(
      RandomAccessFile oldData, OutputStream newData, InputStream patchData); }
BsPatch { static void transformBytes( final int diffLength, final InputStream patchData, final RandomAccessFile oldData, final OutputStream newData, final byte[] buffer1, final byte[] buffer2) throws IOException { int numBytesLeft = diffLength; while (numBytesLeft > 0) { final int numBytesThisRound = Math.min(numBytesLeft, buffer1.length); oldData.readFully(buffer1, 0, numBytesThisRound); readFully(patchData, buffer2, 0, numBytesThisRound); for (int i = 0; i < numBytesThisRound; i++) { buffer1[i] += buffer2[i]; } newData.write(buffer1, 0, numBytesThisRound); numBytesLeft -= numBytesThisRound; } }  static void applyPatch(
      RandomAccessFile oldData, OutputStream newData, InputStream patchData);  }