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, upgradeReadLockToWriteLock
protected AbstractResource(String path)
public final String getPath()
Resource
public final String getFile()
Resource
public final String getFolder()
Resource
public final Resource forFile(String relativePath)
Resource
public final Resource forLocale(Locale locale)
Resource
public final Resource withExtension(String extension)
Resource
Resource.toURL()
may return null.withExtension
in interface Resource
extension
- 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 Resource
IOException
protected abstract Resource newResource(String path)
protected void validateURL(URL url)
url
- to validatepublic boolean isVirtual()
Resource
Resource.toURL()
, Resource.forLocale(java.util.Locale)
,
Resource.withExtension(String)
, Resource.getFile()
, Resource.getFolder()
, Resource.getPath()
}; these
operations will throw an UnsupportedOperationException
.${project.version} - Copyright © 2003-2015 The Apache Software Foundation.