Utils { public static boolean isHexEncoded(String value) { if (value == null) return false; if ("".equals(value)) return true; try { new BigInteger(value, 16); return true; } catch (NumberFormatException e) { return false; } }  static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String longToTimePeriod(long msec); static ImageIcon getImageIcon(String resource); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static String getNodeIdShort(String nodeId); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static List<ByteArrayWrapper> dumpKeys(DbSource<byte[]> ds); static DataWord allButOne64th(DataWord dw); static void showErrorAndExit(String message, String... messages); static void showWarn(String message, String... messages); static String sizeToStr(long size); static void sleep(long ms); static boolean isHexEncoded(String value); static double JAVA_VERSION; }
@Test public void testIsHexEncoded() { assertTrue(Utils.isHexEncoded("AAA")); assertTrue(Utils.isHexEncoded("6c386a4b26f73c802f34673f7248bb118f97424a")); assertFalse(Utils.isHexEncoded(null)); assertFalse(Utils.isHexEncoded("I am not hex")); assertTrue(Utils.isHexEncoded("")); assertTrue(Utils.isHexEncoded( "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a")); }