Class OpenHex
java.lang.Object
cloud.opencode.base.core.OpenHex
Hexadecimal Utility Class - Hex encoding, decoding and validation
十六进制工具类 - 十六进制编码、解码和验证
Provides hexadecimal encoding and decoding operations.
提供十六进制编解码功能。
Features | 主要功能:
- Encoding (encodeHex, encodeHexUpper, byteToHex) - 编码
- Decoding (decodeHex from String/char[]) - 解码
- Validation (isHexNumber, isHexString) - 验证
- Formatting (format with spaces, normalize) - 格式化
- Integer conversion (toHex, toInt, toLong) - 整数转换
Usage Examples | 使用示例:
// Encoding - 编码
String hex = OpenHex.encodeHex(bytes); // "48656c6c6f"
String upper = OpenHex.encodeHexUpper(bytes); // "48656C6C6F"
// Decoding - 解码
byte[] data = OpenHex.decodeHex("48656c6c6f");
// Validation - 验证
boolean valid = OpenHex.isHexString("0f1a2b"); // true
// Formatting - 格式化
String formatted = OpenHex.format("48656c6c6f"); // "48 65 6c 6c 6f"
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringbyteToHex(byte b) Converts a single byte to a hex string 单字节转十六进制字符串static byte[]decodeHex(char[] hex) Converts hex char array to byte array 十六进制字符数组转字节数组static byte[]Converts hex string to byte array 十六进制字符串转字节数组static StringencodeHex(byte[] data) Converts byte array to lowercase hex string 字节数组转十六进制字符串(小写)static char[]encodeHexChars(byte[] data) Converts byte array to hex char array 字节数组转十六进制字符数组static char[]encodeHexChars(byte[] data, boolean toLowerCase) Converts byte array to hex char array 字节数组转十六进制字符数组static StringencodeHexUpper(byte[] data) Converts byte array to uppercase hex string 字节数组转十六进制字符串(大写)static StringFormats hex string with spaces between each byte pair 格式化十六进制字符串(每两位加空格)static booleanisHexNumber(String str) Checks whether the string is a hex number 判断是否为十六进制数static booleanisHexString(String str) Checks whether the string is a valid hex string 判断是否为有效的十六进制字符串static StringRemoves spaces and separators from a hex string 移除十六进制字符串中的空格和分隔符static StringtoHex(int value) Converts an integer to a hex string 整数转十六进制字符串static StringtoHex(long value) Converts a long to a hex string 长整数转十六进制字符串static intConverts a hex string to an integer 十六进制字符串转整数static longConverts a hex string to a long 十六进制字符串转长整数
-
Method Details
-
encodeHex
Converts byte array to lowercase hex string 字节数组转十六进制字符串(小写) -
encodeHexUpper
Converts byte array to uppercase hex string 字节数组转十六进制字符串(大写) -
encodeHexChars
public static char[] encodeHexChars(byte[] data) Converts byte array to hex char array 字节数组转十六进制字符数组 -
encodeHexChars
public static char[] encodeHexChars(byte[] data, boolean toLowerCase) Converts byte array to hex char array 字节数组转十六进制字符数组 -
byteToHex
Converts a single byte to a hex string 单字节转十六进制字符串 -
decodeHex
Converts hex string to byte array 十六进制字符串转字节数组 -
decodeHex
public static byte[] decodeHex(char[] hex) Converts hex char array to byte array 十六进制字符数组转字节数组 -
isHexNumber
Checks whether the string is a hex number 判断是否为十六进制数 -
isHexString
Checks whether the string is a valid hex string 判断是否为有效的十六进制字符串 -
format
-
normalize
-
toHex
Converts an integer to a hex string 整数转十六进制字符串 -
toHex
Converts a long to a hex string 长整数转十六进制字符串 -
toInt
Converts a hex string to an integer 十六进制字符串转整数 -
toLong
Converts a hex string to a long 十六进制字符串转长整数
-