Class URI


public class URI extends URLWithScheme
Represents a hierarchical URI with scheme, host, port, and path components.

This is the concrete URLWithScheme subclass used for standard URLs such as https://example.com:443/path. For opaque/non-hierarchical URLs (e.g. data: or javascript:), see GUID.

Instances can be created directly via the constructor or parsed from a string using parseURI(String).

Author:
Salvation Team
  • Constructor Details

    • URI

      public URI(String scheme, String host, int port, String path)
      Constructs a hierarchical URI with the given components.
      Parameters:
      scheme - the URI scheme (e.g. "https"); will be lowercased
      host - the host name (e.g. "example.com"); will be lowercased
      port - the port number (use defaultPortForProtocol(String) or Constants.EMPTY_PORT for unspecified ports)
      path - the path component (e.g. "/scripts/app.js"); use an empty string if no path is present
  • Method Details

    • parseURI

      public static Optional<URI> parseURI(String uri)
      Parses a hierarchical URI from its string representation.

      The input must contain a scheme (e.g. "https://example.com/path"). If no port is specified, the default port for the scheme is used. If no path is specified, an empty string is used. The host and scheme are lowercased.

      Parameters:
      uri - the URI string to parse
      Returns:
      an Optional containing the parsed URI, or empty if the string does not match the expected URI grammar or has no scheme
    • defaultPortForProtocol

      public static int defaultPortForProtocol(String scheme)
      Returns the default port number for the given protocol scheme.

      Known default ports:

      Default ports by scheme
      SchemePort
      ftp21
      gopher70
      http, ws80
      https, wss443
      fileConstants.EMPTY_PORT

      For unrecognised schemes, Constants.EMPTY_PORT is returned.

      Parameters:
      scheme - the protocol scheme in lowercase (e.g. "https")
      Returns:
      the default port number, or Constants.EMPTY_PORT if the scheme has no default port
      See Also: