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

StringgetHostString(InetSocketAddress socketAddress)
Returns the hostname or IP address of java.net.InetSocketAddress .
InetAddress address = socketAddress.getAddress();
return (address != null && address.toString().startsWith("/")) ? address.getHostAddress()
        : socketAddress.getHostName();
StringgetHostString(InetSocketAddress socketAddress)
Figure out the host string of a given socket address, similar to the Java 7 InetSocketAddress.getHostString().
if (socketAddress.isUnresolved()) {
    return socketAddress.getHostName();
} else {
    return socketAddress.getAddress().getHostAddress();
StringgetHostStringFromInetSocketAddress(InetSocketAddress addr)
get Host String From Inet Socket Address
return addr.getHostString();
StringgetHostStringWithoutNameLookup(InetSocketAddress inetSocketAddress)
A Java 6/7 safe way of looking up a host name from an InetSocketAddress without tickling a name lookup.
String newHost;
if (inetSocketAddress.isUnresolved()) {
    newHost = inetSocketAddress.getHostName();
} else {
    newHost = inetSocketAddress.getAddress().getHostAddress();
return newHost;
InetSocketAddressgetInetSocketAddress(long addrAsInt32, int port)
get Inet Socket Address
return new InetSocketAddress(getAddressFromInt32(addrAsInt32), port);
InetSocketAddressgetInetSocketAddress(String addressPortStr, int defaultPort)
Get an InetSocketAddress from the String format "
:", or "
".
if (addressPortStr == null || addressPortStr.isEmpty()) {
    return null;
String addressStr;
int port;
if (addressPortStr.charAt(0) == '[') {
    int i = addressPortStr.indexOf(']');
    if (i <= 0) {
...
InetSocketAddressgetInetSocketAddress(String arg)
Get the InetSocketAddress corresponding to the FTP format of address
String[] elements = arg.split(",");
if (elements.length != 6) {
    return null;
byte[] address = new byte[4];
int[] iElements = new int[6];
for (int i = 0; i < 6; i++) {
    try {
...
InetSocketAddressgetInetSocketAddress(String endpoint)
Convert an endpoint from String (host:port) to InetSocketAddress
String[] array = endpoint.split(":");
return new InetSocketAddress(array[0], Integer.parseInt(array[1]));
InetSocketAddressgetInetSocketAddress(String endpointURI, int defaultPort)
get Inet Socket Address
final int pos = endpointURI.indexOf(':');
if (pos == -1) {
    InetAddress addr = getInetAddress(endpointURI);
    return new InetSocketAddress(addr, defaultPort);
} else {
    String host = endpointURI.substring(0, pos);
    InetAddress addr = getInetAddress(host);
    String portStr = endpointURI.substring(pos + 1);
...
InetSocketAddressgetInetSocketAddress(String s, String mainHost)
get Inet Socket Address
int finalColon = mainHost.lastIndexOf(':');
if (finalColon < 1) {
    throw new IllegalArgumentException("Invalid server ``" + mainHost + "'' in list:  " + s);
String hostPart = mainHost.substring(0, finalColon).trim();
String portNum = mainHost.substring(finalColon + 1).trim();
InetSocketAddress mainAddress = new InetSocketAddress(hostPart, Integer.parseInt(portNum));
return mainAddress;
...