• Google Archive Patch 基础应用代码记录


    项目地址

    Google Archive Patch

    前置

    
    <dependency>
        <groupId>com.google.archivepatchergroupId>
        <artifactId>archive-patch-applierartifactId>
        <version>1.0.4version>
        <scope>testscope>
    dependency>
    
     <dependency>
        <groupId>com.google.archivepatchergroupId>
        <artifactId>archive-patch-generatorartifactId>
        <version>1.0.4version>
    dependency>
    
    <dependency>
        <groupId>com.google.archivepatchergroupId>
        <artifactId>archive-patch-sharedartifactId>
        <version>1.0.4version>
    dependency>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    生成补丁

    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 archive
        File newFile = new File(args[1]); // must be a zip archive
        Deflater compressor = new Deflater(9, true); // to compress the patch
        try (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();
        }
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    应用补丁

    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 patch
        try (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();
        }
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
  • 相关阅读:
    k8s遇到的错误记录
    Vue3.x的设计理念-Vue3导读
    ZZULIOJ1038: 绝对值最大
    【学生管理系统】学生管理(重点)
    如何修改NX二次开发菜单到NX自带的标签页
    PostgreSQL 认证方式
    3.6 OrCAD中元器件应该怎么进行镜像与翻转?
    z-index属性什么情况下会失效
    AI实用技巧 | 5分钟将coze集成到微信群机器人
    全面了解链上身份之Web3社交及相关项目
  • 原文地址:https://blog.csdn.net/qq_34354257/article/details/134119175