Class ResponsiveBuilder.BatchBuilder

java.lang.Object
cloud.opencode.base.image.responsive.ResponsiveBuilder.BatchBuilder
Enclosing class:
ResponsiveBuilder

public static final class ResponsiveBuilder.BatchBuilder extends Object
Batch Builder for processing multiple source images with the same variant/format configuration. 批量构建器,使用相同的变体/格式配置处理多个源图片。

Supports parallel processing and per-source error handling.

支持并行处理和每个源的错误处理。

Usage Examples | 使用示例:

ResponsiveBuilder.batch(List.of(path1, path2))
    .variant(64, 64, "icon")
    .formats(ImageFormat.JPEG)
    .parallel(4)
    .onError(e -> log.warn("Skipping: {}", e.getMessage()))
    .generate(outputDir);

Security | 安全性:

  • Thread-safe: No (builder pattern) - 线程安全: 否(构建器模式)
Since:
JDK 25, opencode-base-image V2.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • variant

      public ResponsiveBuilder.BatchBuilder variant(int width, int height, String name)
      Add a variant configuration. 添加变体配置。
      Parameters:
      width - the target width | 目标宽度
      height - the target height | 目标高度
      name - the variant name | 变体名称
      Returns:
      this builder for chaining | 用于链式调用的构建器
    • formats

      public ResponsiveBuilder.BatchBuilder formats(ImageFormat... formats)
      Set the output formats. 设置输出格式。
      Parameters:
      formats - the output formats | 输出格式
      Returns:
      this builder for chaining | 用于链式调用的构建器
    • quality

      public ResponsiveBuilder.BatchBuilder quality(float quality)
      Set the compression quality. 设置压缩质量。
      Parameters:
      quality - quality from 0.0 to 1.0 | 质量(0.0 到 1.0)
      Returns:
      this builder for chaining | 用于链式调用的构建器
    • parallel

      public ResponsiveBuilder.BatchBuilder parallel(int threads)
      Set the number of parallel threads for batch processing. 设置批量处理的并行线程数。
      Parameters:
      threads - number of threads (must be positive, default 1) | 线程数(必须为正数,默认 1)
      Returns:
      this builder for chaining | 用于链式调用的构建器
      Throws:
      IllegalArgumentException - if threads is not positive | 如果线程数非正数
    • onError

      Set an error handler for per-source failures. When set, processing continues for remaining sources after a failure. 设置每个源失败时的错误处理器。设置后,失败后继续处理剩余的源。
      Parameters:
      handler - the error handler | 错误处理器
      Returns:
      this builder for chaining | 用于链式调用的构建器
    • generate

      public List<List<ResponsiveBuilder.GenerateResult>> generate(Path outputDir) throws ImageIOException
      Generate all variants for all sources. Creates a subdirectory per source file name under the given output directory. 为所有源生成所有变体。在给定输出目录下为每个源文件名创建子目录。
      Parameters:
      outputDir - the root output directory | 根输出目录
      Returns:
      list of results per source (outer list corresponds to sources) | 每个源的结果列表
      Throws:
      IllegalStateException - if no variants configured | 如果未配置变体
      ImageIOException - if processing fails and no error handler is set | 如果处理失败且未设置错误处理器