@Test public void testToLongError() { String dpidStr = "09:08:07:06:05:04:03:02:01"; try { HexString.toLong(dpidStr); fail("HexString.toLong() should have thrown a NumberFormatException"); } catch (NumberFormatException expected) { Log.info("HexString.toLong() have thrown a NumberFormatException"); } }
public static long toLong(String value) { String[] octets = value.split(":"); if (octets.length > 8) { throw new NumberFormatException("Input string is too big to fit in long: " + value); } long l = 0; for (String octet: octets) { if (octet.length() > 2) { throw new NumberFormatException( "Each colon-separated byte component must consist of 1 or 2 hex digits: " + value); } short s = Short.parseShort(octet, 16); l = (l << 8) + s; } return l; }
HexString { public static long toLong(String value) { String[] octets = value.split(":"); if (octets.length > 8) { throw new NumberFormatException("Input string is too big to fit in long: " + value); } long l = 0; for (String octet: octets) { if (octet.length() > 2) { throw new NumberFormatException( "Each colon-separated byte component must consist of 1 or 2 hex digits: " + value); } short s = Short.parseShort(octet, 16); l = (l << 8) + s; } return l; } }
HexString { public static long toLong(String value) { String[] octets = value.split(":"); if (octets.length > 8) { throw new NumberFormatException("Input string is too big to fit in long: " + value); } long l = 0; for (String octet: octets) { if (octet.length() > 2) { throw new NumberFormatException( "Each colon-separated byte component must consist of 1 or 2 hex digits: " + value); } short s = Short.parseShort(octet, 16); l = (l << 8) + s; } return l; } private  HexString(); }
HexString { public static long toLong(String value) { String[] octets = value.split(":"); if (octets.length > 8) { throw new NumberFormatException("Input string is too big to fit in long: " + value); } long l = 0; for (String octet: octets) { if (octet.length() > 2) { throw new NumberFormatException( "Each colon-separated byte component must consist of 1 or 2 hex digits: " + value); } short s = Short.parseShort(octet, 16); l = (l << 8) + s; } return l; } private  HexString(); static String toHexString(final byte[] bytes); static String toHexString(final byte[] bytes, String separator); static String toHexString(final long val, final int padTo); static String toHexString(final long val); static byte[] fromHexString(final String values); static byte[] fromHexString(final String values, String separator); static long toLong(String value); }
HexString { public static long toLong(String value) { String[] octets = value.split(":"); if (octets.length > 8) { throw new NumberFormatException("Input string is too big to fit in long: " + value); } long l = 0; for (String octet: octets) { if (octet.length() > 2) { throw new NumberFormatException( "Each colon-separated byte component must consist of 1 or 2 hex digits: " + value); } short s = Short.parseShort(octet, 16); l = (l << 8) + s; } return l; } private  HexString(); static String toHexString(final byte[] bytes); static String toHexString(final byte[] bytes, String separator); static String toHexString(final long val, final int padTo); static String toHexString(final long val); static byte[] fromHexString(final String values); static byte[] fromHexString(final String values, String separator); static long toLong(String value);  }