Java Socket Address Get toInetSocketAddress(String hostPortPair, int defaultPort)

Here you can find the source of toInetSocketAddress(String hostPortPair, int defaultPort)

Description

to Inet Socket Address

License

Apache License

Declaration

public static InetSocketAddress toInetSocketAddress(String hostPortPair, int defaultPort) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.InetSocketAddress;

public class Main {
    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 {/*w ww. j a v a2s .c  o m*/
            port = defaultPort;
        }

        InetSocketAddress inetSocketAddress = new InetSocketAddress(hostname, port);
        return inetSocketAddress;
    }
}

Related

  1. toByte(InetSocketAddress socketAddress)
  2. toBytes(SocketAddress address)
  3. toFileName(InetSocketAddress address)
  4. toHttpUrl(InetSocketAddress addr)
  5. toInetSocketAddress(String address)
  6. toInetSocketAddressLIst(List addressList)
  7. toInetSocketAddressList(String addresses, int defaultPort)
  8. toSocketAddress(URL url)
  9. toString(InetSocketAddress addr)