Class URL
java.lang.Object
io.mola.galimatias.URL
- All Implemented Interfaces:
Serializable
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionURL(String scheme, String schemeData, String username, String password, Host host, int port, Iterable<String> pathSegments, String query, String fragment, boolean isHierarchical) URL(String scheme, String schemeData, String username, String password, Host host, int port, String path, String query, String fragment, boolean isHierarchical) -
Method Summary
Modifier and TypeMethodDescriptionstatic URLGets a URL object for file:// scheme.static URLbuildHierarchical(String scheme, String host) Gets a URL object from a relative scheme and a host.static URLbuildOpaque(String scheme) Gets a URL object from a non-relative scheme.intprivate static intdefaultPort(String scheme) booleanfile()fragment()static URLfromJavaURI(URI uri) Construct a URL from aURI.static URLfromJavaURL(URL url) Construct a URL from aURL.inthashCode()host()booleanbooleanisOpaque()static URLparse(URLParsingSettings settings, URL base, String input) static URLparse(URLParsingSettings settings, String input) static URLstatic URLParses a URL by using the default parsing options.password()path()private static StringpathSegmentsToString(Iterable<String> segments) pathStringToSegments(String path) intport()query()relativize(URL url) Returns a relative URL reference for the given URL.Resolves a relative reference to an absolute URL.scheme()Serializes the URL to a human-readable representation.Converts toURI.Converts toURL.toString()Serializes the URL.userInfo()Gets user info component (i.e.username()withFragment(String fragment) withPassword(String password) withPort(int port) withScheme(String scheme) withUsername(String username)
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
scheme
-
schemeData
-
username
-
password
-
host
-
port
private final int port -
path
-
query
-
fragment
-
isHierarchical
private final boolean isHierarchical
-
-
Constructor Details
-
URL
-
URL
-
-
Method Details
-
scheme
-
schemeData
-
username
-
password
-
userInfo
Gets user info component (i.e. user:pass). This will return an empty string if neither user or password are set.- Returns:
-
host
-
authority
-
port
public int port() -
defaultPort
-
defaultPort
public int defaultPort() -
path
-
pathSegments
-
query
-
fragment
-
file
-
isHierarchical
public boolean isHierarchical() -
isOpaque
public boolean isOpaque() -
pathSegmentsToString
-
pathStringToSegments
-
resolve
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
-
parse
Parses a URL by using the default parsing options.- Parameters:
input-- Returns:
- Throws:
GalimatiasParseException
-
parse
- Throws:
GalimatiasParseException
-
parse
- Throws:
GalimatiasParseException
-
parse
public static URL parse(URLParsingSettings settings, URL base, String input) throws GalimatiasParseException - Throws:
GalimatiasParseException
-
buildHierarchical
Gets a URL object from a relative scheme and a host.- Parameters:
scheme-host-- Returns:
- Throws:
GalimatiasParseException
-
buildFile
Gets a URL object for file:// scheme.- Returns:
- Throws:
GalimatiasParseException
-
buildOpaque
Gets a URL object from a non-relative scheme.- Parameters:
scheme-- Returns:
- Throws:
GalimatiasParseException
-
withScheme
- Throws:
GalimatiasParseException
-
withUsername
- Throws:
GalimatiasParseException
-
withPassword
- Throws:
GalimatiasParseException
-
withHost
- Throws:
GalimatiasParseException
-
withHost
- Throws:
GalimatiasParseException
-
withPort
- Throws:
GalimatiasParseException
-
withPath
- Throws:
GalimatiasParseException
-
withQuery
- Throws:
GalimatiasParseException
-
withFragment
- Throws:
GalimatiasParseException
-
toJavaURI
Converts 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:
URISyntaxException
-
toJavaURL
Converts 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:
MalformedURLException
-
fromJavaURI
-
fromJavaURL
-
toString
-
toHumanString
Serializes the URL to a human-readable representation. That is, percent-decoded and with IDN domains in its Unicode representation.- Returns:
-
equals
-
hashCode
-