我正在尝试vcdiff,用于从源文件和目标文件创建差异文件。另外,将对源文件应用diff以获得目标文件。
我已经使用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());