Forge - Resource Addon API 2.0.0.Alpha3

org.jboss.forge.resource
Class AbstractFileResource<T extends FileResource<T>>

java.lang.Object
  extended by org.jboss.forge.facets.AbstractFaceted<ResourceFacet>
      extended by org.jboss.forge.resource.AbstractResource<File>
          extended by org.jboss.forge.resource.AbstractFileResource<T>
All Implemented Interfaces:
org.jboss.forge.facets.Faceted<ResourceFacet>, FileResource<T>, Resource<File>

public abstract class AbstractFileResource<T extends FileResource<T>>
extends AbstractResource<File>
implements FileResource<T>

A standard, built-in resource for representing files on the filesystem.

Author:
Mike Brock, Lincoln Baxter, III

Field Summary
protected  File file
           
protected  long lastModification
           
 
Fields inherited from class org.jboss.forge.resource.AbstractResource
parent, resourceFactory
 
Constructor Summary
protected AbstractFileResource(ResourceFactory factory, File file)
           
 
Method Summary
abstract  Resource<File> createFrom(File file)
          Create a new Resource instance for the target file.
 boolean createNewFile()
          Create the file in the underlying resource system.
 T createTempResource()
          Create a temporary FileResource
 boolean delete()
          Delete this file, non-recursively.
 boolean delete(boolean recursive)
          Delete this Resource, and all child resources.
 void deleteOnExit()
          Requests that the file or directory denoted by this resource be deleted when the virtual machine terminates.
 boolean exists()
          Return true if this Resource exists, return false if not.
 Resource<?> getChild(String name)
          Get a child of this resource.
 String getName()
          Return the common name of the resource.
 Resource<?> getParent()
          Get the parent of the current resource.
 InputStream getResourceInputStream()
          Get the InputStream represented by this Resource.
 long getSize()
          Returns the size of the file denoted by this abstract pathname
 File getUnderlyingResourceObject()
          Get the actual underlying file resource that this resource instance represents, whether existing or non-existing.
 boolean isDirectory()
          Return true if this AbstractFileResource exists and is actually a directory, otherwise return false;
 boolean isExecutable()
          Returns if a file is executable
 boolean isReadable()
          Returns if a file is readable
 boolean isStale()
          Returns true if the underlying resource has been modified on the file system since it was initially loaded.
 boolean isWritable()
          Returns if a file is writable
 void markUpToDate()
          Re-read the last modified timestamp for this resource.
 boolean mkdir()
          Create a new single directory for this resource.
 boolean mkdirs()
          Create all directories required for this resource to exist.
<R extends Resource<?>>
R
reify(Class<R> type)
          Ask this Resource if it is actually a resource of the given type; if it is, return a new reference to the resource as the given type, otherwise return null.
 boolean renameTo(FileResource<?> target)
          Rename this resource to the given AbstractFileResource
 boolean renameTo(String pathspec)
          Rename this resource to the given path.
 T setContents(char[] data)
          Set the contents of this AbstractFileResource to the given character array.
 T setContents(InputStream data)
          Set the contents of this FileResource to the contents of the given InputStream.
 T setContents(String data)
          Set the contents of this AbstractFileResource to the given String
 String toString()
           
 
Methods inherited from class org.jboss.forge.resource.AbstractResource
doListResources, equals, getFullyQualifiedName, getResourceFactory, hashCode, listResources, listResources, supports
 
Methods inherited from class org.jboss.forge.facets.AbstractFaceted
getFacet, getFacets, getFacets, hasAllFacets, hasAllFacets, hasFacet, install, uninstall
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jboss.forge.resource.Resource
getFullyQualifiedName, getResourceFactory, listResources, listResources
 
Methods inherited from interface org.jboss.forge.facets.Faceted
getFacet, getFacets, getFacets, hasAllFacets, hasAllFacets, hasFacet, install, supports, uninstall
 

Field Detail

file

protected File file

lastModification

protected long lastModification
Constructor Detail

AbstractFileResource

protected AbstractFileResource(ResourceFactory factory,
                               File file)
Method Detail

getName

public String getName()
Description copied from interface: Resource
Return the common name of the resource. If it's a file, for instance, just the file name.

Specified by:
getName in interface Resource<File>
Returns:
The name of the resource.

toString

public String toString()
Overrides:
toString in class Object

getUnderlyingResourceObject

public File getUnderlyingResourceObject()
Get the actual underlying file resource that this resource instance represents, whether existing or non-existing.

Specified by:
getUnderlyingResourceObject in interface Resource<File>
Returns:
An instance of File

getResourceInputStream

public InputStream getResourceInputStream()
Description copied from interface: Resource
Get the InputStream represented by this Resource.

Specified by:
getResourceInputStream in interface Resource<File>

getParent

public Resource<?> getParent()
Get the parent of the current resource. Returns null if the current resource is the project root.

