public class URL extends Object implements Serializable
Modifier and Type | Method and Description |
---|---|
String |
authority() |
static URL |
buildFile()
Gets a URL object for file:// scheme.
|
static URL |
buildHierarchical(String scheme,
String host)
Gets a URL object from a relative scheme and a host.
|
static URL |
buildOpaque(String scheme)
Gets a URL object from a non-relative scheme.
|
int |
defaultPort() |
boolean |
equals(Object obj) |
String |
file() |
String |
fragment() |
static URL |
fromJavaURI(URI uri)
Construct a URL from a
URI . |
static URL |
fromJavaURL(URL url)
Construct a URL from a
URL . |
int |
hashCode() |
Host |
host() |
boolean |
isHierarchical() |
boolean |
isOpaque() |
static URL |
parse(String input)
Parses a URL by using the default parsing options.
|
static URL |
parse(URLParsingSettings settings,
String input) |
static URL |
parse(URLParsingSettings settings,
URL base,
String input) |
static URL |
parse(URL base,
String input) |
String |
password() |
String |
path() |
List<String> |
pathSegments() |
int |
port() |
String |
query() |
String |
relativize(URL url)
Returns a relative URL reference for the given URL.
|
URL |
resolve(String input)
Resolves a relative reference to an absolute URL.
|
String |
scheme() |
String |
schemeData() |
String |
toHumanString()
Serializes the URL to a human-readable representation.
|
URI |
toJavaURI()
Converts to
URI . |
URL |
toJavaURL()
Converts to
URL . |
String |
toString()
Serializes the URL.
|
String |
userInfo()
Gets user info component (i.e. user:pass).
|
String |
username() |
URL |
withFragment(String fragment) |
URL |
withHost(Host host) |
URL |
withHost(String host) |
URL |
withPassword(String password) |
URL |
withPath(String path) |
URL |
withPort(int port) |
URL |
withQuery(String query) |
URL |
withScheme(String scheme) |
URL |
withUsername(String username) |
public String scheme()
public String schemeData()
public String username()
public String password()
public String userInfo()
public Host host()
public String authority()
public int port()
public int defaultPort()
public String path()
public String query()
public String fragment()
public String file()
public boolean isHierarchical()
public boolean isOpaque()
public URL resolve(String input) throws GalimatiasParseException
URL base = URL.parse("http://base.com");
String relativeReference = "/foo/bar";
URL absoluteURL = base.resolve(relativeReference);
input
- Relative reference.GalimatiasParseException
public String relativize(URL url)
url
- Absolute URL.public static URL parse(String input) throws GalimatiasParseException
input
- GalimatiasParseException
public static URL parse(URL base, String input) throws GalimatiasParseException
GalimatiasParseException
public static URL parse(URLParsingSettings settings, String input) throws GalimatiasParseException
GalimatiasParseException
public static URL parse(URLParsingSettings settings, URL base, String input) throws GalimatiasParseException
GalimatiasParseException
public static URL buildHierarchical(String scheme, String host) throws GalimatiasParseException
scheme
- host
- GalimatiasParseException
public static URL buildFile() throws GalimatiasParseException
GalimatiasParseException
public static URL buildOpaque(String scheme) throws GalimatiasParseException
scheme
- GalimatiasParseException
public URL withScheme(String scheme) throws GalimatiasParseException
GalimatiasParseException
public URL withUsername(String username) throws GalimatiasParseException
GalimatiasParseException
public URL withPassword(String password) throws GalimatiasParseException
GalimatiasParseException
public URL withHost(String host) throws GalimatiasParseException
GalimatiasParseException
public URL withHost(Host host) throws GalimatiasParseException
GalimatiasParseException
public URL withPort(int port) throws GalimatiasParseException
GalimatiasParseException
public URL withPath(String path) throws GalimatiasParseException
GalimatiasParseException
public URL withQuery(String query) throws GalimatiasParseException
GalimatiasParseException
public URL withFragment(String fragment) throws GalimatiasParseException
GalimatiasParseException
public URI toJavaURI() throws URISyntaxException
URI
.
Conversion to URI
will throw
URISyntaxException
if 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.
URL.parse("http://example.com").toJavaURI().toString() -> "http://example.com"
URL.parse("http://@example.com").toJavaURI().toString() -> "http://example.com"
TODO: Check if this exception can actually be thrownURISyntaxException
public URL toJavaURL() throws MalformedURLException
URL
.
This method is guaranteed to not throw an exception
for URL protocols http, https, ftp, file and jar.
It might or might not throw MalformedURLException
for other URL protocols.MalformedURLException
public static URL fromJavaURI(URI uri)
URI
.uri
- public static URL fromJavaURL(URL url)
URL
.url
- public String toString()
public String toHumanString()
Copyright © 2013–2014. All rights reserved.