Class IRI


public class IRI extends AnyURI
Implementation of AnyURI that prefers RFC 3987 IRI.

This has consistently formatted percent encodings.

Furthermore, this assumes UTF-8 encoding for the query parameters. If the query parameters include any arbitrary encoded data, use AnyURI or URI instead.

When a strict ASCII-only representation of a RFC 3986 URI is required, use URI. When a Unicode representation of a RFC 3987 IRI is preferred, use IRI. Otherwise, to support both, use AnyURI, which should also perform the best since it performs fewer conversions.

Author:
AO Industries, Inc.
  • Field Details

  • Constructor Details

    • IRI

      public IRI(String anyUri)
  • Method Details

    • toString

      public String toString()
      Gets the full IRI in RFC 3987 IRI Unicode format.

      This will be percent-encoding normalized and contain consistently formatted percent encodings.

      Overrides:
      toString in class AnyURI
    • toASCIIString

      public String toASCIIString()
      Gets the full URI in RFC 3986 URI US-ASCII format.

      This will be percent-encoding normalized and contain consistently formatted percent encodings.

      Overrides:
      toASCIIString in class AnyURI
    • appendScheme

      public IRI appendScheme(Appendable out) throws IOException
      Description copied from class: AnyURI
      Appends the scheme (not including the ':').
      Overrides:
      appendScheme in class AnyURI
      Returns:
      this
      Throws:
      IOException
    • appendScheme

      public IRI appendScheme(Encoder encoder, Appendable out) throws IOException
      Description copied from class: AnyURI
      Appends the scheme (not including the ':').
      Overrides:
      appendScheme in class AnyURI
      Returns:
      this
      Throws:
      IOException
    • appendHierPart

      public IRI appendHierPart(Appendable out) throws IOException
      Description copied from class: AnyURI
      Appends the part of the URI after the scheme and up to the first '?' or '#' (exclusive), or the full URI when neither found.
      Overrides:
      appendHierPart in class AnyURI
      Returns:
      this
      Throws:
      IOException
    • appendHierPart

      public IRI appendHierPart(Encoder encoder, Appendable out) throws IOException
      Description copied from class: AnyURI
      Appends the part of the URI after the scheme and up to the first '?' or '#' (exclusive), or the full URI when neither found.
      Overrides:
      appendHierPart in class AnyURI
      Returns:
      this
      Throws:
      IOException
    • appendQueryString

      public IRI appendQueryString(Appendable out) throws IOException
      Description copied from class: AnyURI
      Appends the query string (not including the '?').
      Overrides:
      appendQueryString in class AnyURI
      Returns:
      this
      Throws:
      IOException
    • appendQueryString

      public IRI appendQueryString(Encoder encoder, Appendable out) throws IOException
      Description copied from class: AnyURI
      Appends the query string (not including the '?').
      Overrides:
      appendQueryString in class AnyURI
      Returns:
      this
      Throws:
      IOException
    • appendFragment

      public IRI appendFragment(Appendable out) throws IOException
      Description copied from class: AnyURI
      Appends the fragment (not including the '#').
      Overrides:
      appendFragment in class AnyURI
      Returns:
      this
      Throws:
      IOException
    • appendFragment

      public IRI appendFragment(Encoder encoder, Appendable out) throws IOException
      Description copied from class: AnyURI
      Appends the fragment (not including the '#').
      Overrides:
      appendFragment in class AnyURI
      Returns:
      this
      Throws:
      IOException
    • isEncodingNormalized

      public boolean isEncodingNormalized()
      Is this URI percent-encoding normalized? Normalized percent encoding means it will have only the required percent encodings, and the encodings are capitalized hexadecimal.

      Note: This only refers to the percent encodings. This is not related to full URI normalization.

      Overrides:
      isEncodingNormalized in class AnyURI
      Returns:
      true - IRI are always encoding normalized.
    • toURI

      public URI toURI()
      Gets this URI encoded in RFC 3986 URI US-ASCII format.

      This will be percent-encoding normalized and contain consistently formatted percent encodings.

      Overrides:
      toURI in class AnyURI
      Returns:
      The URI.
      See Also:
    • toIRI

      public IRI toIRI()
      Gets this URI encoded in RFC 3987 IRI Unicode format.
      Overrides:
      toIRI in class AnyURI
      Returns:
      this
      See Also:
    • setHierPart

      public IRI setHierPart(String hierPart)
      Description copied from class: AnyURI
      Replaces the hier-part.
      Overrides:
      setHierPart in class AnyURI
      Parameters:
      hierPart - The hier-part may not contain the query marker '?' or fragment marker '#'
      Returns:
      The new AnyURI or this when unmodified.
    • setQueryString

      public IRI setQueryString(String query)
      Description copied from class: AnyURI
      Replaces the query string.
      Overrides:
      setQueryString in class AnyURI
      Parameters:
      query - The query (not including the first '?') - it is added without additional encoding. The query is removed when the query is null. The query may not contain the fragment marker '#'
      Returns:
      The new AnyURI or this when unmodified.
    • addQueryString

      public IRI addQueryString(String query)
      Description copied from class: AnyURI
      Adds a query string.
      Overrides:
      addQueryString in class AnyURI
      Parameters:
      query - The query (not including the first '?' / '&') - it is added without additional encoding. Nothing is added when the query is null. The query may not contain the fragment marker '#'
      Returns:
      The new AnyURI or this when unmodified.
    • addEncodedParameter

      public IRI addEncodedParameter(String encodedName, String encodedValue)
      Description copied from class: AnyURI
      Adds an already-encoded parameter.
      Overrides:
      addEncodedParameter in class AnyURI
      Parameters:
      encodedName - The parameter name - it is added without additional encoding. Nothing is added when the name is null. The name may not contain the fragment marker '#'
      encodedValue - The parameter value - it is added without additional encoding. When null, the parameter is added without any '='. Must be null when name is null. The value may not contain the fragment marker '#'
      Returns:
      The new AnyURI or this when unmodified.
    • addParameter

      public IRI addParameter(String name, String value)
      Description copied from class: AnyURI
      Encodes and adds a parameter.
      Overrides:
      addParameter in class AnyURI
      Parameters:
      name - The parameter name. Nothing is added when the name is null.
      value - The parameter value. When null, the parameter is added without any '='. Must be null when name is null.
      Returns:
      The new AnyURI or this when unmodified.
      See Also:
    • addParameters

      public IRI addParameters(URIParameters params)
      Description copied from class: AnyURI
      Adds all of the parameters.
      Overrides:
      addParameters in class AnyURI
      Parameters:
      params - The parameters to add. Nothing is added when null or empty.
      Returns:
      The new AnyURI or this when unmodified.
      See Also:
    • setEncodedFragment

      public IRI setEncodedFragment(String encodedFragment)
      Description copied from class: AnyURI
      Replaces the fragment.
      Overrides:
      setEncodedFragment in class AnyURI
      Parameters:
      encodedFragment - The fragment (not including the '#') - it is added without additional encoding. Removes fragment when null.
      Returns:
      The new AnyURI or this when unmodified.
    • setFragment

      public IRI setFragment(String fragment)
      Description copied from class: AnyURI
      Replaces the fragment in the default encoding ENCODING.

      TODO: Implement specification of fragment-escape.

      Overrides:
      setFragment in class AnyURI
      Parameters:
      fragment - The fragment (not including the '#') or null for no fragment.
      Returns:
      The new AnyURI or this when unmodified.