Class Strings

java.lang.Object
zeroecho.core.util.Strings

public final class Strings extends Object
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 Details

    • toShortString

      public static String toShortString(byte[] a)
      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 be null
      Returns:
      a short string representation of the byte array, never null
    • toShortHexString

      public static String toShortHexString(byte[] a)
      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 a is null, the string "null" is returned.
      • If a is 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 be null
      Returns:
      a compact hexadecimal string representation