@Test public void testGenerateDelta_BaseCase() throws Exception { FileByFileV1DeltaGenerator generator = new FileByFileV1DeltaGenerator(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try (TempFileHolder oldArchive = new TempFileHolder(); TempFileHolder newArchive = new TempFileHolder()) { UnitTestZipArchive.saveTestZip(oldArchive.file); UnitTestZipArchive.saveTestZip(newArchive.file); generator.generateDelta(oldArchive.file, newArchive.file, buffer); } byte[] result = buffer.toByteArray(); Assert.assertTrue(result.length > 0); }
@Override public void generateDelta(File oldFile, File newFile, OutputStream patchOut) throws IOException, InterruptedException { try (TempFileHolder deltaFriendlyOldFile = new TempFileHolder(); TempFileHolder deltaFriendlyNewFile = new TempFileHolder(); TempFileHolder deltaFile = new TempFileHolder(); FileOutputStream deltaFileOut = new FileOutputStream(deltaFile.file); BufferedOutputStream bufferedDeltaOut = new BufferedOutputStream(deltaFileOut)) { PreDiffExecutor.Builder builder = new PreDiffExecutor.Builder() .readingOriginalFiles(oldFile, newFile) .writingDeltaFriendlyFiles(deltaFriendlyOldFile.file, deltaFriendlyNewFile.file); for (RecommendationModifier modifier : recommendationModifiers) { builder.withRecommendationModifier(modifier); } PreDiffExecutor executor = builder.build(); PreDiffPlan preDiffPlan = executor.prepareForDiffing(); DeltaGenerator deltaGenerator = getDeltaGenerator(); deltaGenerator.generateDelta( deltaFriendlyOldFile.file, deltaFriendlyNewFile.file, bufferedDeltaOut); bufferedDeltaOut.close(); PatchWriter patchWriter = new PatchWriter( preDiffPlan, deltaFriendlyOldFile.file.length(), deltaFriendlyNewFile.file.length(), deltaFile.file); patchWriter.writeV1Patch(patchOut); } }
FileByFileV1DeltaGenerator implements DeltaGenerator { @Override public void generateDelta(File oldFile, File newFile, OutputStream patchOut) throws IOException, InterruptedException { try (TempFileHolder deltaFriendlyOldFile = new TempFileHolder(); TempFileHolder deltaFriendlyNewFile = new TempFileHolder(); TempFileHolder deltaFile = new TempFileHolder(); FileOutputStream deltaFileOut = new FileOutputStream(deltaFile.file); BufferedOutputStream bufferedDeltaOut = new BufferedOutputStream(deltaFileOut)) { PreDiffExecutor.Builder builder = new PreDiffExecutor.Builder() .readingOriginalFiles(oldFile, newFile) .writingDeltaFriendlyFiles(deltaFriendlyOldFile.file, deltaFriendlyNewFile.file); for (RecommendationModifier modifier : recommendationModifiers) { builder.withRecommendationModifier(modifier); } PreDiffExecutor executor = builder.build(); PreDiffPlan preDiffPlan = executor.prepareForDiffing(); DeltaGenerator deltaGenerator = getDeltaGenerator(); deltaGenerator.generateDelta( deltaFriendlyOldFile.file, deltaFriendlyNewFile.file, bufferedDeltaOut); bufferedDeltaOut.close(); PatchWriter patchWriter = new PatchWriter( preDiffPlan, deltaFriendlyOldFile.file.length(), deltaFriendlyNewFile.file.length(), deltaFile.file); patchWriter.writeV1Patch(patchOut); } } }
FileByFileV1DeltaGenerator implements DeltaGenerator { @Override public void generateDelta(File oldFile, File newFile, OutputStream patchOut) throws IOException, InterruptedException { try (TempFileHolder deltaFriendlyOldFile = new TempFileHolder(); TempFileHolder deltaFriendlyNewFile = new TempFileHolder(); TempFileHolder deltaFile = new TempFileHolder(); FileOutputStream deltaFileOut = new FileOutputStream(deltaFile.file); BufferedOutputStream bufferedDeltaOut = new BufferedOutputStream(deltaFileOut)) { PreDiffExecutor.Builder builder = new PreDiffExecutor.Builder() .readingOriginalFiles(oldFile, newFile) .writingDeltaFriendlyFiles(deltaFriendlyOldFile.file, deltaFriendlyNewFile.file); for (RecommendationModifier modifier : recommendationModifiers) { builder.withRecommendationModifier(modifier); } PreDiffExecutor executor = builder.build(); PreDiffPlan preDiffPlan = executor.prepareForDiffing(); DeltaGenerator deltaGenerator = getDeltaGenerator(); deltaGenerator.generateDelta( deltaFriendlyOldFile.file, deltaFriendlyNewFile.file, bufferedDeltaOut); bufferedDeltaOut.close(); PatchWriter patchWriter = new PatchWriter( preDiffPlan, deltaFriendlyOldFile.file.length(), deltaFriendlyNewFile.file.length(), deltaFile.file); patchWriter.writeV1Patch(patchOut); } } FileByFileV1DeltaGenerator(RecommendationModifier... recommendationModifiers); }
FileByFileV1DeltaGenerator implements DeltaGenerator { @Override public void generateDelta(File oldFile, File newFile, OutputStream patchOut) throws IOException, InterruptedException { try (TempFileHolder deltaFriendlyOldFile = new TempFileHolder(); TempFileHolder deltaFriendlyNewFile = new TempFileHolder(); TempFileHolder deltaFile = new TempFileHolder(); FileOutputStream deltaFileOut = new FileOutputStream(deltaFile.file); BufferedOutputStream bufferedDeltaOut = new BufferedOutputStream(deltaFileOut)) { PreDiffExecutor.Builder builder = new PreDiffExecutor.Builder() .readingOriginalFiles(oldFile, newFile) .writingDeltaFriendlyFiles(deltaFriendlyOldFile.file, deltaFriendlyNewFile.file); for (RecommendationModifier modifier : recommendationModifiers) { builder.withRecommendationModifier(modifier); } PreDiffExecutor executor = builder.build(); PreDiffPlan preDiffPlan = executor.prepareForDiffing(); DeltaGenerator deltaGenerator = getDeltaGenerator(); deltaGenerator.generateDelta( deltaFriendlyOldFile.file, deltaFriendlyNewFile.file, bufferedDeltaOut); bufferedDeltaOut.close(); PatchWriter patchWriter = new PatchWriter( preDiffPlan, deltaFriendlyOldFile.file.length(), deltaFriendlyNewFile.file.length(), deltaFile.file); patchWriter.writeV1Patch(patchOut); } } FileByFileV1DeltaGenerator(RecommendationModifier... recommendationModifiers); @Override void generateDelta(File oldFile, File newFile, OutputStream patchOut); }
FileByFileV1DeltaGenerator implements DeltaGenerator { @Override public void generateDelta(File oldFile, File newFile, OutputStream patchOut) throws IOException, InterruptedException { try (TempFileHolder deltaFriendlyOldFile = new TempFileHolder(); TempFileHolder deltaFriendlyNewFile = new TempFileHolder(); TempFileHolder deltaFile = new TempFileHolder(); FileOutputStream deltaFileOut = new FileOutputStream(deltaFile.file); BufferedOutputStream bufferedDeltaOut = new BufferedOutputStream(deltaFileOut)) { PreDiffExecutor.Builder builder = new PreDiffExecutor.Builder() .readingOriginalFiles(oldFile, newFile) .writingDeltaFriendlyFiles(deltaFriendlyOldFile.file, deltaFriendlyNewFile.file); for (RecommendationModifier modifier : recommendationModifiers) { builder.withRecommendationModifier(modifier); } PreDiffExecutor executor = builder.build(); PreDiffPlan preDiffPlan = executor.prepareForDiffing(); DeltaGenerator deltaGenerator = getDeltaGenerator(); deltaGenerator.generateDelta( deltaFriendlyOldFile.file, deltaFriendlyNewFile.file, bufferedDeltaOut); bufferedDeltaOut.close(); PatchWriter patchWriter = new PatchWriter( preDiffPlan, deltaFriendlyOldFile.file.length(), deltaFriendlyNewFile.file.length(), deltaFile.file); patchWriter.writeV1Patch(patchOut); } } FileByFileV1DeltaGenerator(RecommendationModifier... recommendationModifiers); @Override void generateDelta(File oldFile, File newFile, OutputStream patchOut);  }