@Test public void testParseInetPrefix() throws Exception { assertEquals(new InetSocketAddress(Inet4Address.getByName("122.23.56.2"), 32), IpPrefixConv.parseInetPrefix("122.23.56.2/32")); assertEquals(new InetSocketAddress(Inet4Address.getByName("122.0.56.2"), 24), IpPrefixConv.parseInetPrefix("122.0.56.2/24")); assertEquals(new InetSocketAddress(Inet6Address.getByName("2001:db8::1"), 128), IpPrefixConv.parseInetPrefix("2001:db8::1/128")); assertEquals(new InetSocketAddress(Inet6Address.getByName("201:d8::1"), 32), IpPrefixConv.parseInetPrefix("201:d8::1/32")); assertEquals(new InetSocketAddress(Inet6Address.getByName("2001:db8::1"), 128), IpPrefixConv.parseInetPrefix("2001:db8::1")); }
public static InetSocketAddress parseInetPrefix(String ipPrefix) { if (ipPrefix.startsWith("/")) { ipPrefix = ipPrefix.substring(1); } InetAddress inetAddress; short prefix; int i = ipPrefix.indexOf('/'); if (i != -1) { inetAddress = InetAddresses.forString(ipPrefix.substring(0, i)); prefix = Short.valueOf(ipPrefix.substring(i + 1)); } else { inetAddress = InetAddresses.forString(ipPrefix); if (inetAddress instanceof Inet4Address) { prefix = 32; } else if (inetAddress instanceof Inet6Address) { prefix = 128; } else { prefix = 0; } } return new InetSocketAddress(inetAddress, prefix); }
IpPrefixConv { public static InetSocketAddress parseInetPrefix(String ipPrefix) { if (ipPrefix.startsWith("/")) { ipPrefix = ipPrefix.substring(1); } InetAddress inetAddress; short prefix; int i = ipPrefix.indexOf('/'); if (i != -1) { inetAddress = InetAddresses.forString(ipPrefix.substring(0, i)); prefix = Short.valueOf(ipPrefix.substring(i + 1)); } else { inetAddress = InetAddresses.forString(ipPrefix); if (inetAddress instanceof Inet4Address) { prefix = 32; } else if (inetAddress instanceof Inet6Address) { prefix = 128; } else { prefix = 0; } } return new InetSocketAddress(inetAddress, prefix); } }
IpPrefixConv { public static InetSocketAddress parseInetPrefix(String ipPrefix) { if (ipPrefix.startsWith("/")) { ipPrefix = ipPrefix.substring(1); } InetAddress inetAddress; short prefix; int i = ipPrefix.indexOf('/'); if (i != -1) { inetAddress = InetAddresses.forString(ipPrefix.substring(0, i)); prefix = Short.valueOf(ipPrefix.substring(i + 1)); } else { inetAddress = InetAddresses.forString(ipPrefix); if (inetAddress instanceof Inet4Address) { prefix = 32; } else if (inetAddress instanceof Inet6Address) { prefix = 128; } else { prefix = 0; } } return new InetSocketAddress(inetAddress, prefix); } private  IpPrefixConv(); }
IpPrefixConv { public static InetSocketAddress parseInetPrefix(String ipPrefix) { if (ipPrefix.startsWith("/")) { ipPrefix = ipPrefix.substring(1); } InetAddress inetAddress; short prefix; int i = ipPrefix.indexOf('/'); if (i != -1) { inetAddress = InetAddresses.forString(ipPrefix.substring(0, i)); prefix = Short.valueOf(ipPrefix.substring(i + 1)); } else { inetAddress = InetAddresses.forString(ipPrefix); if (inetAddress instanceof Inet4Address) { prefix = 32; } else if (inetAddress instanceof Inet6Address) { prefix = 128; } else { prefix = 0; } } return new InetSocketAddress(inetAddress, prefix); } private  IpPrefixConv(); static IpPrefix createPrefix(String ipPrefix); static List<IpPrefix> decodeIpv4(byte[] array, boolean compact); static List<IpPrefix> decodeIpv6(byte[] array, boolean compact); static boolean equalTo(IpPrefix prefix1, IpPrefix prefix2); static int getBytesLength(int prefixLength); static int getPrefixLength(IpPrefix ipPrefix); static InetSocketAddress parseInetPrefix(String ipPrefix); static byte[] toBytes(IpPrefix prefix); static byte[] toBytes(List<IpPrefix> prefixes); static String toString(IpPrefix prefix); static String toString(List<IpPrefix> prefixes); static byte[] trimPrefix(byte[] prefix, int blength); }
IpPrefixConv { public static InetSocketAddress parseInetPrefix(String ipPrefix) { if (ipPrefix.startsWith("/")) { ipPrefix = ipPrefix.substring(1); } InetAddress inetAddress; short prefix; int i = ipPrefix.indexOf('/'); if (i != -1) { inetAddress = InetAddresses.forString(ipPrefix.substring(0, i)); prefix = Short.valueOf(ipPrefix.substring(i + 1)); } else { inetAddress = InetAddresses.forString(ipPrefix); if (inetAddress instanceof Inet4Address) { prefix = 32; } else if (inetAddress instanceof Inet6Address) { prefix = 128; } else { prefix = 0; } } return new InetSocketAddress(inetAddress, prefix); } private  IpPrefixConv(); static IpPrefix createPrefix(String ipPrefix); static List<IpPrefix> decodeIpv4(byte[] array, boolean compact); static List<IpPrefix> decodeIpv6(byte[] array, boolean compact); static boolean equalTo(IpPrefix prefix1, IpPrefix prefix2); static int getBytesLength(int prefixLength); static int getPrefixLength(IpPrefix ipPrefix); static InetSocketAddress parseInetPrefix(String ipPrefix); static byte[] toBytes(IpPrefix prefix); static byte[] toBytes(List<IpPrefix> prefixes); static String toString(IpPrefix prefix); static String toString(List<IpPrefix> prefixes); static byte[] trimPrefix(byte[] prefix, int blength);  }