Here you can find the source of toInetSocketAddressList(String addresses, int defaultPort)
Parameter | Description |
---|---|
list | a parameter |
defaultPort | a parameter |
public static List<InetSocketAddress> toInetSocketAddressList(String addresses, int defaultPort)
//package com.java2s; //License from project: Apache License import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.List; public class Main { /**//from w w w. jav a 2s . co m * Parses a comma separated list of ip/host:port pairs. If a port isn't * specified, the default port parameter is used instead. * * @param list * @param defaultPort * @return */ public static List<InetSocketAddress> toInetSocketAddressList(String addresses, int defaultPort) { String[] split = addresses.split(","); return toInetSocketAddressList(split, defaultPort); } public static List<InetSocketAddress> toInetSocketAddressList(String[] hostPortPairs, int defaultPort) { List<InetSocketAddress> addressList = new ArrayList<InetSocketAddress>(); for (String hostPortPair : hostPortPairs) { addressList.add(toInetSocketAddress(hostPortPair.trim(), defaultPort)); } return addressList; } public static InetSocketAddress toInetSocketAddress(String hostPortPair, int defaultPort) { String[] split = hostPortPair.split(":"); String hostname = split[0]; int port; if (split.length > 1) { port = Integer.parseInt(split[1]); } else { port = defaultPort; } InetSocketAddress inetSocketAddress = new InetSocketAddress(hostname, port); return inetSocketAddress; } }