Parses a space and/or comma separated sequence of server specifications
of the form <i>hostname</i> or <i>hostname:port</i>.  If
the specs string is null, defaults to localhost:defaultPort.

@return a list of InetSocketAddress objects.
432803
public static List<InetSocketAddress> parse(String specs, int defaultPort) {
    List<InetSocketAddress> result = new ArrayList<InetSocketAddress>(1);
    if (specs == null) {
      result.add(new InetSocketAddress("localhost", defaultPort));
    }
    else {
      String[] specStrings = specs.split("[ ,]+");
      for (String specString : specStrings) {
        int colon = specString.indexOf(':');
        if (colon < 0 || colon == specString.length() - 1) {
          result.add(new InetSocketAddress(specString, defaultPort));
        } else {
          String hostname = specString.substring(0, colon);
          int port = Integer.parseInt(specString.substring(colon+1));
          result.add(new InetSocketAddress(hostname, port));
        }
      }
    }
    return result;
  }
74967
protected ParseLoginAddress parseServerAddressValue() throws IllegalArgumentException {

		ParseLoginAddress serverAddress = new ParseLoginAddress(this.inputAddress, this.commandConsole);
		// parse <user>:<password>@<host>:<port>
		serverAddress.parseLoginAddressValue("--server");
		
		return serverAddress;
	}
1323510
public static List<InetSocketAddress> getRPCAddresses(String suffix,
      Configuration conf, Collection<String> serviceIds, String... keys) 
          throws IOException {
    // Use default address as fall back
    String defaultAddress = null;
    try {
      defaultAddress = conf.get(FileSystem.FS_DEFAULT_NAME_KEY + suffix);
      if (defaultAddress != null) {
        defaultAddress = NameNode.getDefaultAddress(conf);
      }
    } catch (IllegalArgumentException e) {
      defaultAddress = null;
    }
    
    for (int i = 0; i < keys.length; i++) {
      keys[i] += suffix;
    }
    
    List<InetSocketAddress> addressList = DFSUtil.getAddresses(conf,
        serviceIds, defaultAddress,
        keys);
    if (addressList == null) {
      String keyStr = "";
      for (String key: keys) {
        keyStr += key + " ";
      }
      throw new IOException("Incorrect configuration: namenode address "
          + keyStr
          + " is not configured.");
    }
    return addressList;
  }
533695
public static List<HostAndPort> hostAndPorts(AbstractConfig config, String key) {
    return hostAndPorts(config, key, null);
  }
202540
private static List<InetAddress> getMulticastAddresses() throws SocketException, UnknownHostException {
        List<InetAddress> addresses = NetworkUtil.getMulticastAddresses();
        if (addresses.size() == 0) {
            throw new UnknownHostException("Cannot find address of local host which can be used for sending discovery request");
        }
        return addresses;
    }
696627
public static String getServerPort() {
        String ret = getLatkeProperty("serverPort");
        if (null == ret) {
            final RequestContext requestContext = REQUEST_CONTEXT.get();
            if (null != requestContext) {
                ret = requestContext.getRequest().getServerPort() + "";
            }
        }

        return ret;
    }
833257
public static String formatAddress(InetSocketAddress inet){
        if(inet == null){
            throw new NullPointerException();
        }
        StringBuilder result = new StringBuilder();
        if(inet.isUnresolved()){
            result.append(inet.getHostName());
        }else{
            result.append(formatPossibleIpv6Address(formatAddress(inet.getAddress())));
        }
        result.append(":").append(inet.getPort());
        return result.toString();
    }
1277751
@Override
    public InetAddress[] resolve(String host) throws UnknownHostException {

        if (ipStringToBytes(host) != null) {
            return new InetAddress[] { InetAddress.getByAddress(ipStringToBytes(host)) };
        }

        List<InetAddress> inetAddresses = new ArrayList<>();
        try {
            resolve(host, inetAddresses);
        } catch (NamingException e) {
            throw new UnknownHostException(String.format("Cannot resolve %s to a hostname because of %s", host, e));
        }

        if (inetAddresses.isEmpty()) {
            throw new UnknownHostException(String.format("Cannot resolve %s to a hostname", host));
        }

        return inetAddresses.toArray(new InetAddress[inetAddresses.size()]);
    }
