Java Utililty Methods Socket Address Get

List of utility methods to do Socket Address Get

Description

The list of methods to do Socket Address Get are organized into topic(s).

Method

StringtoFileName(InetSocketAddress address)
Converts the specified address into a string that is suitable for naming files.
return FILE_PREFIX + address.getAddress().getHostAddress() + PORT_SEPARATOR + address.getPort();
URLtoHttpUrl(InetSocketAddress addr)
to Http Url
try {
    return new URL(String.format("http://%s:%d/", addr.getHostString(), addr.getPort()));
} catch (MalformedURLException e) {
    throw new RuntimeException(e);
InetSocketAddresstoInetSocketAddress(String address)
to Inet Socket Address
try {
    URI uri = new URI("pinpoint://" + address);
    return new InetSocketAddress(uri.getHost(), uri.getPort());
} catch (URISyntaxException ignore) {
return null;
InetSocketAddresstoInetSocketAddress(String hostPortPair, int defaultPort)
to Inet Socket Address
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;
ListtoInetSocketAddressLIst(List addressList)
to Inet Socket Address L Ist
List<InetSocketAddress> inetSocketAddressList = new ArrayList<InetSocketAddress>();
for (String address : addressList) {
    InetSocketAddress inetSocketAddress = toInetSocketAddress(address);
    if (inetSocketAddress != null) {
        inetSocketAddressList.add(inetSocketAddress);
return inetSocketAddressList;
...
ListtoInetSocketAddressList(String addresses, int defaultPort)
Parses a comma separated list of ip/host:port pairs.
String[] split = addresses.split(",");
return toInetSocketAddressList(split, defaultPort);
InetSocketAddresstoSocketAddress(URL url)
Creates a socket address from an URL
return new InetSocketAddress(url.getHost(), url.getPort());
StringtoString(InetSocketAddress addr)
to String
if (addr == null) {
    return null;
if (addr.isUnresolved()) {
    return addr.getHostString() + ':' + addr.getPort();
} else {
    InetAddress ia = addr.getAddress();
    return ia.getHostAddress() + ':' + addr.getPort();
...
StringtoString(InetSocketAddress entryServer)
to String
return entryServer.getAddress().getHostAddress() + ":" + entryServer.getPort();
StringtoString(InetSocketAddress socketAddress)
Returns <host>:<port>
return String.format(TO_STRING_FORMAT, socketAddress.getAddress().getHostAddress(),
        socketAddress.getPort());