Package com.yahoo.net

Class URI

    • Constructor Detail

      • URI

        public URI​(String uriString)

        Creates an URI without keeping the fragment (the part starting by #). If the uri is hierarchical, it is normalized and incorrect hierarchical uris which looks like urls are attempted repaired.

        Relative uris are not supported.

        Parameters:
        uriString - the uri string
        Throws:
        NullPointerException - if the given uriString is null
      • URI

        public URI​(String uriString,
                   boolean keepFragment)
        Creates an URI, optionaly keeping the fragment (the part starting by #). If the uri is hierarchical, it is normalized and incorrect hierarchical uris which looks like urls are attempted repaired.

        Relative uris are not supported.

        Parameters:
        uriString - the uri string
        keepFragment - true to keep the fragment
        Throws:
        NullPointerException - if the given uriString is null
      • URI

        public URI​(String uriString,
                   boolean keepFragment,
                   boolean hierarchicalOnly)
        Creates an URI, optionaly keeping the fragment (the part starting by #). If the uri is hierarchical, it is normalized and incorrect hierarchical uris which looks like urls are attempted repaired.

        Relative uris are not supported.

        Parameters:
        uriString - the uri string
        keepFragment - true to keep the fragment
        hierarchicalOnly - will force any uri string given to be parsed as a hierarchical one, causing the uri to be invalid if it isn't
        Throws:
        NullPointerException - if the given uriString is null
      • URI

        public URI​(String scheme,
                   String host,
                   int port,
                   String rest)
        Creates an url type uri
    • Method Detail

      • isValid

        public boolean isValid()
        Returns whether this is a valid URI (after normalizing). All non-hierarchical uri's containing a scheme is valid.
      • getScheme

        public String getScheme()
        Returns the normalized scheme of this URI.
        Returns:
        the normalized scheme (protocol), or null if there is none, which may only be the case with non-hierarchical URIs
      • isOpaque

        public boolean isOpaque()
        Returns whether this URI is hierarchical or opaque. A typical example of an hierarchical URI is an URL, while URI's are mailto, news and such.
        Returns:
        true if the url is opaque, false if it is hierarchical
      • getHost

        public String getHost()
        Returns the normalized host of this URI.
        Returns:
        the normalized host, or null if there is none, which may only be the case if this is a non-hierarchical uri
      • getPort

        public int getPort()
        Returns the port number of this scheme if set explicitly, or -1 otherwise
      • getRest

        public String getRest()
        Returns the rest of this uri, that is what is following the host or port. This is path, query and fragment as defined in RFC 2396. Returns an empty string if this uri has no rest.
      • getDomain

        public String getDomain()
      • getMainTld

        public String getMainTld()
      • getPath

        public String getPath()
      • getFilename

        public String getFilename()
      • getExtension

        public String getExtension()
      • getQuery

        public String getQuery()
      • getFragment

        public String getFragment()
      • getParams

        public String getParams()
      • tokenize

        public static String[] tokenize​(String item)
      • getInvalidExplanation

        public String getInvalidExplanation()
        Returns an explanation of why this uri is invalid, or null if it is valid
      • hashCode

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

        public URI setScheme​(String scheme)
        Returns a new URI with a changed scheme
      • setHost

        public URI setHost​(String host)
        Returns a new URI with a changed host (or authority)
      • setPort

        public URI setPort​(int port)
        Returns a new URI with a changed port
      • setRest

        public URI setRest​(String rest)
        Returns a new URI with a changed rest
      • addParameter

        public URI addParameter​(String name,
                                String value)
        Returns a new uri with the an additional parameter
      • stringValue

        public String stringValue()
        Returns this uri as a string
      • toString

        public String toString()
        Returns this URI as a string
        Overrides:
        toString in class Object
      • getDepth

        public int getDepth()
        Returns the depth of this uri. The depth of an hierarchical uri equals the number of slashes which are not separating the protocol and the host, and not at the end.
        Returns:
        the depth of this uri if it is hierarchical, or 0 if it is opaque