Class ClassPathResource
java.lang.Object
nl.basjes.parse.useragent.utils.springframework.core.io.AbstractResource
nl.basjes.parse.useragent.utils.springframework.core.io.AbstractFileResolvingResource
nl.basjes.parse.useragent.utils.springframework.core.io.ClassPathResource
- All Implemented Interfaces:
InputStreamSource
,Resource
- Direct Known Subclasses:
DefaultResourceLoader.ClassPathContextResource
{link Resource} implementation for class path resources. Uses either a
given {link ClassLoader} or a given {link 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.
- Since:
- 28.12.2003
- Author:
- Juergen Hoeller, Sam Brannen see ClassLoader#getResourceAsStream(String) see Class#getResourceAsStream(String)
-
Constructor Summary
ConstructorDescriptionClassPathResource
(String path, Class<?> clazz) Create a newClassPathResource
forClass
usage.ClassPathResource
(String path, ClassLoader classLoader) Create a newClassPathResource
forClassLoader
usage. -
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.boolean
This implementation compares the underlying class path locations.boolean
exists()
This implementation checks for the resolution of a resource URL.final ClassLoader
Return the ClassLoader that this resource will be obtained from.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 String
getPath()
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, if available.int
hashCode()
This implementation returns the hash code of the underlying class path location.protected URL
Resolves a URL for the underlying class path resource.Methods inherited from class nl.basjes.parse.useragent.utils.springframework.core.io.AbstractFileResolvingResource
contentLength, customizeConnection, customizeConnection, getFile, getFile, isFile, isFile
Methods inherited from class nl.basjes.parse.useragent.utils.springframework.core.io.AbstractResource
getURI, isOpen, toString
-
Constructor Details
-
ClassPathResource
Create a newClassPathResource
forClassLoader
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, ornull
for the thread context class loader see ClassLoader#getResourceAsStream(String)
-
ClassPathResource
Create a newClassPathResource
forClass
usage. The path can be relative to the given class, or absolute within the classpath via a leading slash.- Parameters:
path
- relative or absolute path within the class pathclazz
- the class to load resources with see java.lang.Class#getResourceAsStream
-
-
Method Details
-
getPath
Return the path for this resource (as resource path within the class path). -
getClassLoader
Return the ClassLoader that this resource will be obtained from. -
exists
public boolean exists()This implementation checks for the resolution of a resource URL. see java.lang.ClassLoader#getResource(String) see java.lang.Class#getResource(String)- Specified by:
exists
in interfaceResource
- Overrides:
exists
in classAbstractFileResolvingResource
-
resolveURL
Resolves a URL for the underlying class path resource.- Returns:
- the resolved URL, or
null
if not resolvable
-
getInputStream
This implementation opens an InputStream for the given class path resource. see java.lang.ClassLoader#getResourceAsStream(String) see java.lang.Class#getResourceAsStream(String)- Returns:
- the input stream for the underlying resource (must not be
null
) - Throws:
FileNotFoundException
- if the underlying resource does not existIOException
- if the content stream could not be opened see Resource#isReadable()
-
getURL
This implementation returns a URL for the underlying class path resource, if available. see java.lang.ClassLoader#getResource(String) see java.lang.Class#getResource(String)- Specified by:
getURL
in interfaceResource
- Overrides:
getURL
in classAbstractResource
- Throws:
IOException
- if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor
-
createRelative
This implementation creates a ClassPathResource, applying the given path relative to the path of the underlying resource of this descriptor. see org.springframework.util.StringUtils#applyRelativePath(String, String)- Specified by:
createRelative
in interfaceResource
- Overrides:
createRelative
in classAbstractResource
- Parameters:
relativePath
- the relative path (relative to this resource)- Returns:
- the resource handle for the relative resource
-
getFilename
This implementation returns the name of the file that this class path resource refers to. see org.springframework.util.StringUtils#getFilename(String)- Specified by:
getFilename
in interfaceResource
- Overrides:
getFilename
in classAbstractResource
-
getDescription
This implementation returns a description that includes the class path location. -
equals
This implementation compares the underlying class path locations.- Overrides:
equals
in classAbstractResource
-
hashCode
public int hashCode()This implementation returns the hash code of the underlying class path location.- Overrides:
hashCode
in classAbstractResource
-