public abstract class ResourceSupport extends Object implements Resource
ATTRIBUTE_ARCHIVE, ATTRIBUTE_HIDDEN, ATTRIBUTE_SYSTEM
Constructor and Description |
---|
ResourceSupport() |
Modifier and Type | Method and Description |
---|---|
boolean |
canRead()
Tests whether the application can read the resource denoted by this
abstract pathname.
|
boolean |
canWrite()
Tests whether the application can modify the resource denoted by this
abstract pathname.
|
void |
copyFrom(Resource res,
boolean append)
copy data of given resource to current
|
void |
copyTo(Resource res,
boolean append)
copy current resource data to given resource
|
boolean |
createNewFile()
Creates a new, empty file named by this abstract pathname if
and only if a file with this name does not yet exist.
|
boolean |
delete()
Deletes the resource denoted by this abstract pathname.
|
boolean |
equals(Object obj) |
String |
getAbsolutePath()
Returns the absolute pathname string of this abstract pathname.
|
Resource |
getAbsoluteResource()
Returns the absolute form of this abstract pathname.
|
boolean |
getAttribute(short attribute)
return value of a specific attribute
|
String |
getCanonicalPath()
Returns the canonical pathname string of this abstract pathname.
|
Resource |
getCanonicalResource()
Returns the canonical form of this abstract pathname.
|
OutputStream |
getOutputStream() |
String |
getReal(String relpath)
returns a resource path that is relative to the current resource
|
boolean |
isArchive()
Tests whether the resource named by this abstract pathname is a archive
resource.
|
boolean |
isHidden()
Tests whether the resource named by this abstract pathname is a hidden
resource.
|
boolean |
isSystem()
Tests whether the resource named by this abstract pathname is a system
resource.
|
String[] |
list()
Returns an array of strings naming the files and directories in the
directory denoted by this abstract pathname.
|
String[] |
list(ResourceFilter filter) |
String[] |
list(ResourceNameFilter filter)
Returns an array of strings naming the files and directories in the
directory denoted by this abstract pathname that satisfy the specified
filter.
|
Resource[] |
listResources(ResourceFilter filter)
Returns an array of abstract pathnames denoting the files and
directories in the directory denoted by this abstract pathname that
satisfy the specified filter.
|
Resource[] |
listResources(ResourceNameFilter filter)
Returns an array of abstract pathnames denoting the files and
directories in the directory denoted by this abstract pathname that
satisfy the specified filter.
|
boolean |
mkdir()
Creates the directory named by this abstract pathname.
|
boolean |
mkdirs()
Creates the directory named by this abstract pathname, including any
necessary but nonexistent parent directories.
|
void |
moveTo(Resource dest)
Move/renames the file denoted by this abstract pathname.
|
boolean |
renameTo(Resource dest)
Move/renames the file denoted by this abstract pathname.
|
void |
setArchive(boolean value)
sets archive attribute of the resource
|
void |
setAttribute(short attribute,
boolean value)
sets a attribute on the resource if supported otherwise it will ign
|
void |
setHidden(boolean value)
sets hidden attribute of the resource
|
boolean |
setReadOnly()
Marks the file or directory named by this abstract pathname so that
only read operations are allowed.
|
void |
setSystem(boolean value)
sets system attribute of the resource
|
String |
toString() |
getClass, hashCode, notify, notifyAll, wait, wait, wait
createDirectory, createFile, exists, getInputStream, getMode, getName, getOutputStream, getParent, getParentResource, getPath, getRealResource, getResourceProvider, isAbsolute, isDirectory, isFile, isReadable, isWriteable, lastModified, length, listResources, remove, setLastModified, setMode, setReadable, setWritable
public ResourceSupport()
public void copyFrom(Resource res, boolean append) throws IOException
Resource
copyFrom
in interface Resource
IOException
public void copyTo(Resource res, boolean append) throws IOException
Resource
copyTo
in interface Resource
IOException
public Resource getAbsoluteResource()
Resource
getAbsoluteResource
in interface Resource
public String getAbsolutePath()
Resource
If this abstract pathname is already absolute, then the pathname
string is simply returned as if by the
method.Resource.getPath()
getAbsolutePath
in interface Resource
public OutputStream getOutputStream() throws IOException
getOutputStream
in interface Resource
IOException
public Resource getCanonicalResource() throws IOException
Resource
getCanonicalResource
in interface Resource
IOException
- If an I/O error occurs, which is possible because the
construction of the canonical pathname may require
filesystem queriespublic String getCanonicalPath() throws IOException
Resource
A canonical pathname is both absolute and unique. The precise
definition of canonical form is system-dependent. This method first
converts this pathname to absolute form if necessary, as if by invoking the
Resource.getAbsolutePath()
method, and then maps it to its unique form in a
system-dependent way. This typically involves removing redundant names
such as "." and ".." from the pathname.
Every pathname that denotes an existing file or directory has a unique canonical form. Every pathname that denotes a nonexistent resource also has a unique canonical form. The canonical form of the pathname of a nonexistent file or directory may be different from the canonical form of the same pathname after the resource is created. Similarly, the canonical form of the pathname of an existing resource may be different from the canonical form of the same pathname after the resource is deleted.
getCanonicalPath
in interface Resource
IOException
- If an I/O error occurs, which is possible because the
construction of the canonical pathname may require
filesystem queriespublic void moveTo(Resource dest) throws IOException
Resource
Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists.
moveTo
in interface Resource
dest
- The new abstract pathname for the named fileIOException
- throwed when operation not done sucessfullpublic String[] list(ResourceFilter filter)
public String[] list(ResourceNameFilter filter)
Resource
Resource.list()
method, except that the strings in the
returned array must satisfy the filter. If the given
filter
is null
then all names are accepted.
Otherwise, a name satisfies the filter if and only if the value
true
results when the ResourceNameFilter.accept(lucee.commons.io.res.Resource, java.lang.String)
method of the filter is invoked on this
abstract pathname and the name of a file or directory in the directory
that it denotes.list
in interface Resource
filter
- A resourcename filterfilter
. The array will be empty if
the directory is empty or if no names were accepted by the
filter. Returns null
if this abstract pathname
does not denote a directory, or if an I/O error occurs.public Resource[] listResources(ResourceNameFilter filter)
Resource
Resource.listResources()
method, except
that the pathnames in the returned array must satisfy the filter.
If the given filter
is null
then all
pathnames are accepted. Otherwise, a pathname satisfies the filter
if and only if the value true
results when the
ResourceNameFilter.accept(lucee.commons.io.res.Resource, java.lang.String)
method of the filter is
invoked on this abstract pathname and the name of a file or
directory in the directory that it denotes.listResources
in interface Resource
filter
- A resourcename filternull
if this abstract pathname
does not denote a directory, or if an I/O error occurs.public Resource[] listResources(ResourceFilter filter)
Resource
Resource.listResources()
method, except
that the pathnames in the returned array must satisfy the filter.
If the given filter
is null
then all
pathnames are accepted. Otherwise, a pathname satisfies the filter
if and only if the value true
results when the
ResourceFilter.accept(Resource)
method of
the filter is invoked on the pathname.listResources
in interface Resource
filter
- A resource filternull
if this abstract pathname
does not denote a directory, or if an I/O error occurs.public String getReal(String relpath)
Resource
public String[] list()
Resource
If this abstract pathname does not denote a directory, then this
method returns null
. Otherwise an array of strings is
returned, one for each file or directory in the directory. Names
denoting the directory itself and the directory's parent directory are
not included in the result. Each string is a file name rather than a
complete path.
There is no guarantee that the name strings in the resulting array will appear in any specific order; they are not, in particular, guaranteed to appear in alphabetical order.
public boolean canRead()
Resource
public boolean canWrite()
Resource
public boolean renameTo(Resource dest)
Resource
Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists.
public boolean createNewFile()
Resource
createNewFile
in interface Resource
true
if the named file does not exist and was
successfully created; false
if the named file
already existspublic boolean mkdir()
Resource
public boolean mkdirs()
Resource
public boolean delete()
Resource
public boolean isArchive()
Resource
public boolean isSystem()
Resource
public boolean isHidden()
Resource
public void setArchive(boolean value) throws IOException
Resource
setArchive
in interface Resource
IOException
- throwed when no access to change the value or the resource doesn't existspublic void setHidden(boolean value) throws IOException
Resource
setHidden
in interface Resource
IOException
- throwed when no access to change the value or the resource doesn't existspublic boolean setReadOnly()
Resource
setReadOnly
in interface Resource
true
if and only if the operation succeeded;
false
otherwisepublic void setSystem(boolean value) throws IOException
Resource
setSystem
in interface Resource
IOException
- throwed when no access to change the value or the resource doesn't existspublic boolean getAttribute(short attribute)
Resource
getAttribute
in interface Resource
public void setAttribute(short attribute, boolean value) throws IOException
Resource
setAttribute
in interface Resource
attribute
- wich attrbute (Resource.ATTRIBUTE_*)IOException
- throwed when no access to change the value,
when attributes are not supported or
the resource doesn't existsCopyright © 2015 Lucee