public abstract class AbstractResource extends LockSupport implements Resource
Resource. Subclasses must implement the abstract methods Resource.toURL()
and newResource(String) as well as toString(), hashCode() and equals().| Modifier | Constructor and Description |
|---|---|
protected |
AbstractResource(String path) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
exists()
Simple check for whether
Resource.toURL() returns null or not. |
Resource |
forFile(String relativePath)
Returns a Resource based on a relative path, relative to the folder containing the resource.
|
Resource |
forLocale(Locale locale)
Returns a localized version of the resource.
|
String |
getFile()
Returns the file portion of the Resource path, everything that follows the final forward slash.
|
String |
getFolder()
Returns the portion of the path up to the last forward slash; this is the directory or folder portion of the
Resource.
|
String |
getPath()
Return the path (the combination of folder and file).
|
boolean |
isVirtual()
Returns true if the resource is virtual, meaning this is no underlying file.
|
protected abstract Resource |
newResource(String path)
Factory method provided by subclasses.
|
InputStream |
openStream()
Obtains the URL for the Resource and opens the stream, wrapped by a BufferedInputStream.
|
protected void |
validateURL(URL url)
Validates that the URL is correct; at this time, a correct URL is one of:
null
a non-file: URL
a file: URL where the case of the file matches the corresponding path element
See TAP5-1007
|
Resource |
withExtension(String extension)
Returns a new Resource with the extension changed (or, if the resource does not have an extension, the extension
is added).
|
acquireReadLock, downgradeWriteLockToReadLock, releaseReadLock, releaseWriteLock, takeWriteLock, upgradeReadLockToWriteLockprotected AbstractResource(String path)
public final String getPath()
Resourcepublic final String getFile()
Resourcepublic final String getFolder()
Resourcepublic final Resource forFile(String relativePath)
Resourcepublic final Resource forLocale(Locale locale)
Resourcepublic final Resource withExtension(String extension)
ResourceResource.toURL() may return null.withExtension in interface Resourceextension - to apply to the resource, such as "html" or "properties"public boolean exists()
Resource.toURL() returns null or not.public InputStream openStream() throws IOException
openStream in interface ResourceIOExceptionprotected abstract Resource newResource(String path)
protected void validateURL(URL url)
url - to validatepublic boolean isVirtual()
ResourceResource.toURL(), Resource.forLocale(java.util.Locale),
Resource.withExtension(String), Resource.getFile(), Resource.getFolder(), Resource.getPath()}; these
operations will throw an UnsupportedOperationException.5.6.4 - Copyright © 2003-2021 The Apache Software Foundation.