class BsPatch {

  public static void applyPatch(
      RandomAccessFile oldData, OutputStream newData, InputStream patchData)
      throws PatchFormatException, IOException {
    patchData = new BufferedInputStream(patchData, PATCH_STREAM_BUFFER_SIZE);
    newData = new BufferedOutputStream(newData, OUTPUT_STREAM_BUFFER_SIZE);
    try {
      applyPatchInternal(oldData, newData, patchData);
    } finally {
      newData.flush();
    }
  }

}

class BsPatchTest {

  private static final String SIGNATURE;
  private byte[] buffer1;
  private byte[] buffer2;
  private File oldFile;

  @Test
  public void testApplyPatch_NewLengthTooLarge() throws Exception {

    createEmptyOldFile(10);
    InputStream patchIn =
        makePatch(
            SIGNATURE,
            Integer.MAX_VALUE + 1, // newLength (max supported is Integer.MAX_VALUE)
            10, // diffSegmentLength
            0, // copySegmentLength
            0, // offsetToNextInput
            new byte[10] // addends
            );
    ByteArrayOutputStream newData = new ByteArrayOutputStream();
    try {
      BsPatch.applyPatch(
          new RandomAccessFile(oldFile, "r"), newData, patchIn);
      Assert.fail("Read patch with excessive newLength");
    } catch (PatchFormatException expected) {
      // No way to mock the internal logic, so resort to testing exception string for coverage
      String actual = expected.getMessage();
      Assert.assertEquals("bad newSize", actual);
    }
  }

}