@Test public void testIsValidHex() { String test = null; assertFalse(NumericUtil.isValidHex(test)); test = ""; assertFalse(NumericUtil.isValidHex(test)); test = "0xAFGH"; assertFalse(NumericUtil.isValidHex(test)); test = "0xAF1"; assertFalse(NumericUtil.isValidHex(test)); test = "0x10AF"; assertTrue(NumericUtil.isValidHex(test)); test = "0x10af"; assertTrue(NumericUtil.isValidHex(test)); test = "10af"; assertTrue(NumericUtil.isValidHex(test)); }
public static boolean isValidHex(String value) { if (value == null) { return false; } if (value.startsWith("0x") || value.startsWith("0X")) { value = value.substring(2, value.length()); } if (value.length() == 0 || value.length() % 2 != 0) { return false; } String pattern = "[0-9a-fA-F]+"; return Pattern.matches(pattern, value); }
NumericUtil { public static boolean isValidHex(String value) { if (value == null) { return false; } if (value.startsWith("0x") || value.startsWith("0X")) { value = value.substring(2, value.length()); } if (value.length() == 0 || value.length() % 2 != 0) { return false; } String pattern = "[0-9a-fA-F]+"; return Pattern.matches(pattern, value); } }
NumericUtil { public static boolean isValidHex(String value) { if (value == null) { return false; } if (value.startsWith("0x") || value.startsWith("0X")) { value = value.substring(2, value.length()); } if (value.length() == 0 || value.length() % 2 != 0) { return false; } String pattern = "[0-9a-fA-F]+"; return Pattern.matches(pattern, value); }  }
NumericUtil { public static boolean isValidHex(String value) { if (value == null) { return false; } if (value.startsWith("0x") || value.startsWith("0X")) { value = value.substring(2, value.length()); } if (value.length() == 0 || value.length() % 2 != 0) { return false; } String pattern = "[0-9a-fA-F]+"; return Pattern.matches(pattern, value); }  static byte[] generateRandomBytes(int size); static boolean isValidHex(String value); static String cleanHexPrefix(String input); static String prependHexPrefix(String input); static BigInteger bytesToBigInteger(byte[] value, int offset, int length); static BigInteger bytesToBigInteger(byte[] value); static BigInteger hexToBigInteger(String hexValue); static String bigIntegerToHex(BigInteger value); static String bigIntegerToHexWithZeroPadded(BigInteger value, int size); static byte[] bigIntegerToBytesWithZeroPadded(BigInteger value, int length); static byte[] hexToBytes(String input); static byte[] hexToBytesLittleEndian(String input); static byte[] reverseBytes(byte[] bytes); static String bytesToHex(byte[] input); static String beBigEndianHex(String hex); static String beLittleEndianHex(String hex); static int bytesToInt(byte[] bytes); static byte[] intToBytes(int intValue); }
NumericUtil { public static boolean isValidHex(String value) { if (value == null) { return false; } if (value.startsWith("0x") || value.startsWith("0X")) { value = value.substring(2, value.length()); } if (value.length() == 0 || value.length() % 2 != 0) { return false; } String pattern = "[0-9a-fA-F]+"; return Pattern.matches(pattern, value); }  static byte[] generateRandomBytes(int size); static boolean isValidHex(String value); static String cleanHexPrefix(String input); static String prependHexPrefix(String input); static BigInteger bytesToBigInteger(byte[] value, int offset, int length); static BigInteger bytesToBigInteger(byte[] value); static BigInteger hexToBigInteger(String hexValue); static String bigIntegerToHex(BigInteger value); static String bigIntegerToHexWithZeroPadded(BigInteger value, int size); static byte[] bigIntegerToBytesWithZeroPadded(BigInteger value, int length); static byte[] hexToBytes(String input); static byte[] hexToBytesLittleEndian(String input); static byte[] reverseBytes(byte[] bytes); static String bytesToHex(byte[] input); static String beBigEndianHex(String hex); static String beLittleEndianHex(String hex); static int bytesToInt(byte[] bytes); static byte[] intToBytes(int intValue);  }