Class OpenResource
java.lang.Object
cloud.opencode.base.io.OpenResource
Resource Loading Utility Class
资源加载工具类
Utility class for loading resources from classpath, filesystem, and URLs with a unified API.
用于从类路径、文件系统和URL加载资源的工具类,提供统一的API。
Features | 主要功能:
- Classpath resource loading - 类路径资源加载
- Filesystem resource loading - 文件系统资源加载
- URL resource loading - URL资源加载
- Properties loading - Properties加载
Usage Examples | 使用示例:
// Read classpath resource
String config = OpenResource.readString("application.properties");
// Read properties
Properties props = OpenResource.readProperties("config.properties");
// Check existence
if (OpenResource.exists("optional.xml")) {
// ...
}
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Since:
- JDK 25, opencode-base-io V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ResourceclassPathResource(String path) Creates a classpath resource 创建类路径资源static booleanChecks if resource exists 检查资源是否存在static ResourcefileResource(String path) Creates a filesystem resource from string 从字符串创建文件系统资源static ResourcefileResource(Path path) Creates a filesystem resource 创建文件系统资源static URLgetResource(String resourceName) Gets resource URL 获取资源URLstatic ResourceLoaderGets the resource loader 获取资源加载器static URLgetResourceRequired(String resourceName) Gets resource URL (required) 获取资源URL(必须存在)getResources(String resourceName) Gets all matching resource URLs 获取所有匹配的资源URLstatic InputStreamGets resource input stream 获取资源输入流static ResourceLoads resource using resource loader 使用资源加载器加载资源static byte[]Reads resource as byte array 读取资源为字节数组Reads resource as lines with UTF-8 使用UTF-8读取资源为行列表Reads resource as lines 读取资源为行列表static PropertiesreadProperties(String resourceName) Reads resource as Properties 读取资源为Propertiesstatic StringreadString(String resourceName) Reads resource as UTF-8 string 读取资源为UTF-8字符串static StringreadString(String resourceName, Charset charset) Reads resource as string 读取资源为字符串static ResourceurlResource(String url) Creates a URL resource from string 从字符串创建URL资源static ResourceurlResource(URL url) Creates a URL resource 创建URL资源
-
Method Details
-
getResource
-
getResourceRequired
Gets resource URL (required) 获取资源URL(必须存在)- Parameters:
resourceName- the resource name | 资源名称- Returns:
- URL | URL
- Throws:
OpenIOOperationException- if not found | 如果未找到
-
getResources
-
exists
Checks if resource exists 检查资源是否存在- Parameters:
resourceName- the resource name | 资源名称- Returns:
- true if exists | 如果存在返回true
-
getStream
Gets resource input stream 获取资源输入流- Parameters:
resourceName- the resource name | 资源名称- Returns:
- input stream | 输入流
- Throws:
OpenIOOperationException- if not found | 如果未找到
-
readBytes
Reads resource as byte array 读取资源为字节数组- Parameters:
resourceName- the resource name | 资源名称- Returns:
- byte array | 字节数组
-
readString
-
readString
-
readLines
-
readLines
-
readProperties
Reads resource as Properties 读取资源为Properties- Parameters:
resourceName- the resource name | 资源名称- Returns:
- Properties object | Properties对象
-
classPathResource
-
fileResource
-
fileResource
-
urlResource
-
urlResource
-
getResourceLoader
Gets the resource loader 获取资源加载器- Returns:
- resource loader | 资源加载器
-
load
-