Package spark.resource
Class ClassPathResource
java.lang.Object
spark.resource.AbstractResource
spark.resource.AbstractFileResolvingResource
spark.resource.ClassPathResource
- All Implemented Interfaces:
InputStreamResource,Resource
Resource implementation for class path resources.
Uses either a given ClassLoader or a given Class for loading resources.
Supports resolution as java.io.File if the class path
resource resides in the file system, but not for resources in a JAR.
Always supports resolution as URL.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionClassPathResource(String path) Create a new ClassPathResource for ClassLoader usage.ClassPathResource(String path, ClassLoader classLoader) Create a new ClassPathResource for ClassLoader usage.protectedClassPathResource(String path, ClassLoader classLoader, Class<?> clazz) Create a new ClassPathResource with optional ClassLoader and Class. -
Method Summary
Modifier and TypeMethodDescriptioncreateRelative(String relativePath) This implementation creates a ClassPathResource, applying the given path relative to the path of the underlying resource of this descriptor.booleanThis implementation compares the underlying class path locations.booleanexists()This implementation checks for the resolution of a resource URL.This implementation returns a description that includes the class path location.This implementation returns the name of the file that this class path resource refers to.This implementation opens an InputStream for the given class path resource.final StringgetPath()Return the path for this resource (as resource path within the class path).getURL()This implementation returns a URL for the underlying class path resource.inthashCode()This implementation returns the hash code of the underlying class path location.private static booleanisInvalidPath(String path) private static booleanMethods inherited from class spark.resource.AbstractFileResolvingResource
contentLength, customizeConnection, customizeConnection, getFile, getFileForLastModifiedCheck, isReadable, lastModifiedMethods inherited from class spark.resource.AbstractResource
getURI, isOpen, toString
-
Field Details
-
path
-
classLoader
-
clazz
-
-
Constructor Details
-
ClassPathResource
Create a new ClassPathResource for ClassLoader usage. A leading slash will be removed, as the ClassLoader resource access methods will not accept it.The thread context class loader will be used for loading the resource.
- Parameters:
path- the absolute path within the class path- See Also:
-
ClassPathResource
Create a new ClassPathResource for ClassLoader usage. A leading slash will be removed, as the ClassLoader resource access methods will not accept it.- Parameters:
path- the absolute path within the classpathclassLoader- the class loader to load the resource with, ornullfor the thread context class loader- See Also:
-
ClassPathResource
Create a new ClassPathResource with optional ClassLoader and Class. Only for internal usage.- Parameters:
path- relative or absolute path within the classpathclassLoader- the class loader to load the resource with, if anyclazz- the class to load resources with, if any
-
-
Method Details
-
isValid
-
isInvalidPath
-
getPath
Return the path for this resource (as resource path within the class path).- Returns:
- the path
-
exists
public boolean exists()This implementation checks for the resolution of a resource URL.- Specified by:
existsin interfaceResource- Overrides:
existsin classAbstractFileResolvingResource- Returns:
- if exists.
- See Also:
-
getInputStream
This implementation opens an InputStream for the given class path resource.- Returns:
- the input stream.
- Throws:
IOException- if the stream could not be opened- See Also:
-
getURL
This implementation returns a URL for the underlying class path resource.- Specified by:
getURLin interfaceResource- Overrides:
getURLin classAbstractResource- Returns:
- the url.
- Throws:
IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor- See Also:
-
createRelative
This implementation creates a ClassPathResource, applying the given path relative to the path of the underlying resource of this descriptor.- Specified by:
createRelativein interfaceResource- Overrides:
createRelativein classAbstractResource- Parameters:
relativePath- the relative path (relative to this resource)- Returns:
- the resource.
- See Also:
-
getFilename
This implementation returns the name of the file that this class path resource refers to.- Specified by:
getFilenamein interfaceResource- Overrides:
getFilenamein classAbstractResource- Returns:
- the file name.
- See Also:
-
getDescription
This implementation returns a description that includes the class path location.- Returns:
- the description.
- See Also:
-
equals
This implementation compares the underlying class path locations.- Overrides:
equalsin classAbstractResource- Returns:
- if equals.
- See Also:
-
hashCode
public int hashCode()This implementation returns the hash code of the underlying class path location.- Overrides:
hashCodein classAbstractResource- Returns:
- the hash code.
- See Also:
-