Class DecoratedFileObject

java.lang.Object
org.apache.commons.vfs2.impl.DecoratedFileObject
All Implemented Interfaces:
Closeable, AutoCloseable, Comparable<FileObject>, Iterable<FileObject>, FileObject
Direct Known Subclasses:
OnCallRefreshFileObject, SynchronizedFileObject

public class DecoratedFileObject extends Object implements FileObject
Base class to build a fileObject decoration.
  • Field Details

    • decoratedFileObject

      private final FileObject decoratedFileObject
  • Constructor Details

    • DecoratedFileObject

      public DecoratedFileObject(FileObject decoratedFileObject)
  • Method Details

    • canRenameTo

      public boolean canRenameTo(FileObject newfile)
      Description copied from interface: FileObject
      Queries the file if it is possible to rename it to newfile.
      Specified by:
      canRenameTo in interface FileObject
      Parameters:
      newfile - the new file(-name)
      Returns:
      true it this is the case
    • close

      public void close() throws FileSystemException
      Description copied from interface: FileObject
      Closes this file, and its content. This method is a hint to the implementation that it can release any resources associated with the file.

      The file object can continue to be used after this method is called.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface FileObject
      Throws:
      FileSystemException - On error closing the file.
      See Also:
    • compareTo

      public int compareTo(FileObject fo)
      Specified by:
      compareTo in interface Comparable<FileObject>
    • copyFrom

      public void copyFrom(FileObject srcFile, FileSelector selector) throws FileSystemException
      Description copied from interface: FileObject
      Copies another file, and all its descendants, to this file.

      If this file does not exist, it is created. Its parent folder is also created, if necessary. If this file does exist, it is deleted first.

      This method is not transactional. If it fails and throws an exception, this file will potentially only be partially copied.

      Specified by:
      copyFrom in interface FileObject
      Parameters:
      srcFile - The source file to copy.
      selector - The selector to use to select which files to copy.
      Throws:
      FileSystemException - If this file is read-only, or if the source file does not exist, or on error copying the file.
    • createFile

      public void createFile() throws FileSystemException
      Description copied from interface: FileObject
      Creates this file, if it does not exist. Also creates any ancestor folders which do not exist. This method does nothing if the file already exists and is a file.
      Specified by:
      createFile in interface FileObject
      Throws:
      FileSystemException - If the file already exists with the wrong type, or the parent folder is read-only, or on error creating this file or one of its ancestors.
    • createFolder

      public void createFolder() throws FileSystemException
      Description copied from interface: FileObject
      Creates this folder, if it does not exist. Also creates any ancestor folders which do not exist. This method does nothing if the folder already exists.
      Specified by:
      createFolder in interface FileObject
      Throws:
      FileSystemException - If the folder already exists with the wrong type, or the parent folder is read-only, or on error creating this folder or one of its ancestors.
    • delete

      public boolean delete() throws FileSystemException
      Description copied from interface: FileObject
      Deletes this file. Does nothing if this file does not exist of if it is a folder that has children. Does not delete any descendants of this file, use FileObject.delete(FileSelector) or FileObject.deleteAll() for that.
      Specified by:
      delete in interface FileObject
      Returns:
      true if this object has been deleted
      Throws:
      FileSystemException - If this file is a non-empty folder, or if this file is read-only, or on error deleteing this file.
    • delete

      public int delete(FileSelector selector) throws FileSystemException
      Description copied from interface: FileObject
      Deletes all descendants of this file that match a selector. Does nothing if this file does not exist.

      This method is not transactional. If it fails and throws an exception, this file will potentially only be partially deleted.

      Specified by:
      delete in interface FileObject
      Parameters:
      selector - The selector to use to select which files to delete.
      Returns:
      the number of deleted objects
      Throws:
      FileSystemException - If this file or one of its descendants is read-only, or on error deleting this file or one of its descendants.
    • deleteAll

      public int deleteAll() throws FileSystemException
      Description copied from interface: FileObject
      Deletes this file and all children.
      Specified by:
      deleteAll in interface FileObject
      Returns:
      the number of deleted files.
      Throws:
      FileSystemException - if an error occurs.
      See Also:
    • exists

      public boolean exists() throws FileSystemException
      Description copied from interface: FileObject
      Determines if this file exists.
      Specified by:
      exists in interface FileObject
      Returns:
      true if this file exists, false if not.
      Throws:
      FileSystemException - On error determining if this file exists.
    • findFiles

      public FileObject[] findFiles(FileSelector selector) throws FileSystemException
      Description copied from interface: FileObject
      Finds the set of matching descendants of this file, in depthwise order.
      Specified by:
      findFiles in interface FileObject
      Parameters:
      selector - The selector to use to select matching files.
      Returns:
      The matching files. The files are returned in depthwise order (that is, a child appears in the list before its parent).
      Throws:
      FileSystemException - if an error occurs.
    • findFiles

      public void findFiles(FileSelector selector, boolean depthwise, List<FileObject> selected) throws FileSystemException
      Description copied from interface: FileObject
      Finds the set of matching descendants of this file.
      Specified by:
      findFiles in interface FileObject
      Parameters:
      selector - the selector used to determine if the file should be selected
      depthwise - controls the ordering in the list. e.g. deepest first
      selected - container for selected files. list needs not to be empty.
      Throws:
      FileSystemException - if an error occurs.
    • getChild

      public FileObject getChild(String name) throws FileSystemException
      Description copied from interface: FileObject
      Returns a child of this file. Note that this method returns null when the child does not exist. This differs from FileObject.resolveFile(String, NameScope) which never returns null.
      Specified by:
      getChild in interface FileObject
      Parameters:
      name - The name of the child.
      Returns:
      The child, or null if there is no such child.
      Throws:
      FileSystemException - If this file does not exist, or is not a folder, or on error determining this file's children.
    • getChildren

      public FileObject[] getChildren() throws FileSystemException
      Description copied from interface: FileObject
      Lists the children of this file.
      Specified by:
      getChildren in interface FileObject
      Returns:
      An array containing the children of this file. The array is unordered. If the file does not have any children, a zero-length array is returned. This method never returns null.
      Throws:
      FileSystemException - If this file does not exist, or is not a folder, or on error listing this file's children.
    • getContent

      public FileContent getContent() throws FileSystemException
      Description copied from interface: FileObject
      Returns this file's content. The FileContent returned by this method can be used to read and write the content of the file.

      This method can be called if the file does not exist, and the returned FileContent can be used to create the file by writing its content.

      Specified by:
      getContent in interface FileObject
      Returns:
      This file's content.
      Throws:
      FileSystemException - On error getting this file's content.
    • getDecoratedFileObject

      public FileObject getDecoratedFileObject()
    • getFileOperations

      public FileOperations getFileOperations() throws FileSystemException
      Specified by:
      getFileOperations in interface FileObject
      Returns:
      FileOperations interface that provides access to the operations API.
      Throws:
      FileSystemException - if an error occurs.
    • getFileSystem

      public FileSystem getFileSystem()
      Description copied from interface: FileObject
      Returns the file system that contains this file.
      Specified by:
      getFileSystem in interface FileObject
      Returns:
      The file system.
    • getPublicURIString

      public String getPublicURIString()
      Description copied from interface: FileObject
      Returns the receiver as a URI String for public display, like, without a password.
      Specified by:
      getPublicURIString in interface FileObject
      Returns:
      A URI String without a password, never null.
    • getName

      public FileName getName()
      Description copied from interface: FileObject
      Returns the name of this file.
      Specified by:
      getName in interface FileObject
      Returns:
      the FileName.
    • getParent

      public FileObject getParent() throws FileSystemException
      Description copied from interface: FileObject
      Returns the folder that contains this file.
      Specified by:
      getParent in interface FileObject
      Returns:
      The folder that contains this file. Returns null if this file is the root of a file system.
      Throws:
      FileSystemException - On error finding the file's parent.
    • getType

      public FileType getType() throws FileSystemException
      Description copied from interface: FileObject
      Returns this file's type.
      Specified by:
      getType in interface FileObject
      Returns:
      One of the FileType constants. Never returns null.
      Throws:
      FileSystemException - On error determining the file's type.
    • getURL

      public URL getURL() throws FileSystemException
      Description copied from interface: FileObject
      Returns a URL representing this file.
      Specified by:
      getURL in interface FileObject
      Returns:
      the URL for the file.
      Throws:
      FileSystemException - if an error occurs.
    • isAttached

      public boolean isAttached()
      Description copied from interface: FileObject
      Checks if the fileObject is attached.
      Specified by:
      isAttached in interface FileObject
      Returns:
      true if the FileObject is attached.
    • isContentOpen

      public boolean isContentOpen()
      Description copied from interface: FileObject
      Checks if someone reads/write to this file.
      Specified by:
      isContentOpen in interface FileObject
      Returns:
      true if the file content is open.
    • isExecutable

      public boolean isExecutable() throws FileSystemException
      Description copied from interface: FileObject
      Determines if this file is executable.
      Specified by:
      isExecutable in interface FileObject
      Returns:
      true if this file is executable, false if not.
      Throws:
      FileSystemException - On error determining if this file exists.
    • isFile

      public boolean isFile() throws FileSystemException
      Description copied from interface: FileObject
      Checks if this file is a regular file.
      Specified by:
      isFile in interface FileObject
      Returns:
      true if this file is a regular file.
      Throws:
      FileSystemException - if an error occurs.
      See Also:
    • isFolder

      public boolean isFolder() throws FileSystemException
      Description copied from interface: FileObject
      Checks if this file is a folder.
      Specified by:
      isFolder in interface FileObject
      Returns:
      true if this file is a folder.
      Throws:
      FileSystemException - if an error occurs.
      See Also:
    • isHidden

      public boolean isHidden() throws FileSystemException
      Description copied from interface: FileObject
      Determines if this file is hidden.
      Specified by:
      isHidden in interface FileObject
      Returns:
      true if this file is hidden, false if not.
      Throws:
      FileSystemException - On error determining if this file exists.
    • isReadable

      public boolean isReadable() throws FileSystemException
      Description copied from interface: FileObject
      Determines if this file can be read.
      Specified by:
      isReadable in interface FileObject
      Returns:
      true if this file is readable, false if not.
      Throws:
      FileSystemException - On error determining if this file exists.
    • isWriteable

      public boolean isWriteable() throws FileSystemException
      Description copied from interface: FileObject
      Determines if this file can be written to.
      Specified by:
      isWriteable in interface FileObject
      Returns:
      true if this file is writable, false if not.
      Throws:
      FileSystemException - On error determining if this file exists.
    • iterator

      public Iterator<FileObject> iterator()
      Specified by:
      iterator in interface Iterable<FileObject>
    • moveTo

      public void moveTo(FileObject destFile) throws FileSystemException
      Description copied from interface: FileObject
      Move this file.

      If the destFile exists, it is deleted first.

      Specified by:
      moveTo in interface FileObject
      Parameters:
      destFile - the New file name.
      Throws:
      FileSystemException - If this file is read-only, or if the source file does not exist, or on error copying the file.
    • refresh

      public void refresh() throws FileSystemException
      Description copied from interface: FileObject
      This will prepare the fileObject to get resynchronized with the underlying file system if required.
      Specified by:
      refresh in interface FileObject
      Throws:
      FileSystemException - if an error occurs.
    • resolveFile

      public FileObject resolveFile(String path) throws FileSystemException
      Description copied from interface: FileObject
      Finds a file, relative to this file. Equivalent to calling resolveFile( path, NameScope.FILE_SYSTEM ).
      Specified by:
      resolveFile in interface FileObject
      Parameters:
      path - The path of the file to locate. Can either be a relative path or an absolute path.
      Returns:
      The file.
      Throws:
      FileSystemException - On error parsing the path, or on error finding the file.
    • resolveFile

      public FileObject resolveFile(String name, NameScope scope) throws FileSystemException
      Description copied from interface: FileObject
      Finds a file relative to this file. Refer to NameScope for a description of how names are resolved in the different scopes.
      Specified by:
      resolveFile in interface FileObject
      Parameters:
      name - The name to resolve.
      scope - the NameScope for the file.
      Returns:
      The file.
      Throws:
      FileSystemException - On error parsing the path, or on error finding the file.
    • setExecutable

      public boolean setExecutable(boolean executable, boolean ownerOnly) throws FileSystemException
      Description copied from interface: FileObject
      Sets the owner's (or everybody's) write permission.
      Specified by:
      setExecutable in interface FileObject
      Parameters:
      executable - True to allow read access, false to disallow.
      ownerOnly - If true, the permission applies only to the owner; otherwise, it applies to everybody.
      Returns:
      true if the operation succeeded.
      Throws:
      FileSystemException - On error determining if this file exists.
    • setReadable

      public boolean setReadable(boolean readable, boolean ownerOnly) throws FileSystemException
      Description copied from interface: FileObject
      Sets the owner's (or everybody's) read permission.
      Specified by:
      setReadable in interface FileObject
      Parameters:
      readable - True to allow read access, false to disallow
      ownerOnly - If true, the permission applies only to the owner; otherwise, it applies to everybody.
      Returns:
      true if the operation succeeded
      Throws:
      FileSystemException - On error determining if this file exists.
    • setWritable

      public boolean setWritable(boolean writable, boolean ownerOnly) throws FileSystemException
      Description copied from interface: FileObject
      Sets the owner's (or everybody's) write permission.
      Specified by:
      setWritable in interface FileObject
      Parameters:
      writable - True to allow read access, false to disallow
      ownerOnly - If true, the permission applies only to the owner; otherwise, it applies to everybody.
      Returns:
      true if the operation succeeded
      Throws:
      FileSystemException - On error determining if this file exists.
    • toString

      public String toString()
      Overrides:
      toString in class Object