Package com.yahoo.net
Class URI
java.lang.Object
com.yahoo.net.URI
- All Implemented Interfaces:
Cloneable
,Comparable<URI>
An URI. This is a pure (immutable) value object.
This does more normalization of hierarchical URIs (URLs) than described in the RFC and allows hosts with underscores.
- Author:
- bratseth
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionCreates an URI without keeping the fragment (the part starting by #).Creates an URI, optionaly keeping the fragment (the part starting by #).Creates an URI, optionaly keeping the fragment (the part starting by #).Creates an url type uri -
Method Summary
Modifier and TypeMethodDescriptionaddParameter
(String name, String value) Returns a new uri with the an additional parameterclone()
int
boolean
int
getDepth()
Returns the depth of this uri.getHost()
Returns the normalized host of this URI.Returns an explanation of why this uri is invalid, or null if it is validgetPath()
int
getPort()
Returns the port number of this scheme if set explicitly, or -1 otherwisegetQuery()
getRest()
Returns the rest of this uri, that is what is following the host or port.Returns the normalized scheme of this URI.int
hashCode()
boolean
isOpaque()
Returns whether this URI is hierarchical or opaque.boolean
isValid()
Returns whether this is a valid URI (after normalizing).Returns a new URI with a changed host (or authority)setPort
(int port) Returns a new URI with a changed portReturns a new URI with a changed restReturns a new URI with a changed schemeReturns this uri as a stringtokenize()
static String[]
toString()
Returns this URI as a string
-
Constructor Details
-
URI
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
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 stringkeepFragment
- true to keep the fragment- Throws:
NullPointerException
- if the given uriString is null
-
URI
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 stringkeepFragment
- true to keep the fragmenthierarchicalOnly
- 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
Creates an url type uri
-
-
Method Details
-
isValid
public boolean isValid()Returns whether this is a valid URI (after normalizing). All non-hierarchical uri's containing a scheme is valid. -
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
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
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
-
getMainTld
-
getPath
-
getFilename
-
getExtension
-
getQuery
-
getFragment
-
getParams
-
tokenize
-
tokenize
-
getInvalidExplanation
Returns an explanation of why this uri is invalid, or null if it is valid -
hashCode
public int hashCode() -
equals
-
compareTo
- Specified by:
compareTo
in interfaceComparable<URI>
-
clone
-
setScheme
Returns a new URI with a changed scheme -
setHost
Returns a new URI with a changed host (or authority) -
setPort
Returns a new URI with a changed port -
setRest
Returns a new URI with a changed rest -
addParameter
Returns a new uri with the an additional parameter -
stringValue
Returns this uri as a string -
toString
Returns this URI as a string -
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
-