16263
public static HostAndPort fromString(String hostPort, int defaultPort) {
    if (hostPort == null) throw new NullPointerException("hostPort == null");

    String host = hostPort;
    int endHostIndex = hostPort.length();
    if (hostPort.startsWith("[")) { // Bracketed IPv6
      endHostIndex = hostPort.lastIndexOf(']') + 1;
      host = hostPort.substring(1, endHostIndex == 0 ? 1 : endHostIndex - 1);
      if (!Endpoint.newBuilder().parseIp(host)) { // reuse our IPv6 validator
        throw new IllegalArgumentException(hostPort + " contains an invalid IPv6 literal");
      }
    } else {
      int colonIndex = hostPort.indexOf(':'), nextColonIndex = hostPort.lastIndexOf(':');
      if (colonIndex >= 0) {
        if (colonIndex == nextColonIndex) { // only 1 colon
          host = hostPort.substring(0, colonIndex);
          endHostIndex = colonIndex;
        } else if (!Endpoint.newBuilder().parseIp(hostPort)) { // reuse our IPv6 validator
          throw new IllegalArgumentException(hostPort + " is an invalid IPv6 literal");
        }
      }
    }
    if (host.isEmpty()) throw new IllegalArgumentException(hostPort + " has an empty host");
    if (endHostIndex + 1 < hostPort.length() && hostPort.charAt(endHostIndex) == ':') {
      return new HostAndPort(host, validatePort(hostPort.substring(endHostIndex + 1), hostPort));
    }
    return new HostAndPort(host, defaultPort);
  }
871659
def port_mapping(port)
      case port.to_s
      when /\A(\d+)(?:\/([a-z]+))?\z/
        port = $1.to_i
        {
          "hostPort" => port,
          "containerPort" => port,
          "protocol" => $2 || "tcp"
        }
      when /\A(\d+):(\d+)(?:\/([a-z]+))?\z/
        {
          "hostPort" => $1.to_i,
          "containerPort" => $2.to_i,
          "protocol" => $3 || "tcp"
        }
      else
        raise "Cannot parse port specification: #{port}"
      end
    end
820812
public static InetSocketAddress buildInetSocketAddress(String host, int defaultPort) {
		if (StrUtil.isBlank(host)) {
			host = LOCAL_IP;
		}

		String destHost = null;
		int port = 0;
		int index = host.indexOf(":");
		if (index != -1) {
			// host:port形式
			destHost = host.substring(0, index);
			port = Integer.parseInt(host.substring(index + 1));
		} else {
			destHost = host;
			port = defaultPort;
		}

		return new InetSocketAddress(destHost, port);
	}
1269033
public static String formatHostnameForHttp(InetSocketAddress addr) {
        String hostString = NetUtil.getHostname(addr);
        if (NetUtil.isValidIpV6Address(hostString)) {
            if (!addr.isUnresolved()) {
                hostString = NetUtil.toAddressString(addr.getAddress());
            }
            return '[' + hostString + ']';
        }
        return hostString;
    }
1059674
public List<String> getOutPorts() {
    List<String> ports = new ArrayList<>();
    JsonObject jsonPorts = config.getObject("ports");
    if (jsonPorts == null) {
      return ports;
    }
    JsonArray jsonOutPorts = jsonPorts.getArray("out");
    if (jsonOutPorts == null) {
      return ports;
    }
    for(Object jsonOutPort : jsonOutPorts) {
      ports.add((String) jsonOutPort);
    }
    return ports;
  }
213958
public static List<InetSocketAddress> getAddresses(Configuration conf,
      Collection<String> serviceIds, String defaultAddress, String... keys) {
    Collection<String> nameserviceIds = getNameServiceIds(conf);
    List<InetSocketAddress> isas = new ArrayList<InetSocketAddress>();

    // Configuration with a single namenode
    if (nameserviceIds == null || nameserviceIds.isEmpty()) {
      String address = getConfValue(defaultAddress, null, conf, keys);
      if (address == null) {
        return null;
      }
      isas.add(NetUtils.createSocketAddr(address));
    } else {
      // Get the namenodes for all the configured nameServiceIds
      for (String nameserviceId : nameserviceIds) {
        String address = getConfValue(null, nameserviceId, conf, keys);
        if (address == null) {
          return null;
        }
        isas.add(NetUtils.createSocketAddr(address));
      }
    }
    return isas;
  }
1366668
public com.google.protobuf.ByteString
      getDefaultHostnameBytes() {
    java.lang.Object ref = defaultHostname_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      defaultHostname_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
777754
public java.util.List<String> getDnsIpAddrs() {
        if (dnsIpAddrs == null) {
            dnsIpAddrs = new com.amazonaws.internal.SdkInternalList<String>();
        }
        return dnsIpAddrs;
    }
706541
@SuppressWarnings("rawtypes")
    private List<InetAddress> resolve(String hostname, String attrName) throws NamingException, UnknownHostException {

        Attributes attrs = context.getAttributes(hostname, new String[] { attrName });

        List<InetAddress> inetAddresses = new ArrayList<>();
        Attribute attr = attrs.get(attrName);

        if (attr != null && attr.size() > 0) {
            NamingEnumeration e = attr.getAll();

            while (e.hasMore()) {
                InetAddress inetAddress = InetAddress.getByName("" + e.next());
                inetAddresses.add(InetAddress.getByAddress(hostname, inetAddress.getAddress()));
            }
        }

        return inetAddresses;
    }