- /**
- * Convert an array of 6 bytes into canonical MAC address representation, that is 6 groups of two hexadecimal
- * lower-case digits each, separated by colons.
- *
- * @param bytes Input bytes, may not be null
- * @param charHint Hint at how many characters are needed
- * @return Canonical MAC address string
- * @throws NullPointerException if input is null
- * @throws IllegalArgumentException if length of input is not 6 bytes
- */
- // TODO: HexFormat.ofDelimiter(":").withUpperCase().formatHex(bytes) when we have JDK17+? Compare performance
- private static @NonNull String bytesToString(final byte @NonNull[] bytes, final int charHint) {
- final StringBuilder sb = new StringBuilder(charHint);
- appendHexByte(sb, bytes[0]);
- for (int i = 1; i < bytes.length; ++i) {
- appendHexByte(sb.append(':'), bytes[i]);
- }
-
- return sb.toString();
- }
-
- // FIXME: Replace with HexFormat.toHexDigits(sb, byteVal) when we have JDK17+, but note we prefer capital letters
- private static void appendHexByte(final StringBuilder sb, final byte byteVal) {
- final int intVal = Byte.toUnsignedInt(byteVal);
- sb.append(HEX_CHARS[intVal >>> 4]).append(HEX_CHARS[intVal & 15]);
- }
-