Package org.goplanit.utils.misc
Class UrlUtils
- java.lang.Object
-
- org.goplanit.utils.misc.UrlUtils
-
public class UrlUtils extends Object
Utilities to deal with Java URL instances- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description static String
PROTOCOL_FILE
file protocol string
-
Constructor Summary
Constructors Constructor Description UrlUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static URL
appendRelativePathToURL(URL baseUrl, String relativePath)
Append the given relative path to the URL.static Path
asLocalPath(URL url)
converts to a Path.static URL
createFrom(String path)
Construct a URL based on a given a location either local or notstatic URL
createFromLocalPath(String path)
Construct a URL based on a given local file locationstatic URL
createFromLocalPath(Path path)
Construct a URL based on a given (local) pathstatic URL
createFromLocalPathOrResource(String path)
Construct a URL based on a given (local) pathstatic URL
createFromLocalPathOrResource(Path path)
Construct a URL based on a given (local) pathstatic boolean
hasHost(URL url)
Verify if the URL has a host specifiedstatic boolean
isLocal(URL url)
Test if URL is local, i.e.static boolean
isLocalDirectory(URL url)
Test if URL is a local filestatic boolean
isLocalFile(URL url)
Test if URL is a local filestatic boolean
isLocalZipFile(URL url)
Test if URL is a local file
-
-
-
Field Detail
-
PROTOCOL_FILE
public static final String PROTOCOL_FILE
file protocol string- See Also:
- Constant Field Values
-
-
Method Detail
-
isLocal
public static boolean isLocal(URL url)
Test if URL is local, i.e. a local file or directory- Parameters:
url
- to verify- Returns:
- true when local, false otherwise
-
isLocalFile
public static boolean isLocalFile(URL url)
Test if URL is a local file- Parameters:
url
- to verify- Returns:
- true when local, false otherwise
-
isLocalDirectory
public static boolean isLocalDirectory(URL url)
Test if URL is a local file- Parameters:
url
- to verify- Returns:
- true when local, false otherwise
-
isLocalZipFile
public static boolean isLocalZipFile(URL url)
Test if URL is a local file- Parameters:
url
- to verify- Returns:
- true when local, false otherwise
-
hasHost
public static boolean hasHost(URL url)
Verify if the URL has a host specified- Parameters:
url
- to check- Returns:
- true when host present, false otherwise
-
createFrom
public static URL createFrom(String path)
Construct a URL based on a given a location either local or not- Parameters:
path
- to convert- Returns:
- URL representation
-
createFromLocalPath
public static URL createFromLocalPath(String path)
Construct a URL based on a given local file location- Parameters:
path
- to convert- Returns:
- URL representation
-
createFromLocalPath
public static URL createFromLocalPath(Path path)
Construct a URL based on a given (local) path- Parameters:
path
- to convert- Returns:
- URL representation
-
createFromLocalPathOrResource
public static URL createFromLocalPathOrResource(String path)
Construct a URL based on a given (local) path- Parameters:
path
- to convert- Returns:
- URL representation
-
createFromLocalPathOrResource
public static URL createFromLocalPathOrResource(Path path)
Construct a URL based on a given (local) path- Parameters:
path
- to convert- Returns:
- URL representation
-
appendRelativePathToURL
public static URL appendRelativePathToURL(URL baseUrl, String relativePath)
Append the given relative path to the URL. Implementation based on answer by Martin Senne via https://stackoverflow.com/questions/7498030/append-relative-url-to-java-net-url- Parameters:
baseUrl
- base urlrelativePath
- to append- Returns:
- combined URL
-
asLocalPath
public static Path asLocalPath(URL url)
converts to a Path. Has the benefit compared to using getPath() on the URL directly that this removes the preceding slash for local files, e.g. instead of getting "/C:/something" we obtain "C:/something" which can be used directly as a local path or file etc.- Parameters:
url
- to convert to path- Returns:
- created path, null if not possible
-
-