Forge - Parent 1.0.7-SNAPSHOT

org.jboss.forge.resources
Class FileResource<T extends FileResource<?>>

java.lang.Object
  extended by org.jboss.forge.resources.AbstractResource<File>
      extended by org.jboss.forge.resources.FileResource<T>
All Implemented Interfaces:
Resource<File>
Direct Known Subclasses:
DependencyResource, DirectoryResource, JavaResource, MavenPomResource, PropertiesFileResource, UnknownFileResource

public abstract class FileResource<T extends FileResource<?>>
extends AbstractResource<File>

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
           
protected  boolean scratch
           
protected  File scratchFile
           
 
Fields inherited from class org.jboss.forge.resources.AbstractResource
flags, parent, resourceFactory
 
Constructor Summary
protected FileResource(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()
           
 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.
 File getUnderlyingResourceObject()
          Get the actual underlying file resource that this resource instance represents, whether existing or non-existing.
 boolean isDirectory()
          Return true if this FileResource exists and is actually a directory, otherwise return false;
 boolean isStale()
          Returns true if the underlying resource has been modified on the file system since it was initially loaded.
 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 FileResource
 boolean renameTo(String pathspec)
          Rename this resource to the given path.
 T setContents(char[] data)
          Set the contents of this FileResource to the given character array.
 T setContents(InputStream data)
           
 T setContents(String data)
          Set the contents of this FileResource to the given String
 
Methods inherited from class org.jboss.forge.resources.AbstractResource
doListResources, equals, getFlags, getFullyQualifiedName, getResourceFactory, hashCode, isFlagSet, listResources, listResources, setFlag, unsetFlag
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scratch

protected boolean scratch

file

protected File file

scratchFile

protected File scratchFile

lastModification

protected long lastModification
Constructor Detail

FileResource

protected FileResource(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.

Returns:
The name of the resource.

getUnderlyingResourceObject

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

Returns:
An instance of File

getResourceInputStream

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


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.


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.

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.


isDirectory

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


isStale

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

Returns:
boolean true if resource is changed.

markUpToDate

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


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()


mkdirs

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


delete

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


delete

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

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.


setContents

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


setContents

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


setContents

public T setContents(InputStream data)

createNewFile

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


createTempResource

public T createTempResource()

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.


renameTo

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


Forge - Parent 1.0.7-SNAPSHOT

Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.