@Test(dataProvider = "longToIpv4DataProvider") public void ipv4ToLong(long expected, String ipAsText) { assertEquals(AddressUtils.ipv4ToLong(ipAsText), expected); }
public static long ipv4ToLong(String ipAsText) { if(!InetAddresses.isInetAddress(ipAsText)) { throw new IllegalArgumentException("failed to parse ip [" + ipAsText + "], not a valid ip address"); } String[] octets = IP_PATTER.split(ipAsText); return (Long.parseLong(octets[0]) << 24) + (Integer.parseInt(octets[1]) << 16) + (Integer.parseInt(octets[2]) << 8) + Integer.parseInt(octets[3]); }
AddressUtils { public static long ipv4ToLong(String ipAsText) { if(!InetAddresses.isInetAddress(ipAsText)) { throw new IllegalArgumentException("failed to parse ip [" + ipAsText + "], not a valid ip address"); } String[] octets = IP_PATTER.split(ipAsText); return (Long.parseLong(octets[0]) << 24) + (Integer.parseInt(octets[1]) << 16) + (Integer.parseInt(octets[2]) << 8) + Integer.parseInt(octets[3]); } }
AddressUtils { public static long ipv4ToLong(String ipAsText) { if(!InetAddresses.isInetAddress(ipAsText)) { throw new IllegalArgumentException("failed to parse ip [" + ipAsText + "], not a valid ip address"); } String[] octets = IP_PATTER.split(ipAsText); return (Long.parseLong(octets[0]) << 24) + (Integer.parseInt(octets[1]) << 16) + (Integer.parseInt(octets[2]) << 8) + Integer.parseInt(octets[3]); } private  AddressUtils(); }
AddressUtils { public static long ipv4ToLong(String ipAsText) { if(!InetAddresses.isInetAddress(ipAsText)) { throw new IllegalArgumentException("failed to parse ip [" + ipAsText + "], not a valid ip address"); } String[] octets = IP_PATTER.split(ipAsText); return (Long.parseLong(octets[0]) << 24) + (Integer.parseInt(octets[1]) << 16) + (Integer.parseInt(octets[2]) << 8) + Integer.parseInt(octets[3]); } private  AddressUtils(); static String longToIpv4(long ipAsLong); static long ipv4ToLong(String ipAsText); static String toCIDR(long ipA, long ipB); static long numberOfAddress(String cidrAddress); }
AddressUtils { public static long ipv4ToLong(String ipAsText) { if(!InetAddresses.isInetAddress(ipAsText)) { throw new IllegalArgumentException("failed to parse ip [" + ipAsText + "], not a valid ip address"); } String[] octets = IP_PATTER.split(ipAsText); return (Long.parseLong(octets[0]) << 24) + (Integer.parseInt(octets[1]) << 16) + (Integer.parseInt(octets[2]) << 8) + Integer.parseInt(octets[3]); } private  AddressUtils(); static String longToIpv4(long ipAsLong); static long ipv4ToLong(String ipAsText); static String toCIDR(long ipA, long ipB); static long numberOfAddress(String cidrAddress);  }