Class ZipOptions.Builder

java.lang.Object
cloud.opencode.base.io.compress.ZipOptions.Builder
Enclosing class:
ZipOptions

public static final class ZipOptions.Builder extends Object
Fluent builder for ZipOptions. ZipOptions 的流式 Builder。

The 5 anti-bomb cap setters (maxCompressionRatio / maxTotalSize / maxEntryCount / maxNestingDepth / maxSingleEntrySize) mutate a builder-local copy of BombProtection; callers who prefer to compose the preset upfront can use bombProtection(BombProtection) directly.

5 个反炸弹上限 setter 修改 builder 本地的 BombProtection 副本;偏好整体设置预设时 可直接使用 bombProtection(BombProtection)

Since:
JDK 25, opencode-base-io V1.0.4
Author:
Leon Soo www.LeonSoo.com
  • Method Details

    • compressionLevel

      public ZipOptions.Builder compressionLevel(int level)
      Sets the compression level in the [0, 9] range. 设置压缩级别(0..9)。
      Parameters:
      level - compression level | 压缩级别
      Returns:
      this builder | 当前 builder
    • password

      public ZipOptions.Builder password(String password)
      Sets the encryption password, or null to disable. 设置加密口令,null 表示不加密。
      Parameters:
      password - password or null | 口令或 null
      Returns:
      this builder | 当前 builder
    • encryption

      public ZipOptions.Builder encryption(EncryptionMethod encryption)
      Sets the encryption method. Note: ZipUtil rejects any non-EncryptionMethod.NONE value because base does not bundle an AES engine. 设置加密方式。注意:base 不内置 AES 引擎,ZipUtil 会拒绝任何非 EncryptionMethod.NONE 值。
      Parameters:
      encryption - encryption method | 加密方式
      Returns:
      this builder | 当前 builder
    • zip64

      public ZipOptions.Builder zip64(boolean zip64)
      Enables or disables ZIP64 extensions for archives larger than 4 GiB or with more than 65535 entries. 启用或关闭 ZIP64 扩展,用于大于 4 GiB 或多于 65535 条目的归档。
      Parameters:
      zip64 - enable ZIP64 | 是否启用 ZIP64
      Returns:
      this builder | 当前 builder
    • encoding

      public ZipOptions.Builder encoding(String encoding)
      Sets the filename encoding, e.g. "UTF-8" or "GBK". 设置文件名编码,如 "UTF-8""GBK"
      Parameters:
      encoding - charset name | 字符集名
      Returns:
      this builder | 当前 builder
    • includeRootDir

      public ZipOptions.Builder includeRootDir(boolean include)
      Includes the root directory name as a prefix in entry names when compressing a directory tree. Default false produces flat entries. 压缩目录树时,是否在条目名中保留根目录前缀。默认 false 产出扁平条目。
      Parameters:
      include - include root directory | 是否包含根目录
      Returns:
      this builder | 当前 builder
    • overwrite

      public ZipOptions.Builder overwrite(OverwritePolicy policy)
      Sets the overwrite policy applied during extraction. See OverwritePolicy for the OVERWRITE / SKIP / FAIL semantics. 设置解压覆盖策略,详见 OverwritePolicyOVERWRITE / SKIP / FAIL)。
      Parameters:
      policy - overwrite policy | 覆盖策略
      Returns:
      this builder | 当前 builder
    • excludePatterns

      public ZipOptions.Builder excludePatterns(List<String> patterns)
      Replaces the entire exclude-pattern list with the supplied glob patterns. Passing null clears the list. 用给定 glob 模式整体替换排除列表,传 null 清空。
      Parameters:
      patterns - glob patterns | glob 模式
      Returns:
      this builder | 当前 builder
    • addExcludePattern

      public ZipOptions.Builder addExcludePattern(String pattern)
      Appends a single exclude glob pattern. 追加单个排除 glob 模式。
      Parameters:
      pattern - glob pattern | glob 模式
      Returns:
      this builder | 当前 builder
    • bombProtection

      public ZipOptions.Builder bombProtection(BombProtection protection)
      Replaces the anti-bomb preset wholesale. Useful for propagating a centrally-defined BombProtection through configuration without setting individual caps. 整体替换反炸弹预设,便于通过配置注入中心化定义的 BombProtection 而无需逐项设置。
      Parameters:
      protection - bomb protection preset (null falls back to BombProtection.defaults()) | 反炸弹预设(null 回退到 BombProtection.defaults()
      Returns:
      this builder | 当前 builder
    • maxCompressionRatio

      public ZipOptions.Builder maxCompressionRatio(long maxCompressionRatio)
      Sets the max ratio of decompressed:compressed bytes. Routes into the builder-local BombProtection. 设置最大解压:压缩字节比,写入 builder 本地的 BombProtection
      Parameters:
      maxCompressionRatio - threshold | 阈值
      Returns:
      this builder | 当前 builder
    • maxTotalSize

      public ZipOptions.Builder maxTotalSize(long maxTotalSize)
      Sets the max total decompressed bytes across all entries. 设置所有条目累计的最大解压字节。
      Parameters:
      maxTotalSize - threshold | 阈值
      Returns:
      this builder | 当前 builder
    • maxEntryCount

      public ZipOptions.Builder maxEntryCount(int maxEntryCount)
      Sets the max number of entries permitted in a single archive. 设置单个归档允许的最大条目数。
      Parameters:
      maxEntryCount - threshold | 阈值
      Returns:
      this builder | 当前 builder
    • maxNestingDepth

      public ZipOptions.Builder maxNestingDepth(int maxNestingDepth)
      Sets the max nested-ZIP depth (detected by .zip suffix; payload not magic-byte sniffed). 设置嵌套 ZIP 最大深度(按 .zip 后缀识别,不做魔数嗅探)。
      Parameters:
      maxNestingDepth - threshold | 阈值
      Returns:
      this builder | 当前 builder
    • maxSingleEntrySize

      public ZipOptions.Builder maxSingleEntrySize(long maxSingleEntrySize)
      Sets the max decompressed bytes for any single entry. 设置单条目解压字节上限。
      Parameters:
      maxSingleEntrySize - threshold | 阈值
      Returns:
      this builder | 当前 builder
    • build

      public ZipOptions build()
      Builds an immutable ZipOptions, assembling the 5 anti-bomb caps into a fresh BombProtection. 构建不可变 ZipOptions,把 5 个反炸弹上限装配为新的 BombProtection
      Returns:
      new ZipOptions | 新 ZipOptions