Specified by:
getParent in interface Resource<File>
Overrides:
getParent in class AbstractResource<File>
Returns:
An instance of the resource parent.

getChild

public Resource<?> getChild(String name)
Description copied from interface: Resource
Get a child of this resource. Returns null if no child by the given name can be found.

Specified by:
getChild in interface Resource<File>

createFrom

public abstract Resource<File> createFrom(File file)
Create a new Resource instance for the target file. The new Resource should be of the same type as this.

Specified by:
createFrom in interface Resource<File>
Parameters:
file - The file to create the resource instance from.
Returns:
A new resource.

exists

public boolean exists()
Description copied from interface: Resource
Return true if this Resource exists, return false if not.

Specified by:
exists in interface Resource<File>

isDirectory

public boolean isDirectory()
Return true if this AbstractFileResource exists and is actually a directory, otherwise return false;

Specified by:
isDirectory in interface FileResource<T extends FileResource<T>>

isStale

public boolean isStale()
Returns true if the underlying resource has been modified on the file system since it was initially loaded.

Specified by:
isStale in interface FileResource<T extends FileResource<T>>
Returns:
boolean true if resource is changed.

markUpToDate

public void markUpToDate()
Re-read the last modified timestamp for this resource.

Specified by:
markUpToDate in interface FileResource<T extends FileResource<T>>

mkdir

public boolean mkdir()
Create a new single directory for this resource. This will not succeed if any parent directories needed for this resource to exist are missing. You should consider using mkdirs()

Specified by:
mkdir in interface FileResource<T extends FileResource<T>>

mkdirs

public boolean mkdirs()
Create all directories required for this resource to exist.

Specified by:
mkdirs in interface FileResource<T extends FileResource<T>>

delete

public boolean delete()
Delete this file, non-recursively.

Specified by:
delete in interface Resource<File>

delete

public boolean delete(boolean recursive)
Delete this Resource, and all child resources.

Specified by:
delete in interface Resource<File>
Parameters:
recursive - if false and this resource both supports recursive deletion and contains children, deletion will not occur; otherwise, if true, deletion will propagate to all child resources. Implementations may choose simply to delegate to Resource.delete()

deleteOnExit

public void deleteOnExit()
Requests that the file or directory denoted by this resource be deleted when the virtual machine terminates.

Once deletion has been requested, it is not possible to cancel the request. This method should therefore be used with care.

Specified by:
deleteOnExit in interface FileResource<T extends FileResource<T>>

setContents

public T setContents(String data)
Set the contents of this AbstractFileResource to the given String

Specified by:
setContents in interface FileResource<T extends FileResource<T>>

setContents

public T setContents(char[] data)
Set the contents of this AbstractFileResource to the given character array.

Specified by:
setContents in interface FileResource<T extends FileResource<T>>

setContents

public T setContents(InputStream data)
Description copied from interface: FileResource
Set the contents of this FileResource to the contents of the given InputStream.

Specified by:
setContents in interface FileResource<T extends FileResource<T>>

createNewFile

public boolean createNewFile()
Create the file in the underlying resource system. Necessary directory paths will be created automatically.

Specified by:
createNewFile in interface FileResource<T extends FileResource<T>>

createTempResource

public T createTempResource()
Description copied from interface: FileResource
Create a temporary FileResource

Specified by:
createTempResource in interface FileResource<T extends FileResource<T>>

reify

public <R extends Resource<?>> R reify(Class<R> type)
Description copied from interface: Resource
Ask this Resource if it is actually a resource of the given type; if it is, return a new reference to the resource as the given type, otherwise return null.

Specified by:
reify in interface Resource<File>
Overrides:
reify in class AbstractResource<File>

renameTo

public boolean renameTo(String pathspec)
Rename this resource to the given path.

Specified by:
renameTo in interface FileResource<T extends FileResource<T>>

renameTo

public boolean renameTo(FileResource<?> target)
Rename this resource to the given AbstractFileResource

Specified by:
renameTo in interface FileResource<T extends FileResource<T>>

getSize

public long getSize()
Description copied from interface: FileResource
Returns the size of the file denoted by this abstract pathname

Specified by:
getSize in interface FileResource<T extends FileResource<T>>

isExecutable

public boolean isExecutable()
Description copied from interface: FileResource
Returns if a file is executable

Specified by:
isExecutable in interface FileResource<T extends FileResource<T>>

isReadable

public boolean isReadable()
Description copied from interface: FileResource
Returns if a file is readable

Specified by:
isReadable in interface FileResource<T extends FileResource<T>>

isWritable

public boolean isWritable()
Description copied from interface: FileResource
Returns if a file is writable

Specified by:
isWritable in interface FileResource<T extends FileResource<T>>

Forge - Resource Addon API 2.0.0.Alpha3

Copyright © 2013 JBoss by Red Hat. All Rights Reserved.