My requirements are fairly simple, but I need to do a lot of this so I'm looking for a robust solution.
Is there a good light-weight library for decomposing URLs into their component parts in Java? I'm referring to hostname, query string, etc.
I am always forgetting the URI format, so here it is:
<scheme>://<userinfo>@<host>:<port><path>#<fragement>
And here an example:
URI uri = new URI ("query://[email protected]:9000/public/manuals/appliances?stove#ge");
The following will happen:
uri.getAuthority()
will return "[email protected]:9000"
uri.getFragment ()
will return "ge"
uri.getHost ()
will return "books.com"
uri.getPath ()
will return "/public/manuals/appliances"
uri.getPort ()
will return 9000
uri.getQuery ()
will return "stove"
uri.getScheme ()
will return "query"
uri.getSchemeSpecificPart ()
will return "//[email protected]:9000/public/manuals/appliances?stove"
uri.getUserInfo ()
will return "jeff"
uri.isAbsolute ()
will return true
uri.isOpaque ()
will return false
I found this blog handy: Exploring Java's Network API: URIs and URLs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With