Class UrlResource
java.lang.Object
cloud.opencode.base.io.resource.UrlResource
- All Implemented Interfaces:
Resource
URL Resource Implementation
URL资源实现
Resource implementation for resources accessible via URL. Supports http, https, ftp, file and other URL protocols.
用于通过URL访问资源的资源实现。 支持http、https、ftp、file和其他URL协议。
Features | 主要功能:
- URL-based resource access - 基于URL的资源访问
- Multiple protocol support - 多协议支持
- Immutable and thread-safe - 不可变且线程安全
Usage Examples | 使用示例:
UrlResource resource = new UrlResource(new URL("https://example.com/config.json"));
String content = resource.readString();
- Since:
- JDK 25, opencode-base-io V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionUrlResource(String urlString) Creates a URL resource from string 从字符串创建URL资源UrlResource(URI uri) Creates a URL resource from URI 从URI创建URL资源UrlResource(URL url) Creates a URL resource from URL 从URL创建URL资源 -
Method Summary
Modifier and TypeMethodDescriptionlongGets the content length in bytes 获取内容长度(字节)createRelative(String relativePath) Creates a relative resource 创建相对资源booleanbooleanexists()Checks if the resource exists 检查资源是否存在Gets a description of the resource 获取资源描述Gets the filename of the resource 获取资源的文件名Gets the input stream for reading the resource 获取用于读取资源的输入流getPath()Gets the file path if available 获取文件路径(如果可用)getURI()Gets the URI 获取URIgetURL()Gets the URL of the resource 获取资源的URLinthashCode()booleanChecks if the resource is readable 检查资源是否可读longGets the last modified time 获取最后修改时间toString()Methods inherited from interface Resource
readBytes, readString, readString
-
Constructor Details
-
UrlResource
Creates a URL resource from URL 从URL创建URL资源- Parameters:
url- the URL | URL
-
UrlResource
Creates a URL resource from URI 从URI创建URL资源- Parameters:
uri- the URI | URI
-
UrlResource
Creates a URL resource from string 从字符串创建URL资源- Parameters:
urlString- the URL string | URL字符串
-
-
Method Details
-
exists
-
isReadable
public boolean isReadable()Description copied from interface:ResourceChecks if the resource is readable 检查资源是否可读- Specified by:
isReadablein interfaceResource- Returns:
- true if readable | 如果可读返回true
-
getInputStream
Description copied from interface:ResourceGets the input stream for reading the resource 获取用于读取资源的输入流- Specified by:
getInputStreamin interfaceResource- Returns:
- input stream | 输入流
-
getURL
-
getPath
-
getDescription
Description copied from interface:ResourceGets a description of the resource 获取资源描述- Specified by:
getDescriptionin interfaceResource- Returns:
- description | 描述
-
getFilename
Description copied from interface:ResourceGets the filename of the resource 获取资源的文件名- Specified by:
getFilenamein interfaceResource- Returns:
- filename | 文件名
-
contentLength
public long contentLength()Description copied from interface:ResourceGets the content length in bytes 获取内容长度(字节)- Specified by:
contentLengthin interfaceResource- Returns:
- length or -1 if unknown | 长度,如果未知返回-1
-
lastModified
public long lastModified()Description copied from interface:ResourceGets the last modified time 获取最后修改时间- Specified by:
lastModifiedin interfaceResource- Returns:
- timestamp or -1 if unknown | 时间戳,如果未知返回-1
-
createRelative
Description copied from interface:ResourceCreates a relative resource 创建相对资源- Specified by:
createRelativein interfaceResource- Parameters:
relativePath- the relative path | 相对路径- Returns:
- new resource | 新资源
-
getURI
-
equals
-
hashCode
-
toString
-