Returns the host of the given URI or throws an exception if the URI has no host.

@param uri the URI to extract the host from
@return the extracted host
@throws NormalizationException if there is no host for the given uri
974026
public static String getHost(final URI uri) throws NormalizationException {
        final String host = Strings.emptyToNull(uri.getHost());
        if (host == null) {
            throw new NormalizationException(uri.toString(), "No host in URI");
        }
        return host;
    }
79181
public static String flatten(String uri)
	{
		URI normalized = URI.create( raw( uri ) ).normalize();
		String path = normalized.getPath();
		path = stripLeadingSlash( path );
		path = path.replaceAll( "/", "-" );
		return path;
	}
220270
public static InetSocketAddress toInetSocketAddress(URI uri) {
		final InetAddress adr = toInetAddress(uri);
		final int port = uri.getPort();
		if (port <= 0) {
			throw new IllegalArgumentException(uri.toString());
		}
		return new InetSocketAddress(adr, port);
	}
555573
public static String normalizeURI( String uri )
    {
        //
        // If it's a relative URI, normalize it.  Note that we don't want to create a URI
        // (very expensive) unless we think we'll need to.  "./" catches "../" and "./".
        //
        if ( uri.indexOf( "./" ) != -1 )
        {
            try
            {
                uri = new URI( uri ).normalize().toString();
            }
            catch ( URISyntaxException e )
            {
                logger.error( "Could not parse relative URI " + uri );
            }
        }
        
        return uri;
    }
166959
public static URI removeServer(URI uri) {
        try {
            return new URI(null, null, null, -1, uri.getPath(), uri.getQuery(), uri.getFragment());
        } catch (URISyntaxException e) {
            throw new InvalidUriException(e);
        }

    }
937231
private String normalizeParentPath(String uri) {
        String relativeUri = extractRelativeUrl(uri, null);
        if (relativeUri.endsWith("/") && relativeUri.length() != 1) {
            relativeUri = StringUtils.removeEndIgnoreCase(relativeUri, "/");
        }
        return relativeUri;
    }
1220911
public void normalizeByScheme() {
        String rURI = toString();
        String scheme = uri.getScheme();
        String authority = uri.getAuthority();
        String host = uri.getHost();
        int port = uri.getPort();
        String path = uri.getPath();

        if (port == defaultPort(scheme)) {
            rURI = rURI.replaceFirst(":" + port, "");
            try {
                uri = new URI(rURI);
            } catch (URISyntaxException e) {
                // This should never be reached
                e.printStackTrace();
            }
        }

        if (port == -1 && authority != null && authority.endsWith(":")) {
            rURI = rURI.replaceFirst(authority, authority.substring(0, authority.length() -1));
            try {
                uri = new URI(rURI);
            } catch (URISyntaxException e) {
                // This should never be reached
                e.printStackTrace();
            }
        }

        if (path == null || path.length() == 0) {
            if (host != null) {
                rURI = rURI.replaceFirst(host, host + '/');
            } else {
                rURI = rURI.replaceFirst(authority, authority + '/');
            }
            uri = URI.create(rURI);
        }
    }
823126
def get_uri(self, uri, reference):
        
        if uri == "":
            return self.canonicalization(
                constants.TransformInclC14N, reference.getroottree()
            )
        if uri.startswith("#"):
            query = "//*[@*[local-name() = '{}' ]=$uri]"
            node = reference.getroottree()
            results = self.check_uri_attr(node, query, uri, constants.ID_ATTR)
            if len(results) == 0:
                results = self.check_uri_attr(node, query, uri, 'ID')
            if len(results) == 0:
                results = self.check_uri_attr(node, query, uri, 'Id')
            if len(results) == 0:
                results = self.check_uri_attr(node, query, uri, 'id')
            if len(results) > 1:
                raise Exception(
                    "Ambiguous reference URI {} resolved to {} nodes".format(
                        uri, len(results)))
            elif len(results) == 1:
                return self.canonicalization(
                    constants.TransformInclC14N, results[0]
                )
        raise Exception('URI "' + uri + '" cannot be readed')
135453
protected String toBaseURI(String uri) {
    LoaEnum loa = LoaEnum.parse(uri);
    if (loa != null && loa.isSignatureMessageUri()) {
      return LoaEnum.minusSigMessage(loa).getUri();
    }
    return uri;
  }
1031167
function _getHostAddress (uri, defaultHost, defaultPort) {
      const addr = {};

      if (uri === undefined) { // If no uri, use default
        addr.protocol = 'http://';
        addr.port = defaultPort;
        addr.host = defaultHost;
      } else { // Otherwise parse provided uri
        const uriSplit = uri.replace(/http:\/\/|https:\/\//, '').split(':', 2);

        addr.protocol = (uri.toLowerCase().indexOf('https') == 0 ? 'https://' : 'http://');

        if (uriSplit.length == 0) {
          throw new Error('Invalid webdriveruri specified:' + uri);
        } else if (uriSplit.length < 2) {
          addr.port = defaultPort;
        } else {
          addr.port = uriSplit[1];
        }
        addr.host = uriSplit[0];
      }
      return addr.protocol + addr.host + ':' + addr.port;
    }
1006223
@VisibleForTesting
  static URI sourceURI(URI uri) {
    if (!uri.getScheme().equals("jar")) {
      return uri;
    }
    try {
      return URI.create(
          "file:/" + ((JarURLConnection) uri.toURL().openConnection()).getEntryName());
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }
655312
public static String rewriteURI(String uri, HttpHost targetHost) {
        try {
            return URIUtils.rewriteURI(createURI(uri), targetHost).toString();
        } catch (URISyntaxException e) {
            throw new InvalidUriException(e);
        }
    }
524661
def addressable_normalize(url)
      addressable_uri = Addressable::URI.parse(url)
      addressable_uri.normalize.to_s
    end
1013877
def normalize_uri(self, uri):
        """"""
        return urllib.quote(
            re.sub(r"\s", '+', uri.strip().lower()),
            safe = '~@#$&()*!+=:),.?/\'')
1166251
public static InetAddress toInetAddress(URI uri) {
		try {
			// Copy/paste from the ZeroMQ lib
			final String protocol = uri.getScheme();
			final String address = uri.getHost();
			if ("tcp".equalsIgnoreCase(protocol)) { //$NON-NLS-1$
				return InetAddress.getByName(address);
			}
			throw new IllegalArgumentException(uri.toString());
		} catch (UnknownHostException e) {
			throw new IOError(e);
		}
	}
1077544
public function extractHostname( $uri )
    {
        $hostname = false;

        $parts = parse_url( $uri );

        if ( isset( $parts['host'] ) )
            $hostname = $parts['host'];

        return $hostname;
    }
489090
public static String normalizeHostName(String name) {
    try {
      return InetAddress.getByName(name).getHostAddress();
    } catch (UnknownHostException e) {
      return name;
    }
  }