public class Urls
extends java.lang.Object
Constructor and Description |
---|
Urls() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
asDataUrlBase64(MediaType type,
byte[] bytes)
Creates a "data:..." scheme URL for use with supported parsers, using Base64 encoding.
|
static java.lang.String |
asDataUrlBase64(java.lang.String data)
as
asDataUrlBase64(String) with plain text |
static java.lang.String |
decode(java.lang.String text)
|
static java.lang.String |
encode(java.lang.String text)
Encodes the string suitable for use in a URL, using default UTF-8
(version of URLEncoder.encode that does not throw checked exception)
|
static java.lang.String |
getBasename(java.lang.String url)
return the last segment of the given url before any '?', e.g.
|
static java.lang.String |
getProtocol(java.lang.String url)
returns the protocol (e.g.
|
static boolean |
isDirectory(java.lang.String fileUrl) |
static boolean |
isUrlWithProtocol(java.lang.String x)
returns true if the string begins with a non-empty string of letters followed by a colon,
i.e.
|
static boolean |
isUrlWithProtocol(java.lang.String x,
boolean allowSpacesAfterCharAfterColon,
boolean allowMultiline)
as
isUrlWithProtocol(String) but configurable to be strict (false, false) or allow newline chars (if e.g. |
static java.lang.String |
mergePaths(java.lang.String... items)
returns the items with exactly one "/" between items (whether or not the individual items start or end with /),
except where character before the / is a : (url syntax) in which case it will permit multiple (will not remove any).
|
static <any> |
stringToUriFunction() |
static <any> |
stringToUrlFunction() |
static java.io.File |
toFile(java.lang.String fileUrl) |
static java.net.URI |
toUri(java.lang.String uri)
creates a URI, preserving null and propagating exceptions *unchecked*
|
static java.net.URI |
toUri(java.net.URL url)
creates a URI, preserving null and propagating exceptions *unchecked*
|
static java.net.URL |
toUrl(java.lang.String url)
creates a URL, preserving null and propagating exceptions *unchecked*
|
static java.net.URL |
toUrl(java.net.URI uri)
creates a URL, preserving null and propagating exceptions *unchecked*
|
public static <any> stringToUriFunction()
public static <any> stringToUrlFunction()
public static final java.net.URL toUrl(@Nullable java.lang.String url)
public static final java.net.URL toUrl(@Nullable java.net.URI uri)
public static final java.net.URI toUri(@Nullable java.lang.String uri)
public static final java.net.URI toUri(@Nullable java.net.URL url)
public static boolean isUrlWithProtocol(java.lang.String x)
isUrlWithProtocol(String, boolean, boolean)
public static boolean isUrlWithProtocol(java.lang.String x, boolean allowSpacesAfterCharAfterColon, boolean allowMultiline)
isUrlWithProtocol(String)
but configurable to be strict (false, false) or allow newline chars (if e.g. in an unescaped argument)public static java.lang.String mergePaths(java.lang.String... items)
public static java.lang.String encode(java.lang.String text)
public static java.lang.String decode(java.lang.String text)
public static java.lang.String getProtocol(java.lang.String url)
c:\xxx
being treated as a url)public static java.lang.String getBasename(java.lang.String url)
public static boolean isDirectory(java.lang.String fileUrl)
public static java.io.File toFile(java.lang.String fileUrl)
public static java.lang.String asDataUrlBase64(java.lang.String data)
asDataUrlBase64(String)
with plain textpublic static java.lang.String asDataUrlBase64(MediaType type, byte[] bytes)
It is not necessary (at least for Brookyn's routines) to base64 encode it, but recommended as that is likely more portable and easier to work with if odd characters are included.
It is worth noting that Base64 uses '+' which can be replaced by ' ' in some URL parsing.
But in practice it does not seem to cause issues.
An alternative is to use BaseEncoding#base64Url()
but it is not clear how widely that is supported
(nor what parameter should be given to indicate that type of encoding, as the spec calls for 'base64'!)
null type means no type info will be included in the URL.