railo.commons.io.res.util
Class ResourceSupport

java.lang.Object
  extended by railo.commons.io.res.util.ResourceSupport
All Implemented Interfaces:
Serializable, Resource
Direct Known Subclasses:
CacheResource, CompressResource, DatasourceResource, FTPResource, RamResource, ReadOnlyResourceSupport, S3Resource

public abstract class ResourceSupport
extends Object
implements Resource

Helper class to build resources

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface railo.commons.io.res.Resource
ATTRIBUTE_ARCHIVE, ATTRIBUTE_HIDDEN, ATTRIBUTE_SYSTEM
 
Constructor Summary
ResourceSupport()
           
 
Method Summary
 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 realpath)
          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()
           
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface railo.commons.io.res.Resource
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
 

Constructor Detail

ResourceSupport

public ResourceSupport()
Method Detail

copyFrom

public void copyFrom(Resource res,
                     boolean append)
              throws IOException
Description copied from interface: Resource
copy data of given resource to current

Specified by:
copyFrom in interface Resource
Throws:
IOException
See Also:
Resource.copyFrom(railo.commons.io.res.Resource,boolean)

copyTo

public void copyTo(Resource res,
                   boolean append)
            throws IOException
Description copied from interface: Resource
copy current resource data to given resource

Specified by:
copyTo in interface Resource
Throws:
IOException
See Also:
Resource.copyTo(railo.commons.io.res.Resource,boolean)

getAbsoluteResource

public Resource getAbsoluteResource()
Description copied from interface: Resource
Returns the absolute form of this abstract pathname.

Specified by:
getAbsoluteResource in interface Resource
Returns:
The absolute abstract pathname denoting the same resource as this abstract pathname
See Also:
res.Resource#getAbsoluteResource()

getAbsolutePath

public String getAbsolutePath()
Description copied from interface: Resource
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 Resource.getPath() method.

Specified by:
getAbsolutePath in interface Resource
Returns:
The absolute pathname string denoting the same resource as this abstract pathname
See Also:
res.Resource#getAbsolutePath()

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Specified by:
getOutputStream in interface Resource
Throws:
IOException
See Also:
res.Resource#getOutputStream()

getCanonicalResource

public Resource getCanonicalResource()
                              throws IOException
Description copied from interface: Resource
Returns the canonical form of this abstract pathname.

Specified by:
getCanonicalResource in interface Resource
Returns:
The canonical pathname string denoting the same resource as this abstract pathname
Throws:
IOException - If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
See Also:
res.Resource#getCanonicalResource()

getCanonicalPath

public String getCanonicalPath()
                        throws IOException
Description copied from interface: Resource
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 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.

Specified by:
getCanonicalPath in interface Resource
Returns:
The canonical pathname string denoting the same file or directory as this abstract pathname
Throws:
IOException - If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
See Also:
res.Resource#getCanonicalPath()

moveTo

public void moveTo(Resource dest)
            throws IOException
Description copied from interface: 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.

Specified by:
moveTo in interface Resource
Parameters:
dest - The new abstract pathname for the named file
Throws:
IOException - throwed when operation not done sucessfull
See Also:
res.Resource#moveTo(res.Resource)

list

public String[] list(ResourceFilter filter)
Specified by:
list in interface Resource
See Also:
res.Resource#list(res.filter.ResourceFilter)

list

