Class Reference

java.lang.Object
is.galia.http.Reference

public final class Reference extends Object

Immutable URI class.

Although instances cannot be modified, new modified versions can be created via rebuilder().

Only the schemes in SUPPORTED_SCHEMES are supported.

Components are stored unencoded in order to enable assembly of a partially or fully encoded URI string via one of the toString() overloads.

Also, no checked exceptions are thrown, making it less of a pain to use than URL and URI.

See Also:
  • Field Details

    • SUPPORTED_SCHEMES

      public static final Set<String> SUPPORTED_SCHEMES
  • Constructor Details

    • Reference

      public Reference()
      Constructs an "empty" instance with the http scheme.
    • Reference

      public Reference(Reference reference)
      (Deep) copy constructor.
    • Reference

      public Reference(String uri)
      Throws:
      IllegalArgumentException - if the argument is not a valid URI or has an unrecognized scheme.
    • Reference

      public Reference(URI uri)
    • Reference

      public Reference(Path path)
      Constructor for a file URI.
  • Method Details

    • builder

      public static Reference.Builder builder()
    • decode

      public static String decode(String encoded)
    • encode

      public static String encode(String decoded)
    • equals

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

      public String getAuthority()
      Returns:
      Authority (userinfo + host + port). Never null. If the port is the standard port for the scheme, it is omitted.
    • getFragment

      public String getFragment()
      Returns:
      The fragment, or an empty string if not set.
    • getHost

      public String getHost()
      Returns:
      The host, or an empty string if not set.
    • getPath

      public String getPath()
      Returns:
      The path, or an empty string if not set.
    • getPathSegments

      public List<String> getPathSegments()
      Returns:
      The path segments, or an empty instance if not set.
    • getPathExtension

      public String getPathExtension()
      Returns:
      String after the last period in the last path segment, or an empty string if the last path segment does not contain a period or the period is at the first index in the segment.
    • getPort

      public int getPort()
      Returns:
      -1 unless the instance has a nonstandard port number set.
    • getQuery

      public Query getQuery()
      Returns:
      The query, or an empty instance if not set.
    • getScheme

      public String getScheme()
      Returns:
      Lowercase scheme, or an empty string if not set.
    • getSecret

      public String getSecret()
      Returns:
      The secret, or an empty string if not set.
    • getUser

      public String getUser()
      Returns:
      The user, or an empty string if not set.
    • hashCode

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

      public Reference.Builder rebuilder()
      Returns:
      Reference.Builder of a new instance based on this one.
    • setPathSegment

      public void setPathSegment(int segmentIndex, String segment)
      Updates a segment (token between slashes) of the path.
      Parameters:
      segmentIndex - Zero-based path component index.
      segment - Path segment.
      Throws:
      IndexOutOfBoundsException - if the given index is greater than the number of path components minus one.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      URI string with no additional encoding applied.
    • toString

      public String toString(boolean encodePath)
      Overload that encodes all parts of the URI except the path, which is assumed to already be encoded.
    • toURI

      public URI toURI()