Class OpenBatch
java.lang.Object
cloud.opencode.base.io.batch.OpenBatch
Batch and Parallel File Operations Utility Class
批量和并行文件操作工具类
Provides batch operations for copying, moving, and deleting multiple files with parallel execution support and progress tracking.
提供批量复制、移动和删除多个文件的操作,支持并行执行和进度跟踪。
Features | 主要功能:
- Batch copy/move/delete operations - 批量复制/移动/删除
- Parallel execution with configurable parallelism - 可配置并行度的并行执行
- Progress callbacks - 进度回调
- Failure handling and result collection - 失败处理和结果收集
Usage Examples | 使用示例:
// Batch copy files
List<Path> files = List.of(path1, path2, path3);
BatchResult result = OpenBatch.copyAll(files, targetDir);
// Parallel delete with progress
BatchResult result = OpenBatch.parallel()
.parallelism(4)
.onProgress((path, index, total) -> System.out.println("Processing: " + path))
.deleteAll(files);
// Batch move with filter
BatchResult result = OpenBatch.moveAll(files, targetDir,
path -> path.toString().endsWith(".txt"));
Security | 安全性:
- Thread-safe: Yes, parallel operations use virtual threads - 线程安全: 是,并行操作使用虚拟线程
- Null-safe: No, paths and arguments must not be null - 空值安全: 否,路径和参数不可为null
- Since:
- JDK 25, opencode-base-io V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classParallel Batch Operation Builder 并行批量操作构建器static interfacePath action interface 路径操作接口static interfaceProgress callback interface 进度回调接口 -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault parallelism (number of processors) 默认并行度(处理器数量) -
Method Summary
Modifier and TypeMethodDescriptioncollectByExtension(Path dir, String... extensions) Collect files by extension 按扩展名收集文件collectFiles(Path dir) Collect files from directory 从目录收集文件collectGlob(Path dir, String pattern) Collect files matching glob pattern 收集匹配 glob 模式的文件static BatchResultcopyAll(Collection<Path> sources, Path targetDir, CopyOption... options) Copy all files to target directory 复制所有文件到目标目录static BatchResultcopyAll(Collection<Path> sources, Path targetDir, Predicate<Path> filter, CopyOption... options) Copy files matching filter to target directory 复制匹配过滤器的文件到目标目录static BatchResultcopyGlob(Path sourceDir, String pattern, Path targetDir, CopyOption... options) Copy files matching glob pattern 复制匹配 glob 模式的文件static BatchResultdeleteAll(Collection<Path> paths) Delete all files 删除所有文件static BatchResultdeleteAll(Collection<Path> paths, Predicate<Path> filter) Delete files matching filter 删除匹配过滤器的文件static BatchResultdeleteGlob(Path dir, String pattern) Delete files matching glob pattern 删除匹配 glob 模式的文件static BatchResultmoveAll(Collection<Path> sources, Path targetDir, CopyOption... options) Move all files to target directory 移动所有文件到目标目录static BatchResultmoveAll(Collection<Path> sources, Path targetDir, Predicate<Path> filter, CopyOption... options) Move files matching filter to target directory 移动匹配过滤器的文件到目标目录static BatchResultmoveGlob(Path sourceDir, String pattern, Path targetDir, CopyOption... options) Move files matching glob pattern 移动匹配 glob 模式的文件static OpenBatch.ParallelBuilderparallel()Create a parallel batch operation builder 创建并行批量操作构建器
-
Field Details
-
DEFAULT_PARALLELISM
public static final int DEFAULT_PARALLELISMDefault parallelism (number of processors) 默认并行度(处理器数量)
-
-
Method Details
-
copyAll
Copy all files to target directory 复制所有文件到目标目录- Parameters:
sources- source files | 源文件targetDir- target directory | 目标目录options- copy options | 复制选项- Returns:
- batch result | 批量结果
-
copyAll
public static BatchResult copyAll(Collection<Path> sources, Path targetDir, Predicate<Path> filter, CopyOption... options) Copy files matching filter to target directory 复制匹配过滤器的文件到目标目录- Parameters:
sources- source files | 源文件targetDir- target directory | 目标目录filter- file filter | 文件过滤器options- copy options | 复制选项- Returns:
- batch result | 批量结果
-
moveAll
Move all files to target directory 移动所有文件到目标目录- Parameters:
sources- source files | 源文件targetDir- target directory | 目标目录options- move options | 移动选项- Returns:
- batch result | 批量结果
-
moveAll
public static BatchResult moveAll(Collection<Path> sources, Path targetDir, Predicate<Path> filter, CopyOption... options) Move files matching filter to target directory 移动匹配过滤器的文件到目标目录- Parameters:
sources- source files | 源文件targetDir- target directory | 目标目录filter- file filter | 文件过滤器options- move options | 移动选项- Returns:
- batch result | 批量结果
-
deleteAll
Delete all files 删除所有文件- Parameters:
paths- files to delete | 要删除的文件- Returns:
- batch result | 批量结果
-
deleteAll
Delete files matching filter 删除匹配过滤器的文件- Parameters:
paths- files to delete | 要删除的文件filter- file filter | 文件过滤器- Returns:
- batch result | 批量结果
-
copyGlob
public static BatchResult copyGlob(Path sourceDir, String pattern, Path targetDir, CopyOption... options) Copy files matching glob pattern 复制匹配 glob 模式的文件- Parameters:
sourceDir- source directory | 源目录pattern- glob pattern | glob 模式targetDir- target directory | 目标目录options- copy options | 复制选项- Returns:
- batch result | 批量结果
-
moveGlob
public static BatchResult moveGlob(Path sourceDir, String pattern, Path targetDir, CopyOption... options) Move files matching glob pattern 移动匹配 glob 模式的文件- Parameters:
sourceDir- source directory | 源目录pattern- glob pattern | glob 模式targetDir- target directory | 目标目录options- move options | 移动选项- Returns:
- batch result | 批量结果
-
deleteGlob
Delete files matching glob pattern 删除匹配 glob 模式的文件- Parameters:
dir- directory | 目录pattern- glob pattern | glob 模式- Returns:
- batch result | 批量结果
-
parallel
Create a parallel batch operation builder 创建并行批量操作构建器- Returns:
- builder | 构建器
-
collectFiles
-
collectGlob
-
collectByExtension
-