当前位置:首页 > 编程笔记 > 正文
已解决

Google Archive Patch 基础应用代码记录

来自网友在路上 173873提问 提问时间:2023-11-03 17:33:20阅读次数: 73

最佳答案 问答题库738位专家为你答疑解惑

项目地址

Google Archive Patch

前置

<!-- 差量应用模块 -->
<dependency><groupId>com.google.archivepatcher</groupId><artifactId>archive-patch-applier</artifactId><version>1.0.4</version><scope>test</scope>
</dependency>
<!-- 差量生成模块 --><dependency><groupId>com.google.archivepatcher</groupId><artifactId>archive-patch-generator</artifactId><version>1.0.4</version>
</dependency>
<!-- applier与generator的公共模块 -->
<dependency><groupId>com.google.archivepatcher</groupId><artifactId>archive-patch-shared</artifactId><version>1.0.4</version>
</dependency>

生成补丁

import com.google.archivepatcher.generator.FileByFileV1DeltaGenerator;
import com.google.archivepatcher.shared.DefaultDeflateCompatibilityWindow;
import java.io.File;
import java.io.FileOutputStream;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;/** Generate a patch; args are old file path, new file path, and patch file path. */
public class SamplePatchGenerator {public static void main(String... args) throws Exception {if (!new DefaultDeflateCompatibilityWindow().isCompatible()) {System.err.println("zlib not compatible on this system");System.exit(-1);}File oldFile = new File(args[0]); // must be a zip archiveFile newFile = new File(args[1]); // must be a zip archiveDeflater compressor = new Deflater(9, true); // to compress the patchtry (FileOutputStream patchOut = new FileOutputStream(args[2]); // args[2]为补丁存放地址DeflaterOutputStream compressedPatchOut =new DeflaterOutputStream(patchOut, compressor, 32768)) {new FileByFileV1DeltaGenerator().generateDelta(oldFile, newFile, compressedPatchOut);compressedPatchOut.finish();compressedPatchOut.flush();} finally {compressor.end();}}
}

应用补丁

import com.google.archivepatcher.applier.FileByFileV1DeltaApplier;
import com.google.archivepatcher.shared.DefaultDeflateCompatibilityWindow;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;/** Apply a patch; args are old file path, patch file path, and new file path. */
public class SamplePatchApplier {public static void main(String... args) throws Exception {if (!new DefaultDeflateCompatibilityWindow().isCompatible()) {System.err.println("zlib not compatible on this system");System.exit(-1);}File oldFile = new File(args[0]); // must be a zip archive args[0]为旧版本文件地址Inflater uncompressor = new Inflater(true); // to uncompress the patchtry (FileInputStream compressedPatchIn = new FileInputStream(args[1]); // args[1]补丁文件地址InflaterInputStream patchIn =new InflaterInputStream(compressedPatchIn, uncompressor, 32768);FileOutputStream newFileOut = new FileOutputStream(args[2])) { // args[2]合成文件地址new FileByFileV1DeltaApplier().applyDelta(oldFile, patchIn, newFileOut);} finally {uncompressor.end();}}
}
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"Google Archive Patch 基础应用代码记录":http://eshow365.cn/6-31257-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!