FileByFileV1DeltaApplier implements DeltaApplier { @Override public void applyDelta(File oldBlob, InputStream deltaIn, OutputStream newBlobOut) throws IOException { if (!tempDir.exists()) { tempDir.mkdirs(); } File tempFile = File.createTempFile("gfbfv1", "old", tempDir); try { applyDeltaInternal(oldBlob, tempFile, deltaIn, newBlobOut); } finally { tempFile.delete(); } } FileByFileV1DeltaApplier();  FileByFileV1DeltaApplier(File tempDir); @Override void applyDelta(File oldBlob, InputStream deltaIn, OutputStream newBlobOut);  }
@Test public void testApplyDelta() throws IOException { ByteArrayOutputStream actualNewBlobOut = new ByteArrayOutputStream(); fakeApplier.applyDelta(oldFile, new ByteArrayInputStream(patchBytes), actualNewBlobOut); Assert.assertArrayEquals(expectedNewBytes, actualNewBlobOut.toByteArray()); }
@Test public void testApplyDelta_DoesntCloseStream() throws IOException { final AtomicBoolean closed = new AtomicBoolean(false); ByteArrayOutputStream actualNewBlobOut = new ByteArrayOutputStream() { @Override public void close() throws IOException { closed.set(true); } }; fakeApplier.applyDelta(oldFile, new ByteArrayInputStream(patchBytes), actualNewBlobOut); Assert.assertArrayEquals(expectedNewBytes, actualNewBlobOut.toByteArray()); Assert.assertFalse(closed.get()); }