Class SafeImageService
java.lang.Object
cloud.opencode.base.image.security.SafeImageService
- All Implemented Interfaces:
AutoCloseable
Safe Image Service
安全图片服务
Thread-safe image processing service with security controls.
带安全控制的线程安全图片处理服务。
Features | 特性:
- Size validation | 大小验证
- Timeout control | 超时控制
- Concurrency limits | 并发限制
- Memory estimation | 内存估算
Usage Examples | 使用示例:
SafeImageService service = SafeImageService.builder()
.maxFileSize(5_000_000)
.maxWidth(4000)
.maxHeight(4000)
.timeout(Duration.ofSeconds(30))
.maxConcurrent(10)
.build();
Image image = service.read(path);
service.process(image, img -> img.resize(800, 600));
- Since:
- JDK 25, opencode-base-image V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSafe Image Service Builder 安全图片服务构建器 -
Constructor Summary
ConstructorsConstructorDescriptionSafeImageService(long maxFileSize, int maxWidth, int maxHeight, Duration timeout, int maxConcurrent) Create safe image service 创建安全图片服务 -
Method Summary
Modifier and TypeMethodDescriptionstatic SafeImageService.Builderbuilder()Create builder 创建构建器voidclose()static SafeImageServiceCreate with default settings 使用默认设置创建intGet active operation count 获取活动操作数intGet available permits 获取可用许可数Get image info safely 安全获取图片信息process(Image image, ImageOperation operation) Process image with operation 使用操作处理图片read(byte[] bytes) Read image safely from bytes 从字节数组安全读取图片Read image safely from path 从路径安全读取图片voidSave image safely 安全保存图片
-
Constructor Details
-
SafeImageService
public SafeImageService(long maxFileSize, int maxWidth, int maxHeight, Duration timeout, int maxConcurrent) Create safe image service 创建安全图片服务- Parameters:
maxFileSize- maximum file size in bytes | 最大文件大小(字节)maxWidth- maximum width | 最大宽度maxHeight- maximum height | 最大高度timeout- operation timeout | 操作超时时间maxConcurrent- maximum concurrent operations | 最大并发操作数
-
-
Method Details
-
builder
-
createDefault
Create with default settings 使用默认设置创建- Returns:
- the service | 服务
-
read
Read image safely from path 从路径安全读取图片- Parameters:
path- the file path | 文件路径- Returns:
- the image | 图片
- Throws:
ImageException- if reading or validation fails | 如果读取或验证失败
-
read
Read image safely from bytes 从字节数组安全读取图片- Parameters:
bytes- the image bytes | 图片字节数组- Returns:
- the image | 图片
- Throws:
ImageException- if reading or validation fails | 如果读取或验证失败
-
process
Process image with operation 使用操作处理图片- Parameters:
image- the image | 图片operation- the operation | 操作- Returns:
- the processed image | 处理后的图片
- Throws:
ImageException- if processing fails | 如果处理失败
-
save
Save image safely 安全保存图片- Parameters:
image- the image | 图片path- the output path | 输出路径baseDir- the base directory for validation | 用于验证的基础目录- Throws:
ImageException- if saving fails | 如果保存失败
-
getInfo
Get image info safely 安全获取图片信息- Parameters:
path- the file path | 文件路径- Returns:
- the image info | 图片信息
- Throws:
ImageException- if reading fails | 如果读取失败
-
getActiveCount
public int getActiveCount()Get active operation count 获取活动操作数- Returns:
- the count | 数量
-
getAvailablePermits
public int getAvailablePermits()Get available permits 获取可用许可数- Returns:
- the available permits | 可用许可数
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-