public String[] list(ResourceNameFilter filter)
Description copied from interface: Resource
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 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(railo.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.

Specified by:
list in interface Resource
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. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
See Also:
res.Resource#list(res.filter.ResourceNameFilter)

listResources

public Resource[] listResources(ResourceNameFilter filter)
Description copied from interface: Resource
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 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(railo.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.

Specified by:
listResources in interface Resource
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.
See Also:
res.Resource#listResources(res.filter.ResourceNameFilter)

listResources

public Resource[] listResources(ResourceFilter filter)
Description copied from interface: Resource
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 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.

Specified by:
listResources in interface 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.
See Also:
res.Resource#listResources(res.filter.ResourceFilter)

getReal

public String getReal(String realpath)
Description copied from interface: Resource
returns a resource path that is relative to the current resource

Specified by:
getReal in interface Resource
Returns:
relative resource path to the current
See Also:
res.Resource#getReal(java.lang.String)

list

public String[] list()
Description copied from interface: Resource
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.

Specified by:
list in interface Resource
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.
See Also:
res.Resource#list()

canRead

public boolean canRead()
Description copied from interface: Resource
Tests whether the application can read the resource denoted by this abstract pathname.

Specified by:
canRead in interface Resource
Returns:
true if and only if the resource specified by this abstract pathname exists and can be read by the application; false otherwise
See Also:
res.Resource#canRead()

canWrite

public boolean canWrite()
Description copied from interface: Resource
Tests whether the application can modify the resource denoted by this abstract pathname.

Specified by:
canWrite in interface Resource
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.
See Also:
res.Resource#canWrite()

renameTo

public boolean renameTo(Resource dest)
Description copied from interface: 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.

Specified by:
renameTo in interface Resource
Parameters:
dest - The new abstract pathname for the named file
Returns:
has successfull renamed or not
See Also:
res.Resource#renameTo(res.Resource)

createNewFile

public boolean createNewFile()
Description copied from interface: Resource
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.

Specified by:
createNewFile in interface Resource
Returns:
true if the named file does not exist and was successfully created; false if the named file already exists
See Also:
res.Resource#createNewFile()

mkdir

public boolean mkdir()
Description copied from interface: Resource
Creates the directory named by this abstract pathname.

Specified by:
mkdir in interface Resource
Returns:
true if and only if the directory was created; false otherwise
See Also:
res.Resource#mkdir()

mkdirs

public boolean mkdirs()
Description copied from interface: Resource
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.

Specified by:
mkdirs in interface Resource
Returns:
true if and only if the directory was created, along with all necessary parent directories; false otherwise
See Also:
res.Resource#mkdirs()

delete

public boolean delete()
Description copied from interface: Resource
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.

Specified by:
delete in interface Resource
See Also:
Resource.delete()

isArchive

public boolean isArchive()
Description copied from interface: Resource
Tests whether the resource named by this abstract pathname is a archive resource.

Specified by:
isArchive in interface Resource
Returns:
true if and only if the file denoted by this abstract pathname is a archive
See Also:
Resource.isArchive()

isSystem

public boolean isSystem()
Description copied from interface: Resource
Tests whether the resource named by this abstract pathname is a system resource.

Specified by:
isSystem in interface Resource
Returns:
true if and only if the file denoted by this abstract pathname is a system resource
See Also:
Resource.isSystem()

isHidden

public boolean isHidden()
Description copied from interface: Resource
Tests whether the resource named by this abstract pathname is a hidden resource.

Specified by:
isHidden in interface Resource
Returns:
true if and only if the file denoted by this abstract pathname is hidden
See Also:
Resource.isHidden()

setArchive

public void setArchive(boolean value)
                throws IOException
Description copied from interface: Resource
sets archive attribute of the resource

Specified by:
setArchive in interface Resource
Throws:
IOException - throwed when no access to change the value or the resource doesn't exists
See Also:
Resource.setArchive(boolean)

setHidden

public void setHidden(boolean value)
               throws IOException
Description copied from interface: Resource
sets hidden attribute of the resource

Specified by:
setHidden in interface Resource
Throws:
IOException - throwed when no access to change the value or the resource doesn't exists
See Also:
Resource.setHidden(boolean)

setReadOnly

public boolean setReadOnly()
Description copied from interface: Resource
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.

Specified by:
setReadOnly in interface Resource
Returns:
true if and only if the operation succeeded; false otherwise
See Also:
Resource.setReadOnly()

setSystem

public void setSystem(boolean value)
               throws IOException
Description copied from interface: Resource
sets system attribute of the resource

Specified by:
setSystem in interface Resource
Throws:
IOException - throwed when no access to change the value or the resource doesn't exists
See Also:
Resource.setSystem(boolean)

equals

public boolean equals(Object obj)
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

getAttribute

public boolean getAttribute(short attribute)
Description copied from interface: Resource
return value of a specific attribute

Specified by:
getAttribute in interface Resource
Returns:
value of the attribute
See Also:
Resource.getAttribute(short)

setAttribute

public void setAttribute(short attribute,
                         boolean value)
                  throws IOException
Description copied from interface: Resource
sets a attribute on the resource if supported otherwise it will ign

Specified by:
setAttribute in interface Resource
Parameters:
attribute - wich attrbute (Resource.ATTRIBUTE_*)
Throws:
IOException - throwed when no access to change the value, when attributes are not supported or the resource doesn't exists
See Also:
Resource.setAttribute(short, boolean)


Copyright © 2012 Railo