Class OpenCodec
java.lang.Object
cloud.opencode.base.core.codec.OpenCodec
Codec Facade - Central entry point for encoding and decoding operations
编解码门面类 - 编解码操作的统一入口
Provides static factory methods to obtain codec instances for various encoding schemes. All returned codecs are thread-safe singletons.
提供静态工厂方法获取各种编码方案的编解码器实例。所有返回的编解码器均为线程安全的单例。
Supported Codecs | 支持的编解码器:
- Base64 (standard, URL-safe, no-padding) - Base64(标准、URL 安全、无填充)
- Hex (lowercase, uppercase) - 十六进制(小写、大写)
- URL (RFC 3986 percent-encoding) - URL(RFC 3986 百分号编码)
- HTML (OWASP entity escaping) - HTML(OWASP 实体转义)
- Base32 (RFC 4648, padding/no-padding) - Base32(RFC 4648,有/无填充)
- ASCII85 (Base85) - ASCII85(Base85)
Usage Examples | 使用示例:
// Base64 roundtrip
Codec<byte[], String> b64 = OpenCodec.base64();
String encoded = b64.encode("Hello".getBytes());
byte[] decoded = b64.decode(encoded);
// URL encoding
Codec<String, String> url = OpenCodec.url();
String safe = url.encode("hello world&foo=bar");
// "hello%20world%26foo%3Dbar"
// HTML escaping
Codec<String, String> html = OpenCodec.html();
String escaped = html.encode("<script>alert('xss')</script>");
// "<script>alert('xss')</script>"
// Codec composition
Codec<byte[], String> hexThenUrl = OpenCodec.hex().andThen(OpenCodec.url());
Security | 安全性:
- Thread-safe: Yes (all codecs are immutable singletons) - 线程安全: 是(所有编解码器为不可变单例)
- Null-safe: null input throws
NullPointerException- 空值: null 输入抛出 NPE
- Since:
- JDK 25, opencode-base-core V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionascii85()Returns an ASCII85 (Base85) codec 返回 ASCII85(Base85)编解码器base32()Returns a Base32 codec (RFC 4648, with padding) 返回 Base32 编解码器(RFC 4648,带填充)Returns a Base32 codec without padding 返回无填充 Base32 编解码器base64()Returns a standard Base64 codec (RFC 4648, with padding) 返回标准 Base64 编解码器(RFC 4648,带填充)Returns a Base64 codec without padding 返回无填充 Base64 编解码器Returns a URL-safe Base64 codec (RFC 4648, without padding) 返回 URL 安全 Base64 编解码器(RFC 4648,无填充)hex()Returns a lowercase hex codec 返回小写十六进制编解码器hexUpper()Returns an uppercase hex codec 返回大写十六进制编解码器html()Returns an HTML entity codec (OWASP compliant) 返回 HTML 实体编解码器(符合 OWASP 规范)url()Returns a URL codec (RFC 3986 percent-encoding) 返回 URL 编解码器(RFC 3986 百分号编码)
-
Method Details
-
base64
-
base64UrlSafe
-
base64NoPadding
-
hex
-
hexUpper
-
url
-
html
-
base32
-
base32NoPadding
-
ascii85
-