Package org.goplanit.utils.resource
Class ResourceUtils
- java.lang.Object
-
- org.goplanit.utils.resource.ResourceUtils
-
public class ResourceUtils extends Object
Utilities to access resources in the Java environment- Author:
- markr
-
-
Constructor Summary
Constructors Constructor Description ResourceUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FileSystem
getJarFileSystem(URI uri)
Collect the jar as a FileSystem to access its internalsstatic InputStream
getResourceAsInputStream(URI uri)
Collect a resource input stream, which is either file based or not depending whether or not the resource is located in a jar or notstatic InputStreamReader
getResourceAsInputStreamReader(URI uri)
Collect a resource input stream reader, which is either file based or not depending whether or not the resource is located in a jar or notstatic InputStream
getResourceAsStream(String resourceLocation)
Collect a resource as a stream based on provided locationstatic URI
getResourceUri(String resourceLocation)
find the resource URI via this class' class loaderstatic URL
getResourceUrl(String resourceLocation)
find the resource URL via this class' classloader.static URL
getResourceUrl(Path resourceLocation)
find the resource URL via this class' classloader.
-
-
-
Method Detail
-
getResourceUrl
public static URL getResourceUrl(String resourceLocation)
find the resource URL via this class' classloader. The resource location is expected to be a (relative) path with forward slashes. If the provided path contains backward slashes, these will be replaced to avoid issues- Parameters:
resourceLocation
- to find URL for- Returns:
- the URL of the resource
-
getResourceUrl
public static URL getResourceUrl(Path resourceLocation)
find the resource URL via this class' classloader. The resource location is expected to be a (relative) path with forward slashes. If the provided path contains backward slashes, these will be replaced to avoid issues- Parameters:
resourceLocation
- to find URL for- Returns:
- the URL of the resource
-
getResourceUri
public static URI getResourceUri(String resourceLocation)
find the resource URI via this class' class loader- Parameters:
resourceLocation
- to find URI for- Returns:
- the URI of the resource
-
getJarFileSystem
public static FileSystem getJarFileSystem(URI uri) throws IOException
Collect the jar as a FileSystem to access its internals- Parameters:
uri
- to use- Returns:
- FileSystem of Jar
- Throws:
IOException
- thrown if error
-
getResourceAsStream
public static InputStream getResourceAsStream(String resourceLocation)
Collect a resource as a stream based on provided location- Parameters:
resourceLocation
- to use- Returns:
- input stream
-
getResourceAsInputStreamReader
public static InputStreamReader getResourceAsInputStreamReader(URI uri)
Collect a resource input stream reader, which is either file based or not depending whether or not the resource is located in a jar or not- Parameters:
uri
- to deduce whether or not this resource resides within a jar or not, which drives the type of input reader that is to be created, if null we attempt to create it using the resourceLocation- Returns:
- input stream reader created, or null if something happened
-
getResourceAsInputStream
public static InputStream getResourceAsInputStream(URI uri)
Collect a resource input stream, which is either file based or not depending whether or not the resource is located in a jar or not- Parameters:
uri
- to deduce whether or not this resource resides within a jar or not, which drives the type of input reader that is to be created, if null we attempt to create it using the resourceLocation- Returns:
- input stream reader created, or null if something happened
-
-