@Test public void testToLong1() { String[] split = "127.0.0.1".split("\\."); long r = 0; r = r | (Long.parseLong(split[0]) << 40); r = r | (Long.parseLong(split[1]) << 32); r = r | (Long.parseLong(split[2]) << 24); r = r | (Long.parseLong(split[3]) << 16); r = r | 0; assertThat(NetUtil.toLong("127.0.0.1")).isEqualTo(r); }
public static long toLong(String address) { InetSocketAddress ad = toInetSocketAddress(address); String[] ip = ad.getAddress().getHostAddress().split("\\."); long r = 0; r = r | (Long.parseLong(ip[0]) << 40); r = r | (Long.parseLong(ip[1]) << 32); r = r | (Long.parseLong(ip[2]) << 24); r = r | (Long.parseLong(ip[3]) << 16); r = r | ad.getPort(); return r; }
NetUtil { public static long toLong(String address) { InetSocketAddress ad = toInetSocketAddress(address); String[] ip = ad.getAddress().getHostAddress().split("\\."); long r = 0; r = r | (Long.parseLong(ip[0]) << 40); r = r | (Long.parseLong(ip[1]) << 32); r = r | (Long.parseLong(ip[2]) << 24); r = r | (Long.parseLong(ip[3]) << 16); r = r | ad.getPort(); return r; } }
NetUtil { public static long toLong(String address) { InetSocketAddress ad = toInetSocketAddress(address); String[] ip = ad.getAddress().getHostAddress().split("\\."); long r = 0; r = r | (Long.parseLong(ip[0]) << 40); r = r | (Long.parseLong(ip[1]) << 32); r = r | (Long.parseLong(ip[2]) << 24); r = r | (Long.parseLong(ip[3]) << 16); r = r | ad.getPort(); return r; }  }
NetUtil { public static long toLong(String address) { InetSocketAddress ad = toInetSocketAddress(address); String[] ip = ad.getAddress().getHostAddress().split("\\."); long r = 0; r = r | (Long.parseLong(ip[0]) << 40); r = r | (Long.parseLong(ip[1]) << 32); r = r | (Long.parseLong(ip[2]) << 24); r = r | (Long.parseLong(ip[3]) << 16); r = r | ad.getPort(); return r; }  static String toStringAddress(SocketAddress address); static String toIpAddress(SocketAddress address); static String toStringAddress(InetSocketAddress address); static InetSocketAddress toInetSocketAddress(String address); static long toLong(String address); static String getLocalIp(); static String getLocalHost(); static InetAddress getLocalAddress(); static void validAddress(InetSocketAddress address); static boolean isValidIp(String ip, boolean validLocalAndAny); }
NetUtil { public static long toLong(String address) { InetSocketAddress ad = toInetSocketAddress(address); String[] ip = ad.getAddress().getHostAddress().split("\\."); long r = 0; r = r | (Long.parseLong(ip[0]) << 40); r = r | (Long.parseLong(ip[1]) << 32); r = r | (Long.parseLong(ip[2]) << 24); r = r | (Long.parseLong(ip[3]) << 16); r = r | ad.getPort(); return r; }  static String toStringAddress(SocketAddress address); static String toIpAddress(SocketAddress address); static String toStringAddress(InetSocketAddress address); static InetSocketAddress toInetSocketAddress(String address); static long toLong(String address); static String getLocalIp(); static String getLocalHost(); static InetAddress getLocalAddress(); static void validAddress(InetSocketAddress address); static boolean isValidIp(String ip, boolean validLocalAndAny);  }