Package com.helger.base.url
Class URLHelper
java.lang.Object
com.helger.base.url.URLHelper
URL utilities.
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanSpecial equals implementation for URLs becauseURL.equalsperforms a host lookup.
Click here for detailsstatic Filestatic FilegetAsFileOrNull(URL aURL) static URIGet the passed String as an URI.static URIGet the passed URL as an URI.static URLGet the passed String as an URL.static URLGet the passed String as an URL.static URLGet the passed URI as an URL.static URLgetClassPathURL(String sPath) Get the URL for the specified path using automatic class loader handling.static InputStreamgetInputStream(URL aURL, int nConnectTimeoutMS, int nReadTimeoutMS, Consumer<? super URLConnection> aConnectionModifier, IMutableWrapper<IOException> aExceptionHolder) Get an input stream from the specified URL.static StringgetURLString(String sPath, String sQueryParams, String sAnchor) Get the final representation of the URL using the specified elements.static booleanisClassPathURLExisting(String sPath) static booleanisClassPathURLExisting(String sPath, ClassLoader aClassLoader)
-
Method Details
-
equalURLs
Special equals implementation for URLs becauseURL.equalsperforms a host lookup.
Click here for details- Parameters:
aObj1- first URLaObj2- secondURL- Returns:
trueif they contain the same string
-
getURLString
@Nullable public static String getURLString(@Nullable String sPath, @Nullable String sQueryParams, @Nullable String sAnchor) Get the final representation of the URL using the specified elements.- Parameters:
sPath- The main path. May benull.sQueryParams- The set of all query parameters already concatenated with the correct characters (& and =). Any percent encoding necessary must also have been done. May benull.sAnchor- An optional anchor to be added. Any percent encoding necessary must also have been done. May benull.- Returns:
- May be
nullif path, anchor and parameters arenull.
-
getAsURL
Get the passed String as an URL. If the string is empty or not an URLnullis returned.- Parameters:
sURL- Source URL. May benull.bWhine-trueto debug log if conversion failed- Returns:
nullif the passed URL is empty or invalid.
-
getAsURL
Get the passed String as an URL. If the string is empty or not an URLnullis returned.- Parameters:
sURL- Source URL. May benull.- Returns:
nullif the passed URL is empty or invalid.
-
getAsURL
Get the passed URI as an URL. If the URI is null or cannot be converted to an URLnullis returned.- Parameters:
aURI- Source URI. May benull.- Returns:
nullif the passed URI is null or cannot be converted to an URL.
-
getAsURI
Get the passed String as an URI. If the string is empty or not an URInullis returned.- Parameters:
sURI- Source URI. May benull.- Returns:
nullif the passed URI is empty or invalid.
-
getAsURI
Get the passed URL as an URI. If the URL is null or not an URInullis returned.- Parameters:
aURL- Source URL. May benull.- Returns:
nullif the passed URL is empty or invalid.
-
getInputStream
@Nullable public static InputStream getInputStream(@Nonnull URL aURL, @CheckForSigned int nConnectTimeoutMS, @CheckForSigned int nReadTimeoutMS, @Nullable Consumer<? super URLConnection> aConnectionModifier, @Nullable IMutableWrapper<IOException> aExceptionHolder) Get an input stream from the specified URL. By default caching is disabled. This method only handles GET requests - POST requests are not possible.- Parameters:
aURL- The URL to use. May not benull.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.- Returns:
nullif the input stream could not be opened.
-
getAsFile
-
getAsFileOrNull
-
getClassPathURL
Get the URL for the specified path using automatic class loader handling. The class loaders are iterated in the following order:- Default class loader (usually the context class loader)
- The class loader of this class
- The system class loader
- Parameters:
sPath- The path to be resolved. May neither benullnor empty.- Returns:
nullif the path could not be resolved.
-
isClassPathURLExisting
-
isClassPathURLExisting
public static boolean isClassPathURLExisting(@Nonnull @Nonempty String sPath, @Nonnull ClassLoader aClassLoader)
-