Package com.oorian.utils
Class Url
java.lang.Object
com.oorian.utils.Url
Mutable URL wrapper with query parameter manipulation.
Url provides a convenient way to parse, manipulate, and rebuild URLs.
It automatically parses query parameters into a Parameters object
and can reconstruct the URL after modifications.
- Since:
- 2020
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the authority portion of the URL.getFile()Returns the file portion of the URL (path plus query string).getHost()Returns the host of the URL.Returns the host and port as a combined string.getPath()Returns the path portion of the URL.intgetPort()Returns the port number of the URL.Returns the protocol (scheme) of the URL.getQuery()Returns the query string portion of the URL.getRef()Returns the fragment (anchor) portion of the URL.Returns the user info portion of the URL.final voidsetParameter(String name, String value) Sets or adds a query parameter and rebuilds the URL.final voidSets the URL to a new value, re-parsing the query parameters.toString()
-
Constructor Details
-
Url
Constructs a new Url from the specified URL string.- Parameters:
url- the URL string to parse.- Throws:
MalformedURLException- if the URL is invalid.
-
-
Method Details
-
setUrl
Sets the URL to a new value, re-parsing the query parameters.- Parameters:
url- the URL string to parse.- Throws:
MalformedURLException- if the URL is invalid.
-
setParameter
Sets or adds a query parameter and rebuilds the URL.- Parameters:
name- the parameter name.value- the parameter value.- Throws:
MalformedURLException- if the rebuilt URL is invalid.
-
getQuery
Returns the query string portion of the URL.- Returns:
- the query string, or null if none.
-
getPath
Returns the path portion of the URL.- Returns:
- the path.
-
getUserInfo
Returns the user info portion of the URL.- Returns:
- the user info, or null if none.
-
getAuthority
Returns the authority portion of the URL.- Returns:
- the authority.
-
getProtocol
Returns the protocol (scheme) of the URL.- Returns:
- the protocol (e.g., "https").
-
getHost
Returns the host of the URL.- Returns:
- the host name.
-
getPort
public int getPort()Returns the port number of the URL.- Returns:
- the port number, or -1 if not specified.
-
getHostAndPort
Returns the host and port as a combined string.If no port is specified, returns just the host.
- Returns:
- the host and port (e.g., "example.com:8080" or "example.com").
-
getFile
Returns the file portion of the URL (path plus query string).- Returns:
- the file portion of the URL.
-
getRef
Returns the fragment (anchor) portion of the URL.- Returns:
- the fragment, or null if none.
-
toString
-