/** * Returns the unsigned {@code byte} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code byte} * value * @throws NullPointerException if {@code string} is null (in contrast to {@link * Byte#parseByte(String)}) * @since 13.0 */ @Beta @CanIgnoreReturnValue public static byte parseUnsignedByte(String string) { return parseUnsignedByte(string, 10); }
/** * Returns the unsigned {@code byte} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code byte} * value * @throws NullPointerException if {@code string} is null (in contrast to {@link * Byte#parseByte(String)}) * @since 13.0 */ @Beta @CanIgnoreReturnValue public static byte parseUnsignedByte(String string) { return parseUnsignedByte(string, 10); }
/** * Returns the unsigned {@code byte} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code byte} * value * @throws NullPointerException if {@code string} is null (in contrast to {@link * Byte#parseByte(String)}) * @since 13.0 */ @Beta @CanIgnoreReturnValue public static byte parseUnsignedByte(String string) { return parseUnsignedByte(string, 10); }
private static void assertParseFails(String value) { try { UnsignedBytes.parseUnsignedByte(value); fail(); } catch (NumberFormatException expected) { } }
private static void assertParseFails(String value, int radix) { try { UnsignedBytes.parseUnsignedByte(value, radix); fail(); } catch (NumberFormatException expected) { } }
public void testParseUnsignedByteThrowsExceptionForInvalidRadix() { // Valid radix values are Character.MIN_RADIX to Character.MAX_RADIX, // inclusive. try { UnsignedBytes.parseUnsignedByte("0", Character.MIN_RADIX - 1); fail(); } catch (NumberFormatException expected) { } try { UnsignedBytes.parseUnsignedByte("0", Character.MAX_RADIX + 1); fail(); } catch (NumberFormatException expected) { } // The radix is used as an array index, so try a negative value. try { UnsignedBytes.parseUnsignedByte("0", -1); fail(); } catch (NumberFormatException expected) { } }
public void testParseUnsignedByteWithRadix() throws NumberFormatException { // We can easily afford to test this exhaustively. for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { for (int i = 0; i <= 0xff; i++) { assertEquals((byte) i, UnsignedBytes.parseUnsignedByte(Integer.toString(i, radix), radix)); } assertParseFails(Integer.toString(1000, radix), radix); assertParseFails(Integer.toString(-1, radix), radix); assertParseFails(Integer.toString(-128, radix), radix); assertParseFails(Integer.toString(256, radix), radix); } }
public void testParseUnsignedByte() { // We can easily afford to test this exhaustively. for (int i = 0; i <= 0xff; i++) { assertEquals((byte) i, UnsignedBytes.parseUnsignedByte(Integer.toString(i))); } assertParseFails("1000"); assertParseFails("-1"); assertParseFails("-128"); assertParseFails("256"); }
/** * Returns the unsigned {@code byte} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code byte} * value * @throws NullPointerException if {@code s} is null * (in contrast to {@link Byte#parseByte(String)}) * @since 13.0 */ @Beta public static byte parseUnsignedByte(String string) { return parseUnsignedByte(string, 10); }
public static byte[] parseIpAddress(String ipAddress) { byte cur; String[] addressPart = ipAddress.split("."); int size = addressPart.length; byte[] part = new byte[size]; for (int i = 0; i < size; i++) { cur = UnsignedBytes.parseUnsignedByte(addressPart[i], 16); part[i] = cur; } return part; }
public static byte[] parseMacAddress(String macAddress) { byte cur; String[] addressPart = macAddress.split(":"); int size = addressPart.length; byte[] part = new byte[size]; for (int i = 0; i < size; i++) { cur = UnsignedBytes.parseUnsignedByte(addressPart[i], 16); part[i] = cur; } return part; } }
/** * Returns the unsigned {@code byte} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code byte} * value * @throws NullPointerException if {@code s} is null * (in contrast to {@link Byte#parseByte(String)}) * @since 13.0 */ @Beta public static byte parseUnsignedByte(String string) { return parseUnsignedByte(string, 10); }
/** * Returns the unsigned {@code byte} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code byte} * value * @throws NullPointerException if {@code s} is null * (in contrast to {@link Byte#parseByte(String)}) * @since 13.0 */ @Beta public static byte parseUnsignedByte(String string) { return parseUnsignedByte(string, 10); }
/** * Returns the unsigned {@code byte} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code byte} * value * @throws NullPointerException if {@code s} is null * (in contrast to {@link Byte#parseByte(String)}) * @since 13.0 */ @Beta public static byte parseUnsignedByte(String string) { return parseUnsignedByte(string, 10); }
/** * Returns the unsigned {@code byte} value represented by the given decimal string. * * @throws NumberFormatException if the string does not contain a valid unsigned {@code byte} * value * @throws NullPointerException if {@code s} is null * (in contrast to {@link Byte#parseByte(String)}) * @since 13.0 */ @Beta public static byte parseUnsignedByte(String string) { return parseUnsignedByte(string, 10); }
public static Long ipv4ToLong(Ipv4Address ipv4) { Iterator<String> iterator = SPLITTER.split(ipv4.getValue()).iterator(); byte[] bytes = new byte[8]; for(int i =0;i < bytes.length;i++) { if(i<4) { bytes[i] = 0; } else { bytes[i] = UnsignedBytes.parseUnsignedByte((iterator.next())); } } Long result = Longs.fromByteArray(bytes); return result; }
private static void assertParseFails(String value) { try { UnsignedBytes.parseUnsignedByte(value); fail(); } catch (NumberFormatException expected) { } }
private static void assertParseFails(String value, int radix) { try { UnsignedBytes.parseUnsignedByte(value, radix); fail(); } catch (NumberFormatException expected) { } }
public void testParseUnsignedByteWithRadix() throws NumberFormatException { // We can easily afford to test this exhaustively. for (int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) { for (int i = 0; i <= 0xff; i++) { assertEquals((byte) i, UnsignedBytes.parseUnsignedByte(Integer.toString(i, radix), radix)); } assertParseFails(Integer.toString(1000, radix), radix); assertParseFails(Integer.toString(-1, radix), radix); assertParseFails(Integer.toString(-128, radix), radix); assertParseFails(Integer.toString(256, radix), radix); } }
public void testParseUnsignedByte() { // We can easily afford to test this exhaustively. for (int i = 0; i <= 0xff; i++) { assertEquals((byte) i, UnsignedBytes.parseUnsignedByte(Integer.toString(i))); } assertParseFails("1000"); assertParseFails("-1"); assertParseFails("-128"); assertParseFails("256"); }