Java InetAddress Create getURI(String protocol, InetAddress host, int port)

Here you can find the source of getURI(String protocol, InetAddress host, int port)

Description

get URI

License

BSD License

Declaration

public static String getURI(String protocol, InetAddress host, int port) 

Method Source Code

//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;

    }
}

Related

  1. getProtocolFamily(InetAddress address)
  2. getSafeInetAddress(String name, JSONObject json)
  3. getSourceAddressForDestination(InetAddress destination)
  4. getSpecificAddresses(@Nonnull InetAddress in)
  5. getSubnetPrefix(InetAddress ip, int maskLen)