Package org.apereo.cas.util
Class ResourceUtils
- java.lang.Object
-
- org.apereo.cas.util.ResourceUtils
-
public class ResourceUtils extends java.lang.Object
Utility class to assist with resource operations.- Since:
- 5.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static org.springframework.core.io.Resource
EMPTY_RESOURCE
Empty resource.
-
Constructor Summary
Constructors Constructor Description ResourceUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.springframework.core.io.InputStreamResource
buildInputStreamResourceFrom(java.lang.String value, java.lang.String description)
Build input stream resource from string value.static boolean
doesResourceExist(java.lang.String location)
Does resource exist?static boolean
doesResourceExist(java.lang.String resource, org.springframework.core.io.ResourceLoader resourceLoader)
Does resource exist?static boolean
doesResourceExist(org.springframework.core.io.Resource res)
Does resource exist?static org.springframework.core.io.Resource
exportClasspathResourceToFile(java.io.File parentDirectory, org.springframework.core.io.Resource resource)
Export classpath resource to file.static org.springframework.core.io.AbstractResource
getRawResourceFrom(java.lang.String location)
Gets resource from a String location.static org.springframework.core.io.AbstractResource
getResourceFrom(java.lang.String location)
Gets resource from a String location.static boolean
isFile(java.lang.String resource)
Is the resource a file?static boolean
isFile(org.springframework.core.io.Resource resource)
Is file boolean.static boolean
isJarResource(org.springframework.core.io.Resource resource)
Is jar resource ?.static boolean
isUrl(java.lang.String resource)
Is url boolean.static org.springframework.core.io.Resource
prepareClasspathResourceIfNeeded(org.springframework.core.io.Resource resource)
Prepare classpath resource if needed file.static org.springframework.core.io.Resource
prepareClasspathResourceIfNeeded(org.springframework.core.io.Resource resource, boolean isDirectory, java.lang.String containsName)
If the provided resource is a classpath resource, running inside an embedded container, and if the container is running in a non-exploded form, classpath resources become non-accessible.
-
-
-
Method Detail
-
getRawResourceFrom
public static org.springframework.core.io.AbstractResource getRawResourceFrom(java.lang.String location) throws java.io.IOException
Gets resource from a String location.- Parameters:
location
- the metadata location- Returns:
- the resource from
- Throws:
java.io.IOException
- the exception
-
doesResourceExist
public static boolean doesResourceExist(java.lang.String resource, org.springframework.core.io.ResourceLoader resourceLoader)
Does resource exist?- Parameters:
resource
- the resourceresourceLoader
- the resource loader- Returns:
- true/false
-
doesResourceExist
public static boolean doesResourceExist(org.springframework.core.io.Resource res)
Does resource exist?On Windows, reading one byte from a directory does not return length greater than zero so an explicit directory check is needed.
- Parameters:
res
- the res- Returns:
- true/false
-
doesResourceExist
public static boolean doesResourceExist(java.lang.String location)
Does resource exist?- Parameters:
location
- the resource- Returns:
- true/false
-
getResourceFrom
public static org.springframework.core.io.AbstractResource getResourceFrom(java.lang.String location) throws java.io.IOException
Gets resource from a String location.- Parameters:
location
- the metadata location- Returns:
- the resource from
- Throws:
java.io.IOException
- the exception
-
exportClasspathResourceToFile
public static org.springframework.core.io.Resource exportClasspathResourceToFile(java.io.File parentDirectory, org.springframework.core.io.Resource resource)
Export classpath resource to file.- Parameters:
parentDirectory
- the parent directoryresource
- the resource- Returns:
- the resource
-
prepareClasspathResourceIfNeeded
public static org.springframework.core.io.Resource prepareClasspathResourceIfNeeded(org.springframework.core.io.Resource resource)
Prepare classpath resource if needed file.- Parameters:
resource
- the resource- Returns:
- the file
-
prepareClasspathResourceIfNeeded
public static org.springframework.core.io.Resource prepareClasspathResourceIfNeeded(org.springframework.core.io.Resource resource, boolean isDirectory, java.lang.String containsName)
If the provided resource is a classpath resource, running inside an embedded container, and if the container is running in a non-exploded form, classpath resources become non-accessible. So, this method will attempt to move resources out of classpath and onto a physical location outside the context, typically in the "cas" directory of the temp system folder.- Parameters:
resource
- the resourceisDirectory
- the if the resource is a directory, in which case entries will be copied over.containsName
- the resource name pattern- Returns:
- the file
-
buildInputStreamResourceFrom
public static org.springframework.core.io.InputStreamResource buildInputStreamResourceFrom(java.lang.String value, java.lang.String description)
Build input stream resource from string value.- Parameters:
value
- the valuedescription
- the description- Returns:
- the input stream resource
-
isFile
public static boolean isFile(java.lang.String resource)
Is the resource a file?- Parameters:
resource
- the resource- Returns:
- true/false
-
isFile
public static boolean isFile(org.springframework.core.io.Resource resource)
Is file boolean.- Parameters:
resource
- the resource- Returns:
- true/false
-
isJarResource
public static boolean isJarResource(org.springframework.core.io.Resource resource)
Is jar resource ?.- Parameters:
resource
- the resource- Returns:
- true/false
-
isUrl
public static boolean isUrl(java.lang.String resource)
Is url boolean.- Parameters:
resource
- the resource- Returns:
- the boolean
-
-