@NotThreadSafe public class ClassPathResource extends Object implements IReadableResource, IHasClassLoader
| Modifier and Type | Field and Description |
|---|---|
static String |
CLASSPATH_PREFIX_LONG
Use this prefix to uniquely identify classpath resources
|
static String |
CLASSPATH_PREFIX_SHORT
Use this prefix to uniquely identify classpath resources - alternative
|
| Constructor and Description |
|---|
ClassPathResource(String sPath)
Create a new class path resource, using the specified path.
|
ClassPathResource(String sPath,
ClassLoader aClassLoader)
Create a new class path resource using the specified path and class loader
(optional).
|
ClassPathResource(URL aURL)
Create a new class path resource, using the specified URL.
|
ClassPathResource(URL aURL,
ClassLoader aClassLoader)
Create a new class path resource using the specified URL and class loader
(optional).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canRead() |
boolean |
canReadNoCache(ClassLoader aClassLoader) |
boolean |
equals(Object o) |
boolean |
exists() |
boolean |
existsNoCacheUsage() |
File |
getAsFile() |
static File |
getAsFile(String sPath)
Get the file for the specified path using automatic class loader handling.
|
static File |
getAsFile(String sPath,
ClassLoader aClassLoader) |
File |
getAsFileNoCache(ClassLoader aClassLoader) |
URL |
getAsURL() |
URL |
getAsURLNoCache(ClassLoader aClassLoader)
Convert the path to a URL without using caching.
|
ClassLoader |
getClassLoader() |
InputStream |
getInputStream()
Get the input stream for the specified path using automatic class loader
handling.
|
static InputStream |
getInputStream(String sPath)
Get the input stream for the specified path using automatic class loader
handling.
|
static InputStream |
getInputStream(String sPath,
ClassLoader aClassLoader)
Get the input stream of the passed resource using the specified class
loader only.
|
InputStream |
getInputStreamNoCache(ClassLoader aClassLoader)
Get the input stream to the this resource, using the passed class loader
only.
|
String |
getPath() |
ClassPathResource |
getReadableCloneForPath(String sPath)
Get a new resource of the same implementation type as this object but for a
different path.
|
Reader |
getReaderNoCache(ClassLoader aClassLoader,
Charset aCharset)
Create a
Reader of this resource, using the specified class loader
only. |
String |
getResourceID() |
static String |
getWithoutClassPathPrefix(String sPath)
Remove any leading explicit classpath resource prefixes.
|
int |
hashCode() |
static boolean |
isExplicitClassPathResource(String sName)
Check if the passed resource name is an explicit classpath resource.
|
boolean |
isReadMultiple()
Check if the
InputStream from IHasInputStream.getInputStream() can be
acquired more than once. |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitgetReaderhasClassLoaderpublic static final String CLASSPATH_PREFIX_LONG
public static final String CLASSPATH_PREFIX_SHORT
public ClassPathResource(@Nonnull URL aURL)
aURL - The URL to be used. May not be null.public ClassPathResource(@Nonnull URL aURL, @Nullable ClassLoader aClassLoader)
aURL - The URL to be used. May not be null.aClassLoader - The class loader to use. May be null indicating that
automatic class loader handling should be applied.public ClassPathResource(@Nonnull @Nonempty String sPath)
sPath - The path to be used. May neither be null nor empty.public ClassPathResource(@Nonnull @Nonempty String sPath, @Nullable ClassLoader aClassLoader)
sPath - The path to be used. May neither be null nor empty.aClassLoader - The class loader to use. May be null indicating that
automatic class loader handling should be applied.@Nullable public static String getWithoutClassPathPrefix(@Nullable String sPath)
sPath - The source path to strip the class path prefixes from. May be
null.null if the parameter was null.CLASSPATH_PREFIX_LONG,
CLASSPATH_PREFIX_SHORTpublic static boolean isExplicitClassPathResource(@Nullable String sName)
CLASSPATH_PREFIX_LONG
or CLASSPATH_PREFIX_SHORT.sName - The name to check. May be null.true if the passed name is not null and
an explicit classpath resource.@Nullable public ClassLoader getClassLoader()
getClassLoader in interface IHasClassLoadernull.@Nonnull public String getResourceID()
getResourceID in interface IResourceBasenull resource ID used e.g. for system IDs in XML
resolving.@Nonnull @Nonempty public String getPath()
getPath in interface IResourceBasenull@Nullable public static InputStream getInputStream(@Nonnull @Nonempty String sPath)
sPath - The path to be resolved. May neither be null nor empty.null if the path could not be resolved.@Nullable public static InputStream getInputStream(@Nonnull @Nonempty String sPath, @Nonnull ClassLoader aClassLoader)
sPath - The path to be resolved. May neither be null nor empty.aClassLoader - The class loader to be used. May not be null.null if the path could not be resolved using the
specified class loader.@Nullable public InputStream getInputStream()
getInputStream in interface IHasInputStreamnull if no such resource exists.public final boolean isReadMultiple()
IHasInputStreamInputStream from IHasInputStream.getInputStream() can be
acquired more than once.isReadMultiple in interface IHasInputStreamtrue if the input stream can be acquired more than
once, false if not.@Nullable public InputStream getInputStreamNoCache(@Nonnull ClassLoader aClassLoader)
aClassLoader - The class loader to be used. May not be null.null if the path could not be resolved.@Nullable public Reader getReaderNoCache(@Nonnull ClassLoader aClassLoader, @Nonnull Charset aCharset)
Reader of this resource, using the specified class loader
only.aClassLoader - The class loader to be used. May not be null.aCharset - The charset to be used for the Reader. May not be
null.null if the path could not be resolved.public boolean exists()
exists in interface IResourceBasetrue if the resource exists, false
otherwise.public boolean existsNoCacheUsage()
@Nullable public URL getAsURL()
getAsURL in interface IResourceBasenull
if this resource cannot be represented as an URL.@Nullable public URL getAsURLNoCache(@Nonnull ClassLoader aClassLoader)
getAsURL() using the constructor supplied class loader would
possibly contradict with this resolution.aClassLoader - The class loader to be used. May not be null.null if the path could not be resolved to a URL@Nullable public static File getAsFile(@Nonnull @Nonempty String sPath)
sPath - The path to be resolved. May neither be null nor empty.null if the path could not be resolved.@Nullable public static File getAsFile(@Nonnull @Nonempty String sPath, @Nonnull ClassLoader aClassLoader)
@Nullable public File getAsFile()
getAsFile in interface IResourceBasenull
if this resource cannot be represented as a file.@Nullable public File getAsFileNoCache(@Nonnull ClassLoader aClassLoader)
public boolean canRead()
public boolean canReadNoCache(@Nonnull ClassLoader aClassLoader)
@Nonnull public ClassPathResource getReadableCloneForPath(@Nonnull String sPath)
IReadableResourcegetReadableCloneForPath in interface IReadableResourcesPath - The new path to use. May not be null.null.Copyright © 2014–2017 Philip Helger. All rights reserved.