我正在尝试使用 vcdiff 从源文件和目标文件创建差异文件。此外,将在源文件上应用差异来获取目标文件。
我已经使用 xdelta linux 命令行工具实现了上述用例。
但是如何使用 vcdiff-java API 来实现相同的目标?任何提示或方向都将有助于开始。
谢谢。
我认为 diff 和 apply 的基本用例可以如下处理。这里,diff是从source.txt和target.txt生成的。然后,将diff应用于source.txt以获取与target.txt相等的result.txt。
Path source = Files.createFile(Paths.get(basePath + "source.txt"));
Files.write(source, new StringBuilder(
"First line of the file.\n"
+ "Second line of the file."
).toString().getBytes());
Path target = Files.createFile(Paths.get(basePath + "target.txt"));
Files.write(target, "1. First line of the file!".getBytes());
final ByteArrayOutputStream delta_ = new ByteArrayOutputStream();
VCDiffEncoder<OutputStream> encoder = VCDiffEncoderBuilder.builder()
.withDictionary(Files.readAllBytes(source))
.withTargetMatches(false)
.withChecksum(true)
.withInterleaving(true)
.buildSimple();
encoder.encode(Files.readAllBytes(target), delta_);
ByteArrayOutputStream result_out = new ByteArrayOutputStream();
VCDiffDecoder decoder = VCDiffDecoderBuilder.builder().buildSimple();
decoder.decode(Files.readAllBytes(source), delta_.toByteArray(), result_out);
Path result = Files.createFile(Paths.get(basePath + "result.txt"));
Files.write(result, result_out.toByteArray());