Hex
Overview
Module
- package:
org.eclipse.dirigible.sdk.utils - source: utils/Hex.java
Hex (base-16) encoding helpers. Lower-case alphabet, no separators — useful for rendering digests, fingerprints, and binary identifiers as printable strings.
decode(String) throws DecoderException for invalid input (odd length, non-hex character); reach for it when input is user-supplied and you want to surface a client-friendly error rather than crash on a corrupt byte.
Key Features:
- Lower-case alphabet: Matches the most common digest fingerprint format.
- No separators: Compact output — pair with
Digest.sha256for printable hashes. - Bytes-first variants:
encodeNative/decodeNativeskip theStringround-trip.
Example Usage:
import org.eclipse.dirigible.sdk.utils.Hex;
import org.eclipse.dirigible.sdk.utils.Digest;
// Hex-encode a SHA-256 digest
String fingerprint = Hex.encode(Digest.sha256("payload"));
// Decode a hex string back to bytes — surfaces DecoderException on bad input
byte[] bytes = Hex.decode(fingerprint);Methods
encode()
Encodes the input as a lower-case hex string. Overloaded for String (encoded as bytes by the underlying facade) and raw byte[] payloads.
javapublic static String encode(String input); public static String encode(byte[] input);
Parameter Type Description inputStringorbyte[]The data to encode. Returns
- Type:
String- Description: The hex-encoded representation (lower-case, no separators).
decode()
Decodes a hex string back into raw bytes. Throws DecoderException if the input has odd length or contains non-hex characters.
javapublic static byte[] decode(String input) throws DecoderException;
Parameter Type Description inputStringThe hex-encoded text to decode. Returns
- Type:
byte[]- Description: The decoded raw bytes. Throws
DecoderExceptionon invalid input.
encodeNative()
Bytes-in, bytes-out hex encoding — returns the ASCII hex representation as a byte[] instead of a String.
javapublic static byte[] encodeNative(byte[] input);
Parameter Type Description inputbyte[]The raw bytes to encode. Returns
- Type:
byte[]- Description: The hex-encoded bytes (ASCII, lower-case).
decodeNative()
Bytes-in, bytes-out hex decoding — accepts the ASCII hex representation as a byte[] and returns the decoded raw bytes.
javapublic static byte[] decodeNative(byte[] input) throws DecoderException;
Parameter Type Description inputbyte[]The hex-encoded bytes (ASCII) to decode. Returns
- Type:
byte[]- Description: The decoded raw bytes. Throws
DecoderExceptionon invalid input.