Package io.mola.galimatias
Class URL
- java.lang.Object
-
- io.mola.galimatias.URL
-
- All Implemented Interfaces:
java.io.Serializable
public class URL extends java.lang.Object implements java.io.SerializableA parsed URL. Immutable.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringauthority()intdefaultPort()booleanequals(java.lang.Object obj)java.lang.Stringfile()java.lang.Stringfragment()static URLfromJavaURI(java.net.URI uri)Construct a URL from aURI.static URLfromJavaURL(java.net.URL url)Construct a URL from aURL.inthashCode()Hosthost()booleanisHierarchical()booleanisOpaque()static URLparse(URLParsingSettings settings, URL base, java.lang.String input)static URLparse(URLParsingSettings settings, java.lang.String input)static URLparse(URL base, java.lang.String input)static URLparse(java.lang.String input)Parses a URL by using the default parsing options.java.lang.Stringpassword()java.lang.Stringpath()java.util.List<java.lang.String>pathSegments()intport()java.lang.Stringquery()java.lang.Stringrelativize(URL url)Returns a relative URL reference for the given URL.URLresolve(java.lang.String input)Resolves a relative reference to an absolute URL.java.lang.Stringscheme()java.lang.StringschemeData()java.lang.StringtoHumanString()Serializes the URL to a human-readable representation.java.net.URItoJavaURI()Converts toURI.java.net.URLtoJavaURL()Converts toURL.java.lang.StringtoString()Serializes the URL.java.lang.StringuserInfo()Gets user info component (i.e.java.lang.Stringusername()URLwithFragment(java.lang.String fragment)URLwithHost(Host host)URLwithHost(java.lang.String host)URLwithPassword(java.lang.String password)URLwithPath(java.lang.String path)URLwithPort(int port)URLwithQuery(java.lang.String query)URLwithScheme(java.lang.String scheme)URLwithUsername(java.lang.String username)
-
-
-
Method Detail
-
scheme
public java.lang.String scheme()
-
schemeData
public java.lang.String schemeData()
-
username
public java.lang.String username()
-
password
public java.lang.String password()
-
userInfo
public java.lang.String userInfo()
Gets user info component (i.e. user:pass). This will return an empty string if neither user or password are set.- Returns:
-
host
public Host host()
-
authority
public java.lang.String authority()
-
port
public int port()
-
defaultPort
public int defaultPort()
-
path
public java.lang.String path()
-
pathSegments
public java.util.List<java.lang.String> pathSegments()
-
query
public java.lang.String query()
-
fragment
public java.lang.String fragment()
-
file
public java.lang.String file()
-
isHierarchical
public boolean isHierarchical()
-
isOpaque
public boolean isOpaque()
-
resolve
public URL resolve(java.lang.String input) throws GalimatiasParseException
Resolves a relative reference to an absolute URL. This is just a convenience method equivalent to:URL base = URL.parse("http://base.com"); String relativeReference = "/foo/bar"; URL absoluteURL = base.resolve(relativeReference);- Parameters:
input- Relative reference.- Returns:
- Resolved absolute URL.
- Throws:
GalimatiasParseException
-
relativize
public java.lang.String relativize(URL url)
Returns a relative URL reference for the given URL. Behaves as @{link java.net.URI#relativize(URL)}.- Parameters:
url- Absolute URL.- Returns:
- Relative reference.
-
parse
public static URL parse(java.lang.String input) throws GalimatiasParseException
Parses a URL by using the default parsing options.- Parameters:
input-- Returns:
- Throws:
GalimatiasParseException
-
parse
public static URL parse(URL base, java.lang.String input) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
parse
public static URL parse(URLParsingSettings settings, java.lang.String input) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
parse
public static URL parse(URLParsingSettings settings, URL base, java.lang.String input) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
withScheme
public URL withScheme(java.lang.String scheme) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
withUsername
public URL withUsername(java.lang.String username) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
withPassword
public URL withPassword(java.lang.String password) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
withHost
public URL withHost(java.lang.String host) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
withHost
public URL withHost(Host host) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
withPort
public URL withPort(int port) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
withPath
public URL withPath(java.lang.String path) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
withQuery
public URL withQuery(java.lang.String query) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
withFragment
public URL withFragment(java.lang.String fragment) throws GalimatiasParseException
- Throws:
GalimatiasParseException
-
toJavaURI
public java.net.URI toJavaURI() throws java.net.URISyntaxExceptionConverts toURI. Conversion toURIwill throwURISyntaxExceptionif the URL contains unescaped unsafe characters as defined in RFC 2396. In order to prevent this, force RFC 2396 compliance when parsing the URL. For example: NOTE 1: This will not make distinction between no user and password and just empty user and no password.TODO: Check if this exception can actually be thrownURL.parse("http://example.com").toJavaURI().toString() → "http://example.com" URL.parse("http://@example.com").toJavaURI().toString() → "http://example.com"- Returns:
- Throws:
java.net.URISyntaxException
-
toJavaURL
public java.net.URL toJavaURL() throws java.net.MalformedURLExceptionConverts toURL. This method is guaranteed to not throw an exception for URL protocols http, https, ftp, file and jar. It might or might not throwMalformedURLExceptionfor other URL protocols.- Returns:
- Throws:
java.net.MalformedURLException
-
fromJavaURI
public static URL fromJavaURI(java.net.URI uri)
Construct a URL from aURI.- Parameters:
uri-- Returns:
-
fromJavaURL
public static URL fromJavaURL(java.net.URL url)
Construct a URL from aURL.- Parameters:
url-- Returns:
-
toString
public java.lang.String toString()
Serializes the URL. Note that the "exclude fragment flag" (as in WHATWG standard) is not implemented.- Overrides:
toStringin classjava.lang.Object
-
toHumanString
public java.lang.String toHumanString()
Serializes the URL to a human-readable representation. That is, percent-decoded and with IDN domains in its Unicode representation.- Returns:
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-