Class AbstractFileName

java.lang.Object
org.apache.commons.vfs2.provider.AbstractFileName
All Implemented Interfaces:
Comparable<FileName>, FileName
Direct Known Subclasses:
GenericFileName, LayeredFileName, LocalFileName, ResourceFileName, VirtualFileName

public abstract class AbstractFileName extends Object implements FileName
A default file name implementation.
  • Constructor Details

    • AbstractFileName

      public AbstractFileName(String scheme, String absolutePath, FileType type)
      Constructs a new instance for subclasses.
      Parameters:
      scheme - The scheme.
      absolutePath - the absolute path, maybe empty or null.
      type - the file type.
  • Method Details

    • checkName

      public static boolean checkName(String basePath, String path, NameScope scope)
      Checks whether a path fits in a particular scope of another path.
      Parameters:
      basePath - An absolute, normalized path.
      path - An absolute, normalized path.
      scope - The NameScope.
      Returns:
      true if the path fits in the scope, false otherwise.
    • appendRootUri

      protected abstract void appendRootUri(StringBuilder buffer, boolean addPassword)
      Builds the root URI for this file name. Note that the root URI must not end with a separator character.
      Parameters:
      buffer - A StringBuilder to use to construct the URI.
      addPassword - true if the password should be added, false otherwise.
    • compareTo

      public int compareTo(FileName obj)
      Implement Comparable.
      Specified by:
      compareTo in interface Comparable<FileName>
      Parameters:
      obj - another abstract file name
      Returns:
      negative number if less than, 0 if equal, positive if greater than.
    • createName

      public abstract FileName createName(String absolutePath, FileType fileType)
      Factory method for creating name instances.
      Parameters:
      absolutePath - The absolute path.
      fileType - The FileType.
      Returns:
      The FileName.
    • createURI

      protected String createURI()
      Creates a URI.
      Returns:
      a URI.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • getBaseName

      public String getBaseName()
      Returns the base name of the file.
      Specified by:
      getBaseName in interface FileName
      Returns:
      The base name of the file.
    • getDepth

      public int getDepth()
      Returns the depth of this file name, within its file system.
      Specified by:
      getDepth in interface FileName
      Returns:
      The depth of the file name.
    • getExtension

      public String getExtension()
      Returns the extension of this file name.
      Specified by:
      getExtension in interface FileName
      Returns:
      The file extension.
    • getFriendlyURI

      Returns the URI without a password.
      Specified by:
      getFriendlyURI in interface FileName
      Returns:
      the URI without a password.
    • getParent

      public FileName getParent()
      Returns the name of the parent of the file.
      Specified by:
      getParent in interface FileName
      Returns:
      the FileName of the parent.
    • getPath

      public String getPath()
      Returns the absolute path of the file, relative to the root of the file system that the file belongs to.
      Specified by:
      getPath in interface FileName
      Returns:
      The path String.
    • getPathDecoded

      Returns the decoded path.
      Specified by:
      getPathDecoded in interface FileName
      Returns:
      The decoded path String.
      Throws:
      FileSystemException - If an error occurs.
    • getRelativeName

      Converts a file name to a relative name, relative to this file name.
      Specified by:
      getRelativeName in interface FileName
      Parameters:
      name - The FileName.
      Returns:
      The relative path to the file.
      Throws:
      FileSystemException - if an error occurs.
    • getRoot

      public FileName getRoot()
      find the root of the file system.
      Specified by:
      getRoot in interface FileName
      Returns:
      The root FileName.
    • getRootURI

      public String getRootURI()
      Returns the root URI of the file system this file belongs to.
      Specified by:
      getRootURI in interface FileName
      Returns:
      The URI of the root.
    • getScheme

      public String getScheme()
      Returns the URI scheme of this file.
      Specified by:
      getScheme in interface FileName
      Returns:
      The protocol used to access the file.
    • getType

      public FileType getType()
      Returns the requested or current type of this name.

      The "requested" type is the one determined during resolving the name. n this case the name is a FileType.FOLDER if it ends with an "/" else it will be a FileType.FILE.

      Once attached it will be changed to reflect the real type of this resource.

      Specified by:
      getType in interface FileName
      Returns:
      FileType.FOLDER or FileType.FILE
    • getURI

      public String getURI()
      Returns the absolute URI of the file.
      Specified by:
      getURI in interface FileName
      Returns:
      The absolute URI of the file.
    • getUriTrailer

      protected String getUriTrailer()
      Gets the string to end a URI.
      Returns:
      the string to end a URI
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isAncestor

      public boolean isAncestor(FileName ancestor)
      Determines if another file name is an ancestor of this file name.
      Specified by:
      isAncestor in interface FileName
      Parameters:
      ancestor - The FileName to check.
      Returns:
      true if the FileName is an ancestor, false otherwise.
    • isDescendent

      public boolean isDescendent(FileName descendent)
      Determines if another file name is a descendent of this file name.
      Specified by:
      isDescendent in interface FileName
      Parameters:
      descendent - The FileName to check.
      Returns:
      true if the FileName is a descendent, false otherwise.
    • isDescendent

      public boolean isDescendent(FileName descendent, NameScope scope)
      Determines if another file name is a descendent of this file name.
      Specified by:
      isDescendent in interface FileName
      Parameters:
      descendent - The FileName to check.
      scope - The NameScope.
      Returns:
      true if the FileName is a descendent, false otherwise.
    • isFile

      public boolean isFile() throws FileSystemException
      Checks if this file name is a name for a regular file by using its type.
      Specified by:
      isFile in interface FileName
      Returns:
      true if this file is a regular file.
      Throws:
      FileSystemException - may be thrown by subclasses.
      See Also:
    • toString

      public String toString()
      Returns the URI of the file.
      Overrides:
      toString in class Object
      Returns:
      the FileName as a URI.