Class OpenIOException

All Implemented Interfaces:
OpenExceptionMeta, Serializable

public class OpenIOException extends OpenException
IO Exception Wrapper - Wrap checked IOException as unchecked IO 异常包装 - 将受检 IOException 包装为非受检异常

Wraps checked IOException as unchecked exception to simplify exception handling.

将受检的 IOException 包装为非受检异常,简化异常处理。

Features | 主要功能:

  • Wrap IOException (wrap) - 包装 IOException
  • Read failure factory (readFailed) - 读取失败工厂
  • Write failure factory (writeFailed) - 写入失败工厂
  • File not found factory (fileNotFound) - 文件未找到工厂
  • Close failure factory (closeFailed) - 关闭失败工厂

Usage Examples | 使用示例:

try {
    Files.readString(path);
} catch (IOException e) {
    throw new OpenIOException("Failed to read file", e);
}

// Static factory methods - 静态工厂方法
throw OpenIOException.readFailed(path, e);
throw OpenIOException.writeFailed(path, e);
throw OpenIOException.fileNotFound(path);

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是 (不可变)
  • Serializable: Yes - 可序列化: 是
Since:
JDK 25, opencode-base-core V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenIOException

      public OpenIOException(String message)
      Creates 创建 IO 异常
      Parameters:
      message - the value | 异常消息
    • OpenIOException

      public OpenIOException(String message, Throwable cause)
      Creates 创建 IO 异常(包装原始 IOException)
      Parameters:
      message - the value | 异常消息
      cause - the value | 原始异常
    • OpenIOException

      public OpenIOException(String errorCode, String message, Throwable cause)
      Creates 创建 IO 异常(指定错误码)
      Parameters:
      errorCode - the value | 错误码
      message - the value | 异常消息
      cause - the value | 原始异常
  • Method Details

    • wrap

      public static OpenIOException wrap(IOException cause)
      Wraps 包装 IOException
      Parameters:
      cause - the value | 原始 IOException
      Returns:
      the result | 异常实例
    • readFailed

      public static OpenIOException readFailed(Path path, Throwable cause)
      Creates 创建"读取失败"异常
      Parameters:
      path - the value | 文件路径
      cause - the value | 原始异常
      Returns:
      the result | 异常实例
    • readFailed

      public static OpenIOException readFailed(String resource, Throwable cause)
      Creates 创建"读取失败"异常
      Parameters:
      resource - the value | 资源名
      cause - the value | 原始异常
      Returns:
      the result | 异常实例
    • writeFailed

      public static OpenIOException writeFailed(Path path, Throwable cause)
      Creates 创建"写入失败"异常
      Parameters:
      path - the value | 文件路径
      cause - the value | 原始异常
      Returns:
      the result | 异常实例
    • writeFailed

      public static OpenIOException writeFailed(String resource, Throwable cause)
      Creates 创建"写入失败"异常
      Parameters:
      resource - the value | 资源名
      cause - the value | 原始异常
      Returns:
      the result | 异常实例
    • fileNotFound

      public static OpenIOException fileNotFound(Path path)
      Creates 创建"文件未找到"异常
      Parameters:
      path - the value | 文件路径
      Returns:
      the result | 异常实例
    • fileNotFound

      public static OpenIOException fileNotFound(String resource)
      Creates 创建"文件未找到"异常
      Parameters:
      resource - the value | 资源名
      Returns:
      the result | 异常实例
    • closeFailed

      public static OpenIOException closeFailed(String resource, Throwable cause)
      Creates 创建"关闭资源失败"异常
      Parameters:
      resource - the value | 资源名
      cause - the value | 原始异常
      Returns:
      the result | 异常实例