@ThreadSafe public final class URLHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static char |
AMPERSAND
Separator between params: &
|
static String |
AMPERSAND_STR |
static Charset |
CHARSET_URL_OBJ
Default URL charset is UTF-8
|
static char |
EQUALS
Separator between param name and param value: =
|
static String |
EQUALS_STR |
static char |
HASH
Separator between URL path and anchor name: #
|
static String |
HASH_STR |
static String |
PROTOCOL_FILE
The protocol for file resources
|
static char |
QUESTIONMARK
Separator before first param: ?
|
static String |
QUESTIONMARK_STR |
| Modifier and Type | Method and Description |
|---|---|
static File |
getAsFile(URL aURL) |
static File |
getAsFileOrNull(URL aURL) |
static URI |
getAsURI(String sURI)
Get the passed String as an URI.
|
static URI |
getAsURI(URL aURL)
Get the passed URL as an URI.
|
static URL |
getAsURL(String sURL)
Get the passed String as an URL.
|
static URL |
getAsURL(URI aURI)
Get the passed URI as an URL.
|
static IURLData |
getAsURLData(String sHref) |
static IURLData |
getAsURLData(String sHref,
IDecoder<String,String> aParameterDecoder)
Parses the passed URL into a structured form
|
static URL |
getClassPathURL(String sPath)
Get the URL for the specified path using automatic class loader handling.
|
static String |
getCleanURLPartWithoutUmlauts(String sURLPart)
Clean an URL part from nasty Umlauts.
|
static InputStream |
getInputStream(URL aURL,
int nConnectTimeoutMS,
int nReadTimeoutMS,
Consumer<URLConnection> aConnectionModifier,
IMutableWrapper<IOException> aExceptionHolder)
Get an input stream from the specified URL.
|
static URLParameterList |
getParsedQueryParameters(String sQueryString) |
static URLParameterList |
getParsedQueryParameters(String sQueryString,
IDecoder<String,String> aParameterDecoder) |
static String |
getQueryParametersAsString(List<URLParameter> aQueryParams,
IEncoder<String,String> aQueryParameterEncoder)
Create a parameter string.
|
static String |
getURLString(IURLData aURL,
Charset aParameterCharset) |
static String |
getURLString(String sPath,
List<URLParameter> aQueryParams,
String sAnchor,
Charset aParameterCharset)
Get the final representation of the URL using the specified elements.
|
static String |
getURLString(String sPath,
List<URLParameter> aQueryParams,
String sAnchor,
IEncoder<String,String> aQueryParameterEncoder)
Get the final representation of the URL using the specified elements.
|
static String |
getURLString(String sPath,
String sQueryParams,
String sAnchor)
Get the final representation of the URL using the specified elements.
|
static boolean |
isClassPathURLExisting(String sPath) |
static boolean |
isClassPathURLExisting(String sPath,
ClassLoader aClassLoader) |
static String |
urlDecode(String sValue)
URL-decode the passed value automatically handling charset issues.
|
static String |
urlDecode(String sValue,
Charset aCharset)
URL-decode the passed value automatically handling charset issues.
|
static String |
urlEncode(String sValue)
URL-encode the passed value automatically handling charset issues.
|
static String |
urlEncode(String sValue,
Charset aCharset)
URL-encode the passed value automatically handling charset issues.
|
public static final Charset CHARSET_URL_OBJ
public static final char QUESTIONMARK
public static final String QUESTIONMARK_STR
public static final char AMPERSAND
public static final String AMPERSAND_STR
public static final char EQUALS
public static final String EQUALS_STR
public static final char HASH
public static final String HASH_STR
public static final String PROTOCOL_FILE
@Nonnull public static String urlDecode(@Nonnull String sValue)
CHARSET_URL_OBJ.sValue - The value to be decoded. May not be null.@Nonnull public static String urlDecode(@Nonnull String sValue, @Nonnull Charset aCharset)
sValue - The value to be decoded. May not be null.aCharset - The charset to use. May not be null.URLDecoder.decode(String, String)@Nonnull public static String urlEncode(@Nonnull String sValue)
CHARSET_URL_OBJ.sValue - The value to be encoded. May not be null.@Nonnull public static String urlEncode(@Nonnull String sValue, @Nonnull Charset aCharset)
sValue - The value to be encoded. May not be null.aCharset - The charset to use. May not be null.@Nullable public static String getCleanURLPartWithoutUmlauts(@Nullable String sURLPart)
sURLPart - The original URL part. May be null.null if the input was
null.@Nonnull public static IURLData getAsURLData(@Nonnull String sHref, @Nullable IDecoder<String,String> aParameterDecoder)
sHref - The URL to be parsedaParameterDecoder - The parameter decoder to use. May be null.IURLData representation of the passed URL@Nonnull @ReturnsMutableCopy public static URLParameterList getParsedQueryParameters(@Nullable String sQueryString, @Nullable IDecoder<String,String> aParameterDecoder)
@Nonnull @ReturnsMutableCopy public static URLParameterList getParsedQueryParameters(@Nullable String sQueryString)
@Nullable public static String getURLString(@Nullable String sPath, @Nullable String sQueryParams, @Nullable String sAnchor)
sPath - The main path. May be null.sQueryParams - The set of all query parameters already concatenated with the
correct characters (& and =). May be null.sAnchor - An optional anchor to be added. May be null.null if path, anchor and parameters are
null.@Nullable public static String getQueryParametersAsString(@Nullable List<URLParameter> aQueryParams, @Nullable IEncoder<String,String> aQueryParameterEncoder)
aQueryParams - Parameter map. May be null or empty.aQueryParameterEncoder - The encoder to be used to encode parameter names and parameter
values. May be null. This may be e.g. a
URLParameterEncoder.null if no parameter is present.@Nonnull public static String getURLString(@Nonnull IURLData aURL, @Nullable Charset aParameterCharset)
@Nullable public static String getURLString(@Nullable String sPath, @Nullable List<URLParameter> aQueryParams, @Nullable String sAnchor, @Nullable IEncoder<String,String> aQueryParameterEncoder)
sPath - The main path. May be null.aQueryParams - The list of query parameters to be appended. May be
null .sAnchor - An optional anchor to be added. May be null.aQueryParameterEncoder - The parameters encoding to be used. May be null.null if path, anchor and parameters are
null.@Nullable public static String getURLString(@Nullable String sPath, @Nullable List<URLParameter> aQueryParams, @Nullable String sAnchor, @Nullable Charset aParameterCharset)
sPath - The main path. May be null.aQueryParams - The list of parameters to be appended. May be null.sAnchor - An optional anchor to be added. May be null.aParameterCharset - If not null the parameters are encoded using this
charset.null if all parameters are null.@Nullable public static URL getAsURL(@Nullable String sURL)
null is returned.sURL - Source URL. May be null.null if the passed URL is empty or invalid.@Nullable public static URL getAsURL(@Nullable URI aURI)
null is returned.aURI - Source URI. May be null.null if the passed URI is null or cannot be converted
to an URL.@Nullable public static URI getAsURI(@Nullable String sURI)
null is returned.sURI - Source URI. May be null.null if the passed URI is empty or invalid.@Nullable public static URI getAsURI(@Nullable URL aURL)
null is returned.aURL - Source URL. May be null.null if the passed URL is empty or invalid.@Nullable public static InputStream getInputStream(@Nonnull URL aURL, @CheckForSigned int nConnectTimeoutMS, @CheckForSigned int nReadTimeoutMS, @Nullable Consumer<URLConnection> aConnectionModifier, @Nullable IMutableWrapper<IOException> aExceptionHolder)
aURL - The URL to use. May not be null.nConnectTimeoutMS - Connect timeout milliseconds. 0 == infinite. < 0: ignored.nReadTimeoutMS - Read timeout milliseconds. 0 == infinite. < 0: ignored.aConnectionModifier - An optional callback object to modify the URLConnection before it is
opened.aExceptionHolder - An optional exception holder for further outside investigation.null if the input stream could not be opened.@Nullable public static URL getClassPathURL(@Nonnull @Nonempty String sPath)
sPath - The path to be resolved. May neither be null nor empty.null if the path could not be resolved.public static boolean isClassPathURLExisting(@Nonnull @Nonempty String sPath)
public static boolean isClassPathURLExisting(@Nonnull @Nonempty String sPath, @Nonnull ClassLoader aClassLoader)
Copyright © 2014–2017 Philip Helger. All rights reserved.