Here you can find the source of getURI(String protocol, InetAddress host, int port)
public static String getURI(String protocol, InetAddress host, int port)
//package com.java2s; /*/*from w ww.j a v a 2 s.com*/ * Copyright (c) 2008-2011 by Jan Stender, * Zuse Institute Berlin * * Licensed under the BSD License, see LICENSE file for details. * */ import java.net.Inet6Address; import java.net.InetAddress; public class Main { public static String getURI(String protocol, InetAddress host, int port) { String hostAddr = host.getHostAddress(); if (host instanceof Inet6Address) { if (hostAddr.lastIndexOf('%') >= 0) { hostAddr = hostAddr.substring(0, hostAddr.lastIndexOf('%')); } hostAddr = "[" + hostAddr + "]"; } return protocol + "://" + hostAddr + ":" + port; } public static String getHostAddress(InetAddress host) { String hostAddr = host.getHostAddress(); if (host instanceof Inet6Address) { if (hostAddr.lastIndexOf('%') >= 0) { hostAddr = hostAddr.substring(0, hostAddr.lastIndexOf('%')); } } return hostAddr; } }