Class HostAndPort

java.lang.Object
org.newsclub.net.unix.HostAndPort

public final class HostAndPort extends Object
Hostname and port.
Author:
Christian Kohlschütter
  • Constructor Summary

    Constructors
    Constructor
    Description
    HostAndPort(String hostname, int port)
    Creates a new hostname and port combination.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    Returns the hostname.
    int
    Returns the port, or -1 for "no port specified".
    int
     
    Tries to extract hostname and port information from the given URI.
     
    toURI(String scheme)
    Returns a URI with this hostname and port.
    toURI(String scheme, String rawAuthority, String rawPath, String rawQuery, String rawFragment)
    Returns a URI with this hostname and port, potentially using other URI parameters from the given set of parameters.
    toURI(String scheme, URI template)
    Returns a URI with this hostname and port, potentially reusing other URI parameters from the given template URI (authority, path, query, fragment).

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • HostAndPort

      public HostAndPort(String hostname, int port)
      Creates a new hostname and port combination.
      Parameters:
      hostname - The hostname.
      port - The port, or -1 for "no port".
  • Method Details

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • parseFrom

      public static HostAndPort parseFrom(URI u) throws SocketException
      Tries to extract hostname and port information from the given URI.
      Parameters:
      u - The URI to extract from.
      Returns:
      The parsed HostAndPort instance.
      Throws:
      SocketException - on error.
    • getHostname

      public String getHostname()
      Returns the hostname.
      Returns:
      The hostname.
    • getPort

      public int getPort()
      Returns the port, or -1 for "no port specified".
      Returns:
      The port.
    • toURI

      public URI toURI(String scheme)
      Returns a URI with this hostname and port.
      Parameters:
      scheme - The scheme to use.
      Returns:
      The URI.
    • toURI

      public URI toURI(String scheme, URI template)
      Returns a URI with this hostname and port, potentially reusing other URI parameters from the given template URI (authority, path, query, fragment).
      Parameters:
      scheme - The scheme to use.
      template - The template. or null.
      Returns:
      The URI.
    • toURI

      public URI toURI(String scheme, String rawAuthority, String rawPath, String rawQuery, String rawFragment)
      Returns a URI with this hostname and port, potentially using other URI parameters from the given set of parameters.
      Parameters:
      scheme - The scheme to use.
      rawAuthority - The raw authority field, or null.
      rawPath - The raw path field, or null.
      rawQuery - The raw query field, or null.
      rawFragment - The raw fragment field, or null.
      Returns:
      The URI.