@Test public void setSetHostTest() { assertEquals("test", setHost("localhost", "test")); assertEquals("https: assertEquals("https: assertEquals("https: assertEquals("test", setHost("[2001:0db8::765d]", "test")); assertEquals("test:123", setHost("[2001:0db8::765d]:123", "test")); assertEquals("https: }
public static String setHost(String addr, String host) { int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return host; } String prefix = hostStart > 0? addr.substring(0, hostStart) : ""; String suff = hostEnd > 0? addr.substring(hostEnd) : ""; return prefix + host + suff; }
AddressUtils { public static String setHost(String addr, String host) { int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return host; } String prefix = hostStart > 0? addr.substring(0, hostStart) : ""; String suff = hostEnd > 0? addr.substring(hostEnd) : ""; return prefix + host + suff; } }
AddressUtils { public static String setHost(String addr, String host) { int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return host; } String prefix = hostStart > 0? addr.substring(0, hostStart) : ""; String suff = hostEnd > 0? addr.substring(hostEnd) : ""; return prefix + host + suff; }  }
AddressUtils { public static String setHost(String addr, String host) { int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return host; } String prefix = hostStart > 0? addr.substring(0, hostStart) : ""; String suff = hostEnd > 0? addr.substring(hostEnd) : ""; return prefix + host + suff; }  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 setHost(String addr, String host) { int hostStart = getHostStart(addr); boolean ipv6 = isIpv6(addr); int hostEnd = getHostEnd(addr, ipv6, hostStart); if(hostEnd < 0 && hostStart < 0) { return host; } String prefix = hostStart > 0? addr.substring(0, hostStart) : ""; String suff = hostEnd > 0? addr.substring(hostEnd) : ""; return prefix + host + suff; }  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);  }