Class Strings
java.lang.Object
zeroecho.core.util.Strings
Utility class providing string conversion helpers for debugging and logging.
This class focuses on safe and concise representations of binary data and other values that are commonly needed in diagnostic messages. It is not intended for cryptographic formatting or encoding tasks such as Base64 or hexadecimal.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringtoShortHexString(byte[] a) Converts a byte array into a compact hexadecimal string representation.static StringtoShortString(byte[] a) Converts a byte array into a short, human-readable string representation.
-
Method Details
-
toShortString
Converts a byte array into a short, human-readable string representation.The representation is a comma-separated list of decimal byte values enclosed in square brackets. For arrays longer than 32 elements, the output is truncated after 32 elements, followed by an ellipsis marker:
[...].Examples
Strings.toShortString(null) -> "null" Strings.toShortString(new byte[0]) -> "[]" Strings.toShortString(new byte[]{1, 2, 3}) -> "[1, 2, 3]" Strings.toShortString(new byte[40]) -> "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...]"- Parameters:
a- the byte array to format, may benull- Returns:
- a short string representation of the byte array, never
null
-
toShortHexString
Converts a byte array into a compact hexadecimal string representation.The output starts with
"[0x", concatenates each byte as a two-digit lowercase hexadecimal value with no separators, and ends with"]". If the array contains more than 32 bytes, only the first 32 are included, followed by"...]"to indicate truncation.Special cases:
- If
aisnull, the string"null"is returned. - If
ais empty, the string"[]"is returned.
Examples
toShortHexString(null) -> "null" toShortHexString(new byte[0]) -> "[]" toShortHexString(new byte[]{0x01}) -> "[0x01]" toShortHexString(new byte[]{0x01,0x2a}) -> "[0x012a]"- Parameters:
a- the byte array to convert, may benull- Returns:
- a compact hexadecimal string representation
- If
-