Package com.wavemaker.commons.io
Interface Resource
-
- All Known Implementing Classes:
AbstractReadOnlyFile,ClassPathFile,LocalFile,LocalFolder,StoredFile,StoredFolder,StoredResource,ZipArchive
public interface ResourceBase abstract forFiles andFolders that may be stored on a physical disk or using some other mechanism. Subclasses will either implementFileorFolder(but never both).- See Also:
File,Folder,ResourceURL
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ResourcecopyTo(Folder folder)Recursively copy this resource to the specified folder.voidcreateIfMissing()Recursively creates an empty representation of this resource and allparents.voiddelete()Delete the current resource (and any children).booleanequals(java.lang.Object obj)Determines if this resource is equal to another object.booleanexists()Returns true if the resource exists in the underlying store.longgetLastModified()Gets the time this resource object was last modified.java.lang.StringgetName()Returns the name of the resource.FoldergetParent()Returns the parent folder of the resource or null if this is the root folder.booleanisModifiedAfter(long n)booleanisModifiedAfter(Resource resource)booleanisModifiedBefore(long n)booleanisModifiedBefore(Resource resource)booleanisRelativeTo(Folder folder)ResourcemoveTo(Folder folder)Move this resource to the specified folder.<R extends Resource,O extends ResourceOperation<R>>
OperformOperation(O operation)Resourcerename(java.lang.String name)Rename the current resource.java.lang.StringtoString()Returns the complete name of the resource.java.lang.StringtoString(ResourceStringFormat format)Returns the name of the resource in the specified format.java.lang.StringtoStringRelativeTo(Folder source)Returns the the complete name of this resource (including path elements) relative to the specified source folder.
-
-
-
Method Detail
-
getParent
Folder getParent()
Returns the parent folder of the resource or null if this is the root folder.- Returns:
- the parent folder or null
- Throws:
ResourceDoesNotExistException- if this resource no longer exists
-
getName
java.lang.String getName()
Returns the name of the resource. This name does not include any path element. Root folders will have an empty string name.- Returns:
- the name of the resource, for example "file.txt"
- Throws:
ResourceDoesNotExistException- if this resource no longer exists
-
delete
void delete()
Delete the current resource (and any children). If this resource does not exist then no operation is performed.
-
moveTo
Resource moveTo(Folder folder)
Move this resource to the specified folder. Any duplicateFiles will be replaced (existingFolderresources will be merged). If the resource does not exist aResourceDoesNotExistExceptionis thrown.- Parameters:
folder- the folder to move the resource to- Returns:
- a new resource (the current resource will no longer
exist - Throws:
ResourceDoesNotExistException- if this resource no longer exists
-
copyTo
Resource copyTo(Folder folder)
Recursively copy this resource to the specified folder. Any duplicateFiles will be replaced (existingFolderresources will be merged). If the resource does not exist aResourceDoesNotExistExceptionis thrown.- Parameters:
folder- the folder to copy the resource to- Returns:
- a new resource (the current resource will no longer
exist - Throws:
ResourceDoesNotExistException- if this resource no longer exists
-
rename
Resource rename(java.lang.String name)
Rename the current resource. The rename operation cannot be used not move the resource to a different folder, use themoveTo(Folder)method to move the resource before renaming if required. Root folders cannot be renamed. If the resource does not exist aResourceDoesNotExistExceptionis thrown.- Parameters:
name- the new name of the resource (this must not include any path elements)- Returns:
- a new resource (the current resource will no longer
exist - Throws:
ResourceExistsException- if a resource already exists with the specified name
-
exists
boolean exists()
Returns true if the resource exists in the underlying store.- Returns:
- true if the resource exists.
-
createIfMissing
void createIfMissing()
Recursively creates an empty representation of this resource and allparents. Calling this method on an existing resource has not effect.
-
toString
java.lang.String toString()
Returns the complete name of the resource. This name includes path elements. Folders always end in '/'.- Overrides:
toStringin classjava.lang.Object- Returns:
- the full name of the resource, for example "/folder/file.txt" or "/folder/"
- See Also:
getName(),toString(ResourceStringFormat),toStringRelativeTo(Folder)
-
toString
java.lang.String toString(ResourceStringFormat format)
Returns the name of the resource in the specified format.- Parameters:
format- the format used for the name- Returns:
- the name
- See Also:
toString(),toStringRelativeTo(Folder)
-
toStringRelativeTo
java.lang.String toStringRelativeTo(Folder source)
Returns the the complete name of this resource (including path elements) relative to the specified source folder. The source must be a parent (or grandparent etc) of this resource. If the source is this folder an empty String is returned. The returned value does not include any leading slash, for example: '/a/b/c.txt' relative to '/a/' will return 'b/c.txt'.- Parameters:
source- the source folder- Returns:
- the name
- See Also:
toString(),toStringRelativeTo(Folder)
-
isRelativeTo
boolean isRelativeTo(Folder folder)
- Returns:
- true if the given param folder is relative to comprising folder object, else return false
-
equals
boolean equals(java.lang.Object obj)
Determines if this resource is equal to another object. Any resources that have the same type, path and are stored in the same underlying system are considered equal.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare to- Returns:
- true if the resource is equal to the specified object.
-
performOperation
<R extends Resource,O extends ResourceOperation<R>> O performOperation(O operation)
-
getLastModified
long getLastModified()
Gets the time this resource object was last modified. The time is measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970).- Returns:
- the time this resource object was last modified; or 0 if the resource object does not exist, if an I/O error occurred, or if the operation is not supported
-
isModifiedAfter
boolean isModifiedAfter(long n)
-
isModifiedAfter
boolean isModifiedAfter(Resource resource)
-
isModifiedBefore
boolean isModifiedBefore(long n)
-
isModifiedBefore
boolean isModifiedBefore(Resource resource)
-
-