Class OpenUrl
java.lang.Object
cloud.opencode.base.web.url.OpenUrl
Open URL - URL Utility Class
Open URL - URL 工具类
This class provides static utility methods for URL encoding, decoding, parsing, and validation.
此类提供 URL 编码、解码、解析和验证的静态工具方法。
Example | 示例:
// Encoding
String encoded = OpenUrl.encode("hello world"); // "hello+world"
String pathEncoded = OpenUrl.encodePath("path/to file"); // "path/to%20file"
// Decoding
String decoded = OpenUrl.decode("hello%20world"); // "hello world"
// Parsing
String host = OpenUrl.getHost("https://example.com/path"); // "example.com"
String path = OpenUrl.getPath("https://example.com/path"); // "/path"
// Validation
boolean valid = OpenUrl.isValid("https://example.com"); // true
Features | 主要功能:
- URL encoding and decoding - URL编码和解码
- URL parsing (scheme, host, port, path) - URL解析
- URL validation - URL验证
- IDN (Punycode) support - IDN(Punycode)支持
Usage Examples | 使用示例:
String encoded = OpenUrl.encode("hello world");
String host = OpenUrl.getHost("https://example.com/path");
boolean valid = OpenUrl.isValid("https://example.com");
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 是(无状态工具)
- Null-safe: Yes (returns null for null input) - 是(null输入返回null)
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic UrlBuilderbuilder()Creates a URL builder.static UrlBuilderCreates a URL builder from existing URL.static StringURL decodes a string.static StringURL encodes a string.static StringencodeParams(Map<String, String> params) Encodes query parameters from map.static StringencodePath(String path) Encodes a path segment (preserves slashes).static StringgetBaseUrl(String url) Gets the base URL (scheme + host + port).static intgetEffectivePort(String url) Gets the effective port (considering default ports).static StringgetFragment(String url) Gets the fragment from URL.static StringGets the host from URL.static StringGets the path from URL.static intGets the port from URL.static StringGets the query string from URL.static StringgetQueryParam(String url, String name) Gets query parameter from URL.static StringGets the scheme from URL.static booleanChecks if URL is HTTP.static booleanChecks if URL is HTTPS.static booleanChecks if URL is valid.static booleanisValidDomain(String domain) Checks if domain is valid.static booleanisValidUrl(String url) Checks if URL matches pattern.static StringJoins URL parts.static StringNormalizes a URL.static QueryStringparseQuery(String url) Parses query string from URL.static StringremoveFragment(String url) Removes fragment from URL.static StringremoveQuery(String url) Removes query string from URL.static StringConverts domain to ASCII (Punycode).static StringConverts domain from ASCII (Punycode) to Unicode.
-
Method Details
-
encode
-
decode
-
encodePath
-
encodeParams
-
builder
-
builder
Creates a URL builder from existing URL. 从现有 URL 创建构建器。- Parameters:
url- the base URL - 基础 URL- Returns:
- the builder - 构建器
-
getScheme
-
getHost
-
getPort
Gets the port from URL. 从 URL 获取端口。- Parameters:
url- the URL - URL- Returns:
- the port or -1 - 端口或 -1
-
getEffectivePort
Gets the effective port (considering default ports). 获取有效端口(考虑默认端口)。- Parameters:
url- the URL - URL- Returns:
- the effective port - 有效端口
-
getPath
-
getQuery
-
getFragment
-
parseQuery
Parses query string from URL. 从 URL 解析查询字符串。- Parameters:
url- the URL - URL- Returns:
- the parsed query string - 解析的查询字符串
-
getQueryParam
-
join
-
normalize
-
removeQuery
-
removeFragment
-
getBaseUrl
-
isValid
Checks if URL is valid. 检查 URL 是否有效。- Parameters:
url- the URL - URL- Returns:
- true if valid - 如果有效返回 true
-
isValidUrl
Checks if URL matches pattern. 检查 URL 是否匹配模式。- Parameters:
url- the URL - URL- Returns:
- true if matches - 如果匹配返回 true
-
isValidDomain
Checks if domain is valid. 检查域名是否有效。- Parameters:
domain- the domain - 域名- Returns:
- true if valid - 如果有效返回 true
-
isHttps
Checks if URL is HTTPS. 检查 URL 是否为 HTTPS。- Parameters:
url- the URL - URL- Returns:
- true if HTTPS - 如果是 HTTPS 返回 true
-
isHttp
Checks if URL is HTTP. 检查 URL 是否为 HTTP。- Parameters:
url- the URL - URL- Returns:
- true if HTTP - 如果是 HTTP 返回 true
-
toAscii
-
toUnicode
-