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 StringPROTOCOL_FILEfile protocol string
-
Constructor Summary
Constructors Constructor Description UrlUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static URLappendRelativePathToURL(URL baseUrl, String relativePath)Append the given relative path to the URL.static PathasLocalPath(URL url)converts to a Path.static URLcreateFromPath(String path)Construct a URL based on a given local file locationstatic URLcreateFromPath(Path path)Construct a URL based no a given pathstatic booleanhasHost(URL url)Verify if the URL has a host specifiedstatic booleanisLocal(URL url)Test if URL is local, i.e.static booleanisLocalDirectory(URL url)Test if URL is a local filestatic booleanisLocalFile(URL url)Test if URL is a local filestatic booleanisLocalZipFile(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
-
createFromPath
public static URL createFromPath(String path)
Construct a URL based on a given local file location- Parameters:
path- to convert- Returns:
- URL representation
-
createFromPath
public static URL createFromPath(Path path)
Construct a URL based no a given 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
-
-