@Test public void testPrepareForDiffing_OneCompressedEntry_Changed() throws IOException { byte[] oldBytes = UnitTestZipArchive.makeTestZip(Collections.singletonList(ENTRY_LEVEL_6)); File oldFile = store(oldBytes); byte[] newBytes = UnitTestZipArchive.makeTestZip(Collections.singletonList(ENTRY_LEVEL_9)); File newFile = store(newBytes); PreDiffExecutor executor = new PreDiffExecutor.Builder() .readingOriginalFiles(oldFile, newFile) .writingDeltaFriendlyFiles(deltaFriendlyOldFile, deltaFriendlyNewFile) .build(); PreDiffPlan plan = executor.prepareForDiffing(); Assert.assertNotNull(plan); Assert.assertEquals(1, plan.getOldFileUncompressionPlan().size()); Assert.assertEquals(1, plan.getNewFileUncompressionPlan().size()); Assert.assertEquals(1, plan.getDeltaFriendlyNewFileRecompressionPlan().size()); Assert.assertTrue(oldFile.length() < deltaFriendlyOldFile.length()); Assert.assertTrue(newFile.length() < deltaFriendlyNewFile.length()); { MinimalZipEntry oldEntry = findEntry(oldFile, ENTRY_LEVEL_6.path); ByteArrayOutputStream expectedDeltaFriendlyOldFileBytes = new ByteArrayOutputStream(); expectedDeltaFriendlyOldFileBytes.write( oldBytes, 0, (int) oldEntry.getFileOffsetOfCompressedData()); expectedDeltaFriendlyOldFileBytes.write(ENTRY_LEVEL_6.getUncompressedBinaryContent()); int oldRemainderOffset = (int) (oldEntry.getFileOffsetOfCompressedData() + oldEntry.getCompressedSize()); int oldRemainderLength = oldBytes.length - oldRemainderOffset; expectedDeltaFriendlyOldFileBytes.write(oldBytes, oldRemainderOffset, oldRemainderLength); byte[] expectedOld = expectedDeltaFriendlyOldFileBytes.toByteArray(); byte[] actualOld = readFile(deltaFriendlyOldFile); Assert.assertArrayEquals(expectedOld, actualOld); } { MinimalZipEntry newEntry = findEntry(newFile, ENTRY_LEVEL_9.path); ByteArrayOutputStream expectedDeltaFriendlyNewFileBytes = new ByteArrayOutputStream(); expectedDeltaFriendlyNewFileBytes.write( newBytes, 0, (int) newEntry.getFileOffsetOfCompressedData()); expectedDeltaFriendlyNewFileBytes.write(ENTRY_LEVEL_9.getUncompressedBinaryContent()); int newRemainderOffset = (int) (newEntry.getFileOffsetOfCompressedData() + newEntry.getCompressedSize()); int newRemainderLength = newBytes.length - newRemainderOffset; expectedDeltaFriendlyNewFileBytes.write(newBytes, newRemainderOffset, newRemainderLength); byte[] expectedNew = expectedDeltaFriendlyNewFileBytes.toByteArray(); byte[] actualNew = readFile(deltaFriendlyNewFile); Assert.assertArrayEquals(expectedNew, actualNew); } }
public PreDiffPlan prepareForDiffing() throws IOException { PreDiffPlan preDiffPlan = generatePreDiffPlan(); List<TypedRange<JreDeflateParameters>> deltaFriendlyNewFileRecompressionPlan = null; if (deltaFriendlyOldFile != null) { deltaFriendlyNewFileRecompressionPlan = Collections.unmodifiableList(generateDeltaFriendlyFiles(preDiffPlan)); } return new PreDiffPlan( preDiffPlan.getQualifiedRecommendations(), preDiffPlan.getOldFileUncompressionPlan(), preDiffPlan.getNewFileUncompressionPlan(), deltaFriendlyNewFileRecompressionPlan); }
PreDiffExecutor { public PreDiffPlan prepareForDiffing() throws IOException { PreDiffPlan preDiffPlan = generatePreDiffPlan(); List<TypedRange<JreDeflateParameters>> deltaFriendlyNewFileRecompressionPlan = null; if (deltaFriendlyOldFile != null) { deltaFriendlyNewFileRecompressionPlan = Collections.unmodifiableList(generateDeltaFriendlyFiles(preDiffPlan)); } return new PreDiffPlan( preDiffPlan.getQualifiedRecommendations(), preDiffPlan.getOldFileUncompressionPlan(), preDiffPlan.getNewFileUncompressionPlan(), deltaFriendlyNewFileRecompressionPlan); } }
PreDiffExecutor { public PreDiffPlan prepareForDiffing() throws IOException { PreDiffPlan preDiffPlan = generatePreDiffPlan(); List<TypedRange<JreDeflateParameters>> deltaFriendlyNewFileRecompressionPlan = null; if (deltaFriendlyOldFile != null) { deltaFriendlyNewFileRecompressionPlan = Collections.unmodifiableList(generateDeltaFriendlyFiles(preDiffPlan)); } return new PreDiffPlan( preDiffPlan.getQualifiedRecommendations(), preDiffPlan.getOldFileUncompressionPlan(), preDiffPlan.getNewFileUncompressionPlan(), deltaFriendlyNewFileRecompressionPlan); } private  PreDiffExecutor(
      File originalOldFile,
      File originalNewFile,
      File deltaFriendlyOldFile,
      File deltaFriendlyNewFile,
      List<RecommendationModifier> recommendationModifiers); }
PreDiffExecutor { public PreDiffPlan prepareForDiffing() throws IOException { PreDiffPlan preDiffPlan = generatePreDiffPlan(); List<TypedRange<JreDeflateParameters>> deltaFriendlyNewFileRecompressionPlan = null; if (deltaFriendlyOldFile != null) { deltaFriendlyNewFileRecompressionPlan = Collections.unmodifiableList(generateDeltaFriendlyFiles(preDiffPlan)); } return new PreDiffPlan( preDiffPlan.getQualifiedRecommendations(), preDiffPlan.getOldFileUncompressionPlan(), preDiffPlan.getNewFileUncompressionPlan(), deltaFriendlyNewFileRecompressionPlan); } private  PreDiffExecutor(
      File originalOldFile,
      File originalNewFile,
      File deltaFriendlyOldFile,
      File deltaFriendlyNewFile,
      List<RecommendationModifier> recommendationModifiers); PreDiffPlan prepareForDiffing(); }
PreDiffExecutor { public PreDiffPlan prepareForDiffing() throws IOException { PreDiffPlan preDiffPlan = generatePreDiffPlan(); List<TypedRange<JreDeflateParameters>> deltaFriendlyNewFileRecompressionPlan = null; if (deltaFriendlyOldFile != null) { deltaFriendlyNewFileRecompressionPlan = Collections.unmodifiableList(generateDeltaFriendlyFiles(preDiffPlan)); } return new PreDiffPlan( preDiffPlan.getQualifiedRecommendations(), preDiffPlan.getOldFileUncompressionPlan(), preDiffPlan.getNewFileUncompressionPlan(), deltaFriendlyNewFileRecompressionPlan); } private  PreDiffExecutor(
      File originalOldFile,
      File originalNewFile,
      File deltaFriendlyOldFile,
      File deltaFriendlyNewFile,
      List<RecommendationModifier> recommendationModifiers); PreDiffPlan prepareForDiffing();  }