Class OpenIOOperationException

All Implemented Interfaces:
OpenExceptionMeta, Serializable
Direct Known Subclasses:
ZipBombDetectedException

public class OpenIOOperationException extends OpenException
IO Operation Exception (Unchecked) IO操作异常(非受检)

Unchecked exception for IO operations that wraps checked IOException. Simplifies caller code by eliminating mandatory try-catch blocks.

用于IO操作的非受检异常,封装受检的IOException。 通过消除强制性的try-catch块来简化调用方代码。

Features | 主要功能:

  • Unchecked exception wrapper - 非受检异常包装
  • Operation and path tracking - 操作和路径追踪
  • Factory methods for common errors - 常见错误的工厂方法

Usage Examples | 使用示例:

// Create with factory method
throw OpenIOOperationException.fileNotFound(path);

// Create with operation details
throw new OpenIOOperationException("read", path.toString(), "File not readable");

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
  • Null-safe: Yes, operation and path may be null - 空值安全: 是,operation和path可以为null
Since:
JDK 25, opencode-base-io V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenIOOperationException

      public OpenIOOperationException(String message)
      Creates an exception with message 创建带消息的异常
      Parameters:
      message - the error message | 错误消息
    • OpenIOOperationException

      public OpenIOOperationException(String message, Throwable cause)
      Creates an exception with message and cause 创建带消息和原因的异常
      Parameters:
      message - the error message | 错误消息
      cause - the cause | 原因
    • OpenIOOperationException

      public OpenIOOperationException(String operation, String path, String message)
      Creates an exception with operation, path and message 创建带操作、路径和消息的异常
      Parameters:
      operation - the operation type | 操作类型
      path - the path involved | 涉及的路径
      message - the error message | 错误消息
    • OpenIOOperationException

      public OpenIOOperationException(String operation, String path, String message, Throwable cause)
      Creates an exception with operation, path, message and cause 创建带操作、路径、消息和原因的异常
      Parameters:
      operation - the operation type | 操作类型
      path - the path involved | 涉及的路径
      message - the error message | 错误消息
      cause - the cause | 原因
  • Method Details

    • operation

      public String operation()
      Gets the operation type 获取操作类型
      Returns:
      operation type | 操作类型
    • path

      public String path()
      Gets the path involved 获取涉及的路径
      Returns:
      path | 路径
    • fileNotFound

      public static OpenIOOperationException fileNotFound(Path path)
      Creates a file not found exception 创建文件未找到异常
      Parameters:
      path - the file path | 文件路径
      Returns:
      exception instance | 异常实例
    • resourceNotFound

      public static OpenIOOperationException resourceNotFound(String resource)
      Creates a resource not found exception 创建资源未找到异常
      Parameters:
      resource - the resource name | 资源名称
      Returns:
      exception instance | 异常实例
    • readFailed

      public static OpenIOOperationException readFailed(Path path, Throwable cause)
      Creates a read failed exception 创建读取失败异常
      Parameters:
      path - the file path | 文件路径
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • readFailed

      public static OpenIOOperationException readFailed(Throwable cause)
      Creates a read failed exception for stream 创建流读取失败异常
      Parameters:
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • writeFailed

      public static OpenIOOperationException writeFailed(Path path, Throwable cause)
      Creates a write failed exception 创建写入失败异常
      Parameters:
      path - the file path | 文件路径
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • writeFailed

      public static OpenIOOperationException writeFailed(Throwable cause)
      Creates a write failed exception for stream 创建流写入失败异常
      Parameters:
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • copyFailed

      public static OpenIOOperationException copyFailed(Path source, Path target, Throwable cause)
      Creates a copy failed exception 创建复制失败异常
      Parameters:
      source - the source path | 源路径
      target - the target path | 目标路径
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • moveFailed

      public static OpenIOOperationException moveFailed(Path source, Path target, Throwable cause)
      Creates a move failed exception 创建移动失败异常
      Parameters:
      source - the source path | 源路径
      target - the target path | 目标路径
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • deleteFailed

      public static OpenIOOperationException deleteFailed(Path path, Throwable cause)
      Creates a delete failed exception 创建删除失败异常
      Parameters:
      path - the path | 路径
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • createFileFailed

      public static OpenIOOperationException createFileFailed(Path path, Throwable cause)
      Creates a create file failed exception 创建文件创建失败异常
      Parameters:
      path - the path | 路径
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • createDirectoryFailed

      public static OpenIOOperationException createDirectoryFailed(Path path, Throwable cause)
      Creates a create directory failed exception 创建目录创建失败异常
      Parameters:
      path - the path | 路径
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • streamOperationFailed

      public static OpenIOOperationException streamOperationFailed(String operation, Throwable cause)
      Creates a stream operation failed exception 创建流操作失败异常
      Parameters:
      operation - the operation name | 操作名称
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • sizeLimitExceeded

      public static OpenIOOperationException sizeLimitExceeded(long maxSize, long actualSize)
      Creates a size limit exceeded exception 创建大小超限异常
      Parameters:
      maxSize - the max size | 最大大小
      actualSize - the actual size | 实际大小
      Returns:
      exception instance | 异常实例
    • invalidPath

      public static OpenIOOperationException invalidPath(String path, Throwable cause)
      Creates an invalid path exception 创建无效路径异常
      Parameters:
      path - the path | 路径
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • watchFailed

      public static OpenIOOperationException watchFailed(Path path, Throwable cause)
      Creates a watch failed exception 创建监听失败异常
      Parameters:
      path - the path | 路径
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例
    • checksumFailed

      public static OpenIOOperationException checksumFailed(String algorithm, Throwable cause)
      Creates a checksum failed exception 创建校验和计算失败异常
      Parameters:
      algorithm - the algorithm | 算法
      cause - the cause | 原因
      Returns:
      exception instance | 异常实例