Interface Resource
-
- All Superinterfaces:
java.io.Serializable
public interface Resource extends java.io.Serializable
a Resource handle connection to different resources in an abstract form
-
-
Field Summary
Fields Modifier and Type Field Description static short
ATTRIBUTE_ARCHIVE
static short
ATTRIBUTE_HIDDEN
static short
ATTRIBUTE_SYSTEM
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description boolean
canRead()
Deprecated.use instead#isReadable()
boolean
canWrite()
Deprecated.use instead#isWriteable()
void
copyFrom(Resource res, boolean append)
copy data of given resource to currentvoid
copyTo(Resource res, boolean append)
copy current resource data to given resourcevoid
createDirectory(boolean createParentWhenNotExists)
Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories if flag "createParentWhenNotExists" is set to true.void
createFile(boolean createParentWhenNotExists)
Creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist.boolean
createNewFile()
Deprecated.use instead#createFile(boolean)
boolean
delete()
Deprecated.replaced with method remove(boolean)boolean
exists()
Tests whether the resource denoted by this abstract pathname exists.java.lang.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 attributejava.lang.String
getCanonicalPath()
Returns the canonical pathname string of this abstract pathname.Resource
getCanonicalResource()
Returns the canonical form of this abstract pathname.java.io.InputStream
getInputStream()
int
getMode()
java.lang.String
getName()
Returns the name of the resource denoted by this abstract pathname.java.io.OutputStream
getOutputStream()
java.io.OutputStream
getOutputStream(boolean append)
java.lang.String
getParent()
Returns the pathname string of this abstract pathname's parent, ornull
if this pathname does not name a parent directory.Resource
getParentResource()
Returns the abstract pathname of this abstract pathname's parent, ornull
if this pathname does not name a parent directory.java.lang.String
getPath()
Converts this abstract pathname into a pathname string.java.lang.String
getReal(java.lang.String realpath)
returns a resource path that is relative to the current resourceResource
getRealResource(java.lang.String relpath)
returns a resource that is relative to the current resourceResourceProvider
getResourceProvider()
boolean
isAbsolute()
Tests whether this abstract pathname is absolute.boolean
isArchive()
Deprecated.use insteadgetAttribute(short)
boolean
isDirectory()
Tests whether the resource denoted by this abstract pathname is a directory.boolean
isFile()
Tests whether the file denoted by this abstract pathname is a normal file.boolean
isHidden()
Deprecated.use insteadgetAttribute(short)
boolean
isReadable()
Tests whether the application can read the resource denoted by this abstract pathname.boolean
isSystem()
Deprecated.use insteadgetAttribute(short)
boolean
isWriteable()
Tests whether the application can modify the resource denoted by this abstract pathname.long
lastModified()
Returns the time that the resource denoted by this abstract pathname was last modified.long
length()
Returns the length of the resource denoted by this abstract pathname.java.lang.String[]
list()
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.java.lang.String[]
list(ResourceFilter filter)
java.lang.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()
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.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()
Deprecated.use#createDirectory(boolean)
boolean
mkdirs()
Deprecated.use#createDirectory(boolean)
void
moveTo(Resource dest)
Move/renames the file denoted by this abstract pathname.void
remove(boolean force)
Deletes the resource denoted by this abstract pathname.boolean
renameTo(Resource dest)
Deprecated.use instead#moveTo(Resource)
void
setArchive(boolean value)
Deprecated.use insteadsetAttribute(short, boolean)
void
setAttribute(short attribute, boolean value)
sets an attribute on the resource if supported otherwise it will ignvoid
setHidden(boolean value)
Deprecated.use insteadsetAttribute(short, boolean)
boolean
setLastModified(long time)
Sets the last-modified time of the file or directory named by this abstract pathname.void
setMode(int mode)
boolean
setReadable(boolean readable)
boolean
setReadOnly()
Deprecated.use insteadsetWritable(boolean)
void
setSystem(boolean value)
Deprecated.use insteadsetAttribute(short, boolean)
boolean
setWritable(boolean writable)
-
-
-
Field Detail
-
ATTRIBUTE_HIDDEN
static final short ATTRIBUTE_HIDDEN
- See Also:
- Constant Field Values
-
ATTRIBUTE_SYSTEM
static final short ATTRIBUTE_SYSTEM
- See Also:
- Constant Field Values
-
ATTRIBUTE_ARCHIVE
static final short ATTRIBUTE_ARCHIVE
- See Also:
- Constant Field Values
-
-
Method Detail
-
isReadable
boolean isReadable()
Tests whether the application can read the resource denoted by this abstract pathname.- Returns:
true
if and only if the resource specified by this abstract pathname exists and can be read by the application;false
otherwise
-
canRead
@Deprecated boolean canRead()
Deprecated.use instead#isReadable()
Tests whether the application can read the resource denoted by this abstract pathname.- Returns:
true
if and only if the resource specified by this abstract pathname exists and can be read by the application;false
otherwise
-
isWriteable
boolean isWriteable()
Tests whether the application can modify the resource denoted by this abstract pathname.- Returns:
true
if and only if the resource system actually contains a resource denoted by this abstract pathname and the application is allowed to write to the resource;false
otherwise.
-
canWrite
@Deprecated boolean canWrite()
Deprecated.use instead#isWriteable()
Tests whether the application can modify the resource denoted by this abstract pathname.- Returns:
true
if and only if the resource system actually contains a resource denoted by this abstract pathname and the application is allowed to write to the resource;false
otherwise.
-
remove
void remove(boolean force) throws java.io.IOException
Deletes the resource denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty, when argument "force" is set to false, when argument "force" is set to true, also the children of the directory will be deleted.- Parameters:
force
- force the removal- Throws:
java.io.IOException
- if the file doesn't exists or can't delete
-
delete
@Deprecated boolean delete()
Deprecated.replaced with method remove(boolean)Deletes the resource denoted by this abstract pathname. If this pathname denotes a directory, then the directory must be empty, when argument "force" is set to false, when argument "force" is set to true, also the children oif the directory will be deleted. if the file doesn't exists or can't delete- Returns:
- was delete sucessfull or not
-
exists
boolean exists()
Tests whether the resource denoted by this abstract pathname exists.- Returns:
- true if and only if the resource denoted by this abstract pathname exists; false otherwise
-
getAbsoluteResource
Resource getAbsoluteResource()
Returns the absolute form of this abstract pathname.- Returns:
- The absolute abstract pathname denoting the same resource as this abstract pathname
-
getAbsolutePath
java.lang.String getAbsolutePath()
Returns the absolute pathname string of this abstract pathname.If this abstract pathname is already absolute, then the pathname string is simply returned as if by the
method.getPath()
- Returns:
- The absolute pathname string denoting the same resource as this abstract pathname
-
getCanonicalResource
Resource getCanonicalResource() throws java.io.IOException
Returns the canonical form of this abstract pathname.- Returns:
- The canonical pathname string denoting the same resource as this abstract pathname
- Throws:
java.io.IOException
- If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
-
getCanonicalPath
java.lang.String getCanonicalPath() throws java.io.IOException
Returns the canonical pathname string of this abstract pathname.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
getAbsolutePath()
method, and then maps it to its unique form in a system-dependent way.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.
- Returns:
- The canonical pathname string denoting the same file or directory as this abstract pathname
- Throws:
java.io.IOException
- If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
-
getName
java.lang.String getName()
Returns the name of the resource denoted by this abstract pathname. This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned.- Returns:
- The name of the resource denoted by this abstract pathname, or the empty string if this pathname's name sequence is empty
-
getParent
java.lang.String getParent()
Returns the pathname string of this abstract pathname's parent, ornull
if this pathname does not name a parent directory.The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.
- Returns:
- The pathname string of the parent directory named by this abstract pathname, or
null
if this pathname does not name a parent
-
getParentResource
Resource getParentResource()
Returns the abstract pathname of this abstract pathname's parent, ornull
if this pathname does not name a parent directory.The parent of an abstract pathname consists of the pathname's prefix, if any, and each name in the pathname's name sequence except for the last. If the name sequence is empty then the pathname does not name a parent directory.
- Returns:
- The abstract pathname of the parent directory named by this abstract pathname, or
null
if this pathname does not name a parent
-
getReal
java.lang.String getReal(java.lang.String realpath)
returns a resource path that is relative to the current resource- Parameters:
realpath
- relative path to get resource from- Returns:
- relative resource path to the current
-
getRealResource
Resource getRealResource(java.lang.String relpath)
returns a resource that is relative to the current resource- Parameters:
relpath
- relative path to get resource from- Returns:
- relative resource to the current
-
getPath
java.lang.String getPath()
Converts this abstract pathname into a pathname string.- Returns:
- The string form of this abstract pathname
-
isAbsolute
boolean isAbsolute()
Tests whether this abstract pathname is absolute.- Returns:
true
if this abstract pathname is absolute,false
otherwise
-
isDirectory
boolean isDirectory()
Tests whether the resource denoted by this abstract pathname is a directory.- Returns:
true
if and only if the file denoted by this abstract pathname exists and is a directory;false
otherwise
-
isFile
boolean isFile()
Tests whether the file denoted by this abstract pathname is a normal file. A file is normal if it is not a directory and, in addition, satisfies other system-dependent criteria. Any non-directory file created by a Java application is guaranteed to be a normal file.- Returns:
true
if and only if the file denoted by this abstract pathname exists and is a normal file;false
otherwise
-
isHidden
@Deprecated boolean isHidden()
Deprecated.use insteadgetAttribute(short)
Tests whether the resource named by this abstract pathname is a hidden resource.- Returns:
true
if and only if the file denoted by this abstract pathname is hidden
-
isArchive
@Deprecated boolean isArchive()
Deprecated.use insteadgetAttribute(short)
Tests whether the resource named by this abstract pathname is an archive resource.- Returns:
true
if and only if the file denoted by this abstract pathname is an archive
-
isSystem
@Deprecated boolean isSystem()
Deprecated.use insteadgetAttribute(short)
Tests whether the resource named by this abstract pathname is a system resource.- Returns:
true
if and only if the file denoted by this abstract pathname is a system resource
-
lastModified
long lastModified()
Returns the time that the resource denoted by this abstract pathname was last modified.- Returns:
- A
long
value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or0L
if the file does not exist or if an I/O error occurs
-
length
long length()
Returns the length of the resource denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.- Returns:
- The length, in bytes, of the resource denoted by this abstract pathname, or
0L
if the resource does not exist
-
list
java.lang.String[] list()
Returns an array of strings naming the files and directories in the directory denoted by this abstract pathname.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.
- Returns:
- An array of strings naming the files and directories in the directory denoted by this
abstract pathname. The array will be empty if the directory is empty. Returns
null
if this abstract pathname does not denote a directory, or if an I/O error occurs.
-
list
java.lang.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. The behavior of this method is the same as that of the
method, except that the strings in the returned array must satisfy the filter. If the givenlist()
filter
isnull
then all names are accepted. Otherwise, a name satisfies the filter if and only if the valuetrue
results when the
method of the filter is invoked on this abstract pathname and the name of a file or directory in the directory that it denotes.ResourceNameFilter.accept(lucee.commons.io.res.Resource, java.lang.String)
- Parameters:
filter
- A resourcename filter- Returns:
- An array of strings naming the files and directories in the directory denoted by this
abstract pathname that were accepted by the given
filter
. The array will be empty if the directory is empty or if no names were accepted by the filter. Returnsnull
if this abstract pathname does not denote a directory, or if an I/O error occurs.
-
list
java.lang.String[] list(ResourceFilter filter)
-
listResources
Resource[] listResources()
Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.If this abstract pathname does not denote a directory, then this method returns
null
. Otherwise an array ofFile
objects is returned, one for each file or directory in the directory. Therefore if this pathname is absolute then each resulting pathname is absolute; if this pathname is relative then each resulting pathname will be relative to the same directory.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.
- Returns:
- An array of abstract pathnames denoting the files and directories in the directory
denoted by this abstract pathname. The array will be empty if the directory is empty.
Returns
null
if this abstract pathname does not denote a directory, or if an I/O error occurs.
-
listResources
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. The behavior of this method is the same as that of the
method, except that the pathnames in the returned array must satisfy the filter. If the givenlistResources()
filter
isnull
then all pathnames are accepted. Otherwise, a pathname satisfies the filter if and only if the valuetrue
results when the
method of the filter is invoked on the pathname.ResourceFilter.accept(Resource)
- Parameters:
filter
- A resource filter- Returns:
- An array of abstract pathnames denoting the files and directories in the directory
denoted by this abstract pathname. The array will be empty if the directory is empty.
Returns
null
if this abstract pathname does not denote a directory, or if an I/O error occurs.
-
listResources
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. The behavior of this method is the same as that of the
method, except that the pathnames in the returned array must satisfy the filter. If the givenlistResources()
filter
isnull
then all pathnames are accepted. Otherwise, a pathname satisfies the filter if and only if the valuetrue
results when the
method of the filter is invoked on this abstract pathname and the name of a file or directory in the directory that it denotes.ResourceNameFilter.accept(lucee.commons.io.res.Resource, java.lang.String)
- Parameters:
filter
- A resourcename filter- Returns:
- An array of abstract pathnames denoting the files and directories in the directory
denoted by this abstract pathname. The array will be empty if the directory is empty.
Returns
null
if this abstract pathname does not denote a directory, or if an I/O error occurs.
-
renameTo
@Deprecated boolean renameTo(Resource dest)
Deprecated.use instead#moveTo(Resource)
Move/renames the file denoted by this abstract pathname.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.
- Parameters:
dest
- The new abstract pathname for the named file- Returns:
- has successfull renamed or not
-
moveTo
void moveTo(Resource dest) throws java.io.IOException
Move/renames the file denoted by this abstract pathname.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.
- Parameters:
dest
- The new abstract pathname for the named file- Throws:
java.io.IOException
- thrown when operation not done successfully
-
setLastModified
boolean setLastModified(long time)
Sets the last-modified time of the file or directory named by this abstract pathname.All platforms support file-modification times to the nearest second, but some provide more precision. The argument will be truncated to fit the supported precision. If the operation succeeds and no intervening operations on the file take place, then the next invocation of the
method will return the (possibly truncated)lastModified()
time
argument that was passed to this method.- Parameters:
time
- The new last-modified time, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970)- Returns:
true
if and only if the operation succeeded;false
otherwise
-
setReadOnly
@Deprecated boolean setReadOnly()
Deprecated.use insteadsetWritable(boolean)
Marks the file or directory named by this abstract pathname so that only read operations are allowed. After invoking this method the file or directory is guaranteed not to change until it is either deleted or marked to allow write access. Whether or not a read-only file or directory may be deleted depends upon the underlying system.- Returns:
true
if and only if the operation succeeded;false
otherwise
-
setWritable
boolean setWritable(boolean writable)
-
setReadable
boolean setReadable(boolean readable)
-
createNewFile
@Deprecated boolean createNewFile()
Deprecated.use instead#createFile(boolean)
Creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.- Returns:
true
if the named file does not exist and was successfully created;false
if the named file already exists
-
createFile
void createFile(boolean createParentWhenNotExists) throws java.io.IOException
Creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file.- Parameters:
createParentWhenNotExists
- create parent when not exist- Throws:
java.io.IOException
- If an I/O error occurred
-
mkdir
@Deprecated boolean mkdir()
Deprecated.use#createDirectory(boolean)
Creates the directory named by this abstract pathname.- Returns:
true
if and only if the directory was created;false
otherwise
-
mkdirs
@Deprecated boolean mkdirs()
Deprecated.use#createDirectory(boolean)
Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.- Returns:
true
if and only if the directory was created, along with all necessary parent directories;false
otherwise
-
createDirectory
void createDirectory(boolean createParentWhenNotExists) throws java.io.IOException
Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories if flag "createParentWhenNotExists" is set to true. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.- Parameters:
createParentWhenNotExists
- throws Exception when can't create directory- Throws:
java.io.IOException
- in case copy fails
-
getInputStream
java.io.InputStream getInputStream() throws java.io.IOException
- Throws:
java.io.IOException
-
getOutputStream
java.io.OutputStream getOutputStream() throws java.io.IOException
- Throws:
java.io.IOException
-
copyTo
void copyTo(Resource res, boolean append) throws java.io.IOException
copy current resource data to given resource- Parameters:
res
- resource to copy toappend
- do append value to existing data or overwrite- Throws:
java.io.IOException
- in case copy fails
-
copyFrom
void copyFrom(Resource res, boolean append) throws java.io.IOException
copy data of given resource to current- Parameters:
res
- resource to copy fromappend
- do append value to existing data or overwrite- Throws:
java.io.IOException
- in case copy fails
-
getOutputStream
java.io.OutputStream getOutputStream(boolean append) throws java.io.IOException
- Throws:
java.io.IOException
-
getResourceProvider
ResourceProvider getResourceProvider()
-
getMode
int getMode()
-
setMode
void setMode(int mode) throws java.io.IOException
- Throws:
java.io.IOException
-
setHidden
@Deprecated void setHidden(boolean value) throws java.io.IOException
Deprecated.use insteadsetAttribute(short, boolean)
sets hidden attribute of the resource- Parameters:
value
- value to set- Throws:
java.io.IOException
- thrown when no access to change the value or the resource doesn't exist
-
setSystem
@Deprecated void setSystem(boolean value) throws java.io.IOException
Deprecated.use insteadsetAttribute(short, boolean)
sets system attribute of the resource- Parameters:
value
- value to set- Throws:
java.io.IOException
- thrown when no access to change the value or the resource doesn't exist
-
setArchive
@Deprecated void setArchive(boolean value) throws java.io.IOException
Deprecated.use insteadsetAttribute(short, boolean)
sets archive attribute of the resource- Parameters:
value
- value to set- Throws:
java.io.IOException
- thrown when no access to change the value or the resource doesn't exist
-
setAttribute
void setAttribute(short attribute, boolean value) throws java.io.IOException
sets an attribute on the resource if supported otherwise it will ign- Parameters:
attribute
- which attribute (Resource.ATTRIBUTE_*)value
- value to set- Throws:
java.io.IOException
- thrown when no access to change the value, when attributes are not supported or the resource doesn't exist
-
getAttribute
boolean getAttribute(short attribute)
return value of a specific attribute- Parameters:
attribute
- attribute to get the value for- Returns:
- value of the attribute
-
-