Here you can find the source of addressToString(InetSocketAddress a)
public static String addressToString(InetSocketAddress a)
//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; } }