Java Utililty Methods URI to Host Name

List of utility methods to do URI to Host Name

Description

The list of methods to do URI to Host Name are organized into topic(s).

Method

StringgetHost(final URI uri)
Return just the host portion of the URI if applicable.
String retval = uri.getHost();
if ((retval == null) && (uri.getAuthority() != null)) {
    final String text = uri.getAuthority();
    final int ptr = text.indexOf(':');
    if (ptr > -1) {
        retval = text.substring(0, ptr);
return retval;
StringgetHost(URI uri)
Extract host name from the URI
String host = uri.getHost();
if (host != null) {
    return host;
host = uri.toString();
int sInd = host.indexOf("//") + 2;
host = host.substring(sInd);
int eInd = host.indexOf("/");
...
StringgetHost(URI uri)
get Host
String host = uri.getHost();
int port = uri.getPort();
if (port != -1) {
    host += ":" + port;
return host;
StringgetHost(URI uri)
get Host
String host = uri.getHost();
if (host == null) {
    host = uri.getAuthority();
return host;
InetAddressgetHostAddress(final URI uri)
Get the address of the host.
if (uri != null) {
    final String host = uri.getHost();
    if (host != null) {
        try {
            return InetAddress.getByName(host);
        } catch (final Exception exception) {
return null;
InetAddressgetHostAddress(final URI uri)
Get the address of the host.
if (uri != null) {
    final String host = uri.getHost();
    if (host != null) {
        try {
            return InetAddress.getByName(host);
        } catch (final Exception exception) {
return null;
StringgetHostAndPort(URI u)
get Host And Port
String host = u.getHost();
int port = u.getPort();
return port < 1 ? host : host + ":" + port;
StringgetHostFromURI(final URI uri)
Get the host (if available) from a URI.
return uri.getHost();
URIgetHostUri()
get Host Uri
return getProperty("host.uri");