Java Socket Address Get addressToString(InetSocketAddress a)

Here you can find the source of addressToString(InetSocketAddress a)

Description

Stringize an internet address reasonably.

License

Open Source License

Declaration

public static String addressToString(InetSocketAddress a) 

Method Source Code

//package com.java2s;
/*//from   ww  w .j  av  a  2 s.  co m
 * Copyright 2006 Helsinki Institute for Information Technology
 * 
 * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
 * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
 * Fuego middleware source distribution. If you did not receive the MIT license with the
 * distribution, write to the Fuego Core project at fuego-core-users@hoslab.cs.helsinki.fi.
 */

import java.net.InetAddress;
import java.net.InetSocketAddress;

public class Main {
    /**
     * Stringize an internet address reasonably. The normal stringization of an
     * <code>InetSocketAddress</code> does not produce addresses suitable for the host:port part of
     * a URL. This method returns a string of the form <code>addr:port</code> where
     * <code>addr</code> is either a hostname or a dotted-decimal IP address. IP address is
     * preferred if available.
     */
    public static String addressToString(InetSocketAddress a) {
        String value;
        InetAddress addr = a.getAddress();
        if (addr != null) {
            value = addr.getHostAddress();
        } else {
            value = a.getHostName();
        }
        value += ":" + a.getPort();
        return value;
    }
}

Related

  1. address2String(InetSocketAddress address)
  2. address2string(InetSocketAddress isa)
  3. addressIn(SocketAddress address, String ip)
  4. addressLabel(SocketAddress localAddress, SocketAddress remoteAddress)
  5. addressMapToString( Map> map)
  6. addressToString(InetSocketAddress address, Boolean useIpAddress)
  7. asString(SocketAddress socketAddress)
  8. cast2SocketAddress(String addr)
  9. compareAddresses(InetSocketAddress addr1, InetSocketAddress addr2)