@Test public void replaceHostNameTest() throws UnknownHostException { Assert.assertEquals(NetworkUtils.replaceHostName(""), null); Assert.assertEquals(NetworkUtils.replaceHostName(null), null); String[] paths = new String[] { "hdfs: "hdfs: for (String path : paths) { Assert.assertEquals(NetworkUtils.replaceHostName(path), path); } }
public static String replaceHostName(String addr) throws UnknownHostException { if (addr == null || addr.isEmpty()) { return null; } if (addr.contains(": int idx = addr.indexOf(": String prefix = addr.substring(0, idx + 3); String rest = addr.substring(idx + 3); if (rest.contains(":")) { int idx2 = rest.indexOf(":"); String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } else if (rest.contains(Constants.PATH_SEPARATOR)) { int idx2 = rest.indexOf(Constants.PATH_SEPARATOR); if (idx2 > 0) { String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } } else { return prefix + resolveHostName(rest); } } return addr; }
NetworkUtils { public static String replaceHostName(String addr) throws UnknownHostException { if (addr == null || addr.isEmpty()) { return null; } if (addr.contains(": int idx = addr.indexOf(": String prefix = addr.substring(0, idx + 3); String rest = addr.substring(idx + 3); if (rest.contains(":")) { int idx2 = rest.indexOf(":"); String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } else if (rest.contains(Constants.PATH_SEPARATOR)) { int idx2 = rest.indexOf(Constants.PATH_SEPARATOR); if (idx2 > 0) { String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } } else { return prefix + resolveHostName(rest); } } return addr; } }
NetworkUtils { public static String replaceHostName(String addr) throws UnknownHostException { if (addr == null || addr.isEmpty()) { return null; } if (addr.contains(": int idx = addr.indexOf(": String prefix = addr.substring(0, idx + 3); String rest = addr.substring(idx + 3); if (rest.contains(":")) { int idx2 = rest.indexOf(":"); String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } else if (rest.contains(Constants.PATH_SEPARATOR)) { int idx2 = rest.indexOf(Constants.PATH_SEPARATOR); if (idx2 > 0) { String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } } else { return prefix + resolveHostName(rest); } } return addr; }  }
NetworkUtils { public static String replaceHostName(String addr) throws UnknownHostException { if (addr == null || addr.isEmpty()) { return null; } if (addr.contains(": int idx = addr.indexOf(": String prefix = addr.substring(0, idx + 3); String rest = addr.substring(idx + 3); if (rest.contains(":")) { int idx2 = rest.indexOf(":"); String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } else if (rest.contains(Constants.PATH_SEPARATOR)) { int idx2 = rest.indexOf(Constants.PATH_SEPARATOR); if (idx2 > 0) { String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } } else { return prefix + resolveHostName(rest); } } return addr; }  static String getLocalHostName(); static String getLocalIpAddress(); static String replaceHostName(String addr); static String resolveHostName(String hostname); }
NetworkUtils { public static String replaceHostName(String addr) throws UnknownHostException { if (addr == null || addr.isEmpty()) { return null; } if (addr.contains(": int idx = addr.indexOf(": String prefix = addr.substring(0, idx + 3); String rest = addr.substring(idx + 3); if (rest.contains(":")) { int idx2 = rest.indexOf(":"); String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } else if (rest.contains(Constants.PATH_SEPARATOR)) { int idx2 = rest.indexOf(Constants.PATH_SEPARATOR); if (idx2 > 0) { String hostname = rest.substring(0, idx2); hostname = resolveHostName(hostname); String suffix = rest.substring(idx2); return prefix + hostname + suffix; } } else { return prefix + resolveHostName(rest); } } return addr; }  static String getLocalHostName(); static String getLocalIpAddress(); static String replaceHostName(String addr); static String resolveHostName(String hostname);  }