public class Urls
extends java.lang.Object
Constructor and Description |
---|
Urls() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
asDataUrlBase64(com.google.common.net.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 character set
(non-deprecated version of URLEncoder.encode)
|
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 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 com.google.common.base.Function<java.lang.String,java.net.URI> |
stringToUriFunction() |
static com.google.common.base.Function<java.lang.String,java.net.URL> |
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 com.google.common.base.Function<java.lang.String,java.net.URI> stringToUriFunction()
public static com.google.common.base.Function<java.lang.String,java.net.URL> 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)
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(com.google.common.net.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.