Class HexUtil

java.lang.Object
org.snmp4j.mcp.tool.snmp.HexUtil

public final class HexUtil extends Object
Hex-string conversion helpers shared by the SNMP byte-level tools (snmp_message_ber, snmp_send_raw, snmp_encode_ber).
Since:
0.1.0
  • Method Details

    • parseHex

      public static byte[] parseHex(String hex)
      Parses a hex string into a byte array. Accepts colon-delimited bytes (e.g. "30:73:02"), plain hex digits ("307302"), and "0x"-prefixed bytes ("0x30:0x73"). Whitespace is ignored.
      Parameters:
      hex - the hex string
      Returns:
      the decoded bytes (empty array for an empty/whitespace input)
      Throws:
      IllegalArgumentException - if the normalized string has an odd number of digits or contains a non-hex character
    • toHex

      public static String toHex(byte[] bytes)
      Formats bytes as a lower-case, colon-delimited hex string (e.g. "30:73:02"), matching the display style used by the BER tools.
      Parameters:
      bytes - the bytes to format (may be empty)
      Returns:
      the colon-delimited hex string; empty string for empty input