Class ClassPathResource
java.lang.Object
cloud.opencode.base.classloader.resource.AbstractResource
cloud.opencode.base.classloader.resource.ClassPathResource
- All Implemented Interfaces:
Resource
ClassPath Resource - Resource loaded from classpath
ClassPath 资源 - 从 classpath 加载的资源
Represents a resource that can be loaded from the classpath.
表示可以从 classpath 加载的资源。
Features | 主要功能:
- Load resources from classpath - 从 classpath 加载资源
- Support custom ClassLoader - 支持自定义 ClassLoader
- Relative resource creation - 相对资源创建
Usage Examples | 使用示例:
Resource resource = new ClassPathResource("config.yml");
Resource resource = new ClassPathResource("config.yml", customClassLoader);
String content = resource.getString();
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-classloader V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionClassPathResource(String path) Create classpath resource with default classloader 使用默认类加载器创建 classpath 资源ClassPathResource(String path, ClassLoader classLoader) Create classpath resource with specified classloader 使用指定类加载器创建 classpath 资源 -
Method Summary
Modifier and TypeMethodDescriptioncreateRelative(String relativePath) Create relative resource 创建相对资源booleanexists()Check if resource exists 检查资源是否存在Get the class loader 获取类加载器Get resource description 获取资源描述Get filename 获取文件名Get input stream for resource 获取资源的输入流Get the resource path 获取资源路径getUrl()Get resource URL 获取资源 URLMethods inherited from class AbstractResource
contentLength, equals, getFile, getPath, getUri, hashCode, isFile, isReadable, lastModified, toString
-
Constructor Details
-
ClassPathResource
Create classpath resource with default classloader 使用默认类加载器创建 classpath 资源- Parameters:
path- resource path | 资源路径
-
ClassPathResource
Create classpath resource with specified classloader 使用指定类加载器创建 classpath 资源- Parameters:
path- resource path | 资源路径classLoader- class loader | 类加载器
-
-
Method Details
-
exists
public boolean exists()Description copied from interface:ResourceCheck if resource exists 检查资源是否存在- Specified by:
existsin interfaceResource- Overrides:
existsin classAbstractResource- Returns:
- true if exists | 存在返回 true
-
getInputStream
Description copied from interface:ResourceGet input stream for resource 获取资源的输入流- Returns:
- input stream | 输入流
- Throws:
IOException- if cannot open stream | 无法打开流时抛出
-
getUrl
Description copied from interface:ResourceGet resource URL 获取资源 URL- Returns:
- resource URL | 资源 URL
- Throws:
IOException- if cannot get URL | 无法获取 URL 时抛出
-
getFilename
Description copied from interface:ResourceGet filename 获取文件名- Specified by:
getFilenamein interfaceResource- Overrides:
getFilenamein classAbstractResource- Returns:
- filename or null | 文件名或 null
-
getDescription
-
createRelative
Description copied from interface:ResourceCreate relative resource 创建相对资源- Parameters:
relativePath- relative path | 相对路径- Returns:
- relative resource | 相对资源
- Throws:
IOException- if cannot create relative resource | 无法创建相对资源时抛出
-
getResourcePath
-
getClassLoader
-