Here you can find the source of resolve(final String desc, final int defaultPort)
public static InetSocketAddress resolve(final String desc, final int defaultPort)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; public class Main { /** Parse and resolve an address string, looking up the IP address. */ public static InetSocketAddress resolve(final String desc, final int defaultPort) { final InetSocketAddress addr = parse(desc, defaultPort); if (addr.getAddress() != null && addr.getAddress().isAnyLocalAddress()) { return addr; }/* w w w .j a v a2 s . c o m*/ try { final InetAddress host = InetAddress.getByName(addr.getHostName()); return new InetSocketAddress(host, addr.getPort()); } catch (UnknownHostException e) { throw new IllegalArgumentException("unknown host: " + desc, e); } } /** Parse an address string such as {@code host:port} or {@code *:port}. */ public static InetSocketAddress parse(final String desc, final int defaultPort) { String hostStr; String portStr; if (desc.startsWith("[")) { // IPv6, as a raw IP address. // final int hostEnd = desc.indexOf(']'); if (hostEnd < 0) { throw new IllegalArgumentException("invalid IPv6: " + desc); } hostStr = desc.substring(1, hostEnd); portStr = desc.substring(hostEnd + 1); } else { // IPv4, or a host name. // final int hostEnd = desc.indexOf(':'); hostStr = 0 <= hostEnd ? desc.substring(0, hostEnd) : desc; portStr = 0 <= hostEnd ? desc.substring(hostEnd) : ""; } if ("".equals(hostStr)) { hostStr = "*"; } if (portStr.startsWith(":")) { portStr = portStr.substring(1); } final int port; if (portStr.length() > 0) { try { port = Integer.parseInt(portStr); } catch (NumberFormatException e) { throw new IllegalArgumentException("invalid port: " + desc); } } else { port = defaultPort; } if ("*".equals(hostStr)) { return new InetSocketAddress(port); } return InetSocketAddress.createUnresolved(hostStr, port); } }