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 @NonNull FileConvert a URL to aFile.static @Nullable FilegetAsFileOrNull(@Nullable URL aURL) Try to convert a URL to aFile.static @Nullable URIGet the passed String as an URI.static @Nullable URIGet the passed URL as an URI.static @Nullable URLGet the passed String as an URL.static @Nullable URLGet the passed String as an URL.static @Nullable URLGet the passed URI as an URL.static @Nullable URLgetClassPathURL(@NonNull @Nonempty String sPath) Get the URL for the specified path using automatic class loader handling.static @Nullable InputStreamgetInputStream(@NonNull URL aURL, int nConnectTimeoutMS, int nReadTimeoutMS, @Nullable Consumer<? super URLConnection> aConnectionModifier, @Nullable IMutableWrapper<IOException> aExceptionHolder) Get an input stream from the specified URL.static @Nullable StringgetURLString(@Nullable String sPath, @Nullable String sQueryParams, @Nullable String sAnchor) Get the final representation of the URL using the specified elements.static booleanisClassPathURLExisting(@NonNull @Nonempty String sPath) Check if a classpath URL exists for the given path.static booleanisClassPathURLExisting(@NonNull @Nonempty String sPath, @NonNull ClassLoader aClassLoader) Check if a classpath URL exists for the given path using the specified class loader.
-
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
public static @Nullable 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
public static @Nullable 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
Convert a URL to aFile. The URL must use the "file" protocol.- Parameters:
aURL- The URL to convert. May not benull. Must use the "file" protocol.- Returns:
- The corresponding
Fileobject. The file may be non-existing. Nevernull. - Throws:
IllegalArgumentException- if the URL does not use the "file" protocol.
-
getAsFileOrNull
Try to convert a URL to aFile. If the URL isnullor does not use the "file" protocol,nullis returned.- Parameters:
aURL- The URL to convert. May benull.- Returns:
nullif the URL isnullor does not use the "file" protocol.
-
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
Check if a classpath URL exists for the given path.- Parameters:
sPath- The path to be resolved. May neither benullnor empty.- Returns:
trueif the classpath URL exists,falseotherwise.
-
isClassPathURLExisting
public static boolean isClassPathURLExisting(@Nonempty @NonNull @Nonempty String sPath, @NonNull ClassLoader aClassLoader) Check if a classpath URL exists for the given path using the specified class loader.- Parameters:
sPath- The path to be resolved. May neither benullnor empty.aClassLoader- The class loader to use for resolving. May not benull.- Returns:
trueif the classpath URL exists,falseotherwise.
-