Record Class ZipOptions
- Record Components:
compressionLevel- compression level0..9| 压缩级别0..9password- encryption password, ornullfor none | 加密口令,null不加密encryption- encryption method | 加密方式zip64- whether to enable ZIP64 extensions | 是否启用 ZIP64encoding- filename encoding (default"UTF-8") | 文件名编码(默认"UTF-8")includeRootDir- include the root directory when compressing | 压缩时是否包含根目录overwrite- overwrite policy during extraction | 解压覆盖策略excludePatterns- glob patterns for files to exclude — each pattern is tested against BOTH the full entry path AND the file-name leaf to be lenient with simple"*.log"style. Callers wanting strict path matching (no leaf fallback) should use"**/*.log"explicitly. | 排除文件的 glob 模式 — 每个模式同时对完整条目路径与叶子文件名匹配, 兼容简单形式如"*.log";需要严格路径匹配(不走叶子兜底)时 请显式使用"**/*.log"bombProtection- anti-bomb threshold preset | 反炸弹阈值组
Provides comprehensive control: compression level, password encryption, ZIP64,
filename encoding, overwrite policy, file exclusion globs, and ZIP-bomb protection
thresholds (grouped into a BombProtection nested record).
提供完整控制:压缩级别、密码加密、ZIP64、文件名编码、覆盖策略、文件排除 glob,以及
ZIP 炸弹防护阈值(聚合为 BombProtection 嵌套记录)。
Usage Examples | 使用示例:
// Defaults
ZipOptions opts = ZipOptions.defaults();
// Custom via builder — individual cap setters route to a builder-local BombProtection
ZipOptions opts = ZipOptions.builder()
.compressionLevel(9)
.password("secret")
.encryption(EncryptionMethod.AES_256)
.zip64(true)
.maxCompressionRatio(200) // routed into bombProtection
.addExcludePattern("*.log")
.build();
// Or pass a BombProtection preset directly
ZipOptions opts = ZipOptions.builder()
.bombProtection(new BombProtection(20, 100L*1024*1024, 1000, 1, 50L*1024*1024))
.build();
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全:是(不可变记录)
- Null-safe: Yes — null fields are normalised in canonical constructor — 空值安全:是,规范构造器将 null 字段归一化
Naming convention | 命名约定: boolean record components follow the
canonical record style and are exposed as includeRootDir() / zip64() (no
is prefix). Note that ZipEntryInfo.isDirectory() predates this record and
uses the JavaBean is prefix — kept stable for binary compatibility with V1.0.3.
布尔字段访问器遵循记录习惯,不带 is 前缀(includeRootDir() /
zip64())。ZipEntryInfo.isDirectory() 早于本记录,沿用 JavaBean 风格的
is 前缀以与 V1.0.3 二进制兼容,故不一致是有意保留的。
- Since:
- JDK 25, opencode-base-io V1.0.4
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionZipOptions(int compressionLevel, String password, EncryptionMethod encryption, boolean zip64, String encoding, boolean includeRootDir, OverwritePolicy overwrite, List<String> excludePatterns, BombProtection bombProtection) Canonical constructor with normalisation and validation. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thebombProtectionrecord component.static ZipOptions.Builderbuilder()Create a fluent builder.intReturns the value of thecompressionLevelrecord component.static ZipOptionsdefaults()Default options: level 6, no password, UTF-8, OVERWRITE, defaultBombProtection.encoding()Returns the value of theencodingrecord component.Returns the value of theencryptionrecord component.final booleanIndicates whether some other object is "equal to" this one.Returns the value of theexcludePatternsrecord component.final inthashCode()Returns a hash code value for this object.booleanReturns the value of theincludeRootDirrecord component.longEquivalent tobombProtection().maxCompressionRatio(). / 等价于bombProtection().maxCompressionRatio()。intEquivalent tobombProtection().maxEntryCount(). / 等价于bombProtection().maxEntryCount()。intEquivalent tobombProtection().maxNestingDepth(). / 等价于bombProtection().maxNestingDepth()。longEquivalent tobombProtection().maxSingleEntrySize(). / 等价于bombProtection().maxSingleEntrySize()。longEquivalent tobombProtection().maxTotalSize(). / 等价于bombProtection().maxTotalSize()。Returns the value of theoverwriterecord component.password()Returns the value of thepasswordrecord component.toString()Returns atoStringthat redactspassword().booleanzip64()Returns the value of thezip64record component.
-
Constructor Details
-
ZipOptions
public ZipOptions(int compressionLevel, String password, EncryptionMethod encryption, boolean zip64, String encoding, boolean includeRootDir, OverwritePolicy overwrite, List<String> excludePatterns, BombProtection bombProtection) Canonical constructor with normalisation and validation. 带归一化与校验的规范构造器。
-
-
Method Details
-
maxCompressionRatio
public long maxCompressionRatio()Equivalent tobombProtection().maxCompressionRatio(). / 等价于bombProtection().maxCompressionRatio()。- Returns:
- max compression ratio | 最大压缩比
-
maxTotalSize
public long maxTotalSize()Equivalent tobombProtection().maxTotalSize(). / 等价于bombProtection().maxTotalSize()。- Returns:
- max total decompressed bytes | 最大解压总字节
-
maxEntryCount
public int maxEntryCount()Equivalent tobombProtection().maxEntryCount(). / 等价于bombProtection().maxEntryCount()。- Returns:
- max entry count | 最大条目数
-
maxNestingDepth
public int maxNestingDepth()Equivalent tobombProtection().maxNestingDepth(). / 等价于bombProtection().maxNestingDepth()。- Returns:
- max nested-zip depth | 嵌套 ZIP 最大深度
-
maxSingleEntrySize
public long maxSingleEntrySize()Equivalent tobombProtection().maxSingleEntrySize(). / 等价于bombProtection().maxSingleEntrySize()。- Returns:
- max single entry size | 单条目最大字节
-
toString
Returns atoStringthat redactspassword(). The auto-generated recordtoStringwould otherwise print the password verbatim, leaking it into any debug log, exception-context dump, MDC, or telemetry that snapshots configuration objects. 返回会脱敏password()的toString。否则记录自动生成的toString会原文打印口令,泄漏到调试日志、异常上下文、MDC 或快照配置对象的遥测中。 -
defaults
Default options: level 6, no password, UTF-8, OVERWRITE, defaultBombProtection. 默认选项:级别 6,无密码,UTF-8,OVERWRITE,默认BombProtection。- Returns:
- default options | 默认选项
-
builder
Create a fluent builder. 创建流式 Builder。- Returns:
- new builder | 新 Builder
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
compressionLevel
public int compressionLevel()Returns the value of thecompressionLevelrecord component.- Returns:
- the value of the
compressionLevelrecord component
-
password
-
encryption
Returns the value of theencryptionrecord component.- Returns:
- the value of the
encryptionrecord component
-
zip64
-
encoding
-
includeRootDir
public boolean includeRootDir()Returns the value of theincludeRootDirrecord component.- Returns:
- the value of the
includeRootDirrecord component
-
overwrite
-
excludePatterns
Returns the value of theexcludePatternsrecord component.- Returns:
- the value of the
excludePatternsrecord component
-
bombProtection
Returns the value of thebombProtectionrecord component.- Returns:
- the value of the
bombProtectionrecord component
-