@Test public void setGetHostTest() { assertEquals("localhost", getHost("localhost")); assertEquals("localhost", getHost("https: assertEquals("localhost", getHost("https: assertEquals("[2001:0db8::765d]", getHost("[2001:0db8::765d]")); assertEquals("[2001:0db8::765d]", getHost("[2001:0db8::765d]:123")); assertEquals("[2001:0db8::765d]", getHost("https: }
public static String getHost(String addr) { if (addr == null) { return null; } int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return addr; } if(hostStart > 0) { if(hostEnd < hostStart) { return addr.substring(hostStart); } return addr.substring(hostStart, hostEnd); } return addr.substring(0, hostEnd); }
AddressUtils { public static String getHost(String addr) { if (addr == null) { return null; } int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return addr; } if(hostStart > 0) { if(hostEnd < hostStart) { return addr.substring(hostStart); } return addr.substring(hostStart, hostEnd); } return addr.substring(0, hostEnd); } }
AddressUtils { public static String getHost(String addr) { if (addr == null) { return null; } int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return addr; } if(hostStart > 0) { if(hostEnd < hostStart) { return addr.substring(hostStart); } return addr.substring(hostStart, hostEnd); } return addr.substring(0, hostEnd); }  }
AddressUtils { public static String getHost(String addr) { if (addr == null) { return null; } int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return addr; } if(hostStart > 0) { if(hostEnd < hostStart) { return addr.substring(hostStart); } return addr.substring(hostStart, hostEnd); } return addr.substring(0, hostEnd); }  static int getPort(String addr); static boolean hasPort(String addr); static String setPort(String address, int port); static boolean isIpv6(String url); static String getHostPort(String addr); static boolean isHttps(String url); static String getHost(String addr); static String setHost(String addr, String host); static boolean isLocal(String host); }
AddressUtils { public static String getHost(String addr) { if (addr == null) { return null; } int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return addr; } if(hostStart > 0) { if(hostEnd < hostStart) { return addr.substring(hostStart); } return addr.substring(hostStart, hostEnd); } return addr.substring(0, hostEnd); }  static int getPort(String addr); static boolean hasPort(String addr); static String setPort(String address, int port); static boolean isIpv6(String url); static String getHostPort(String addr); static boolean isHttps(String url); static String getHost(String addr); static String setHost(String addr, String host); static boolean isLocal(String host);  }