Class FTPFileStrategy


  • public abstract class FTPFileStrategy
    extends Object
    A strategy for handling FTP files in an FTP server specific way. This will help support FTP servers that return the current directory (.) when listing directories, and FTP servers that don't.
    Author:
    Rob Spoor
    • Constructor Detail

      • FTPFileStrategy

        public FTPFileStrategy()
    • Method Detail

      • initialize

        protected void initialize​(FTPClient client)
                           throws IOException
        Initializes the FTP file strategy. This method should be called only once, before calling any other method. This default implementation does nothing.
        Parameters:
        client - The FTP client to use for initialization.
        Throws:
        IOException - If an I/O error occurs.
      • getChildren

        protected abstract List<FTPFile> getChildren​(FTPClient client,
                                                     Path path,
                                                     FileSystemExceptionFactory exceptionFactory)
                                              throws IOException
        Returns the direct children for a path.
        Parameters:
        client - The FTP client to use.
        path - The path to return the direct children for.
        exceptionFactory - The file system exception factory to use.
        Returns:
        The direct children for the given path.
        Throws:
        NoSuchFileException - If the given path does not exist.
        NotDirectoryException - If the given path does not represent a directory.
        IOException - If an I/O error occurs.
      • getFTPFile

        protected abstract FTPFile getFTPFile​(FTPClient client,
                                              Path path,
                                              FileSystemExceptionFactory exceptionFactory)
                                       throws IOException
        Returns a single FTP file.
        Parameters:
        client - The FTP client to use.
        path - The path to return the matching FTP file for.
        exceptionFactory - The file system exception factory to use.
        Returns:
        The FTP file matching the given path.
        Throws:
        NoSuchFileException - If the given path does not exist.
        IOException - If an I/O error occurs.
      • getLink

        protected abstract FTPFile getLink​(FTPClient client,
                                           FTPFile ftpFile,
                                           Path path,
                                           FileSystemExceptionFactory exceptionFactory)
                                    throws IOException
        Returns an FTP file representing a link. This can be as simple as returning the object if FTPFile.getLink() is not null, or it can be more complex.
        Parameters:
        client - The FTP client to use.
        ftpFile - The FTP file that represents the possible link.
        path - The path to the FTP file.
        exceptionFactory - The file system exception factory to use.
        Returns:
        An FTP file representing a link if the given FTP file and path represent a link, or null if they represent a non-link.
        Throws:
        IOException - If an I/O error occurs.
      • fileName

        protected final String fileName​(Path path)
        Returns a path's file name. This method should only be called by sub classes to retrieve the file name of paths passed to their methods.
        Parameters:
        path - The path to return the file name of.
        Returns:
        The file name of the given path.
      • path

        protected final String path​(Path path)
        Returns a path's full path. This method should only be called by sub classes to retrieve the full path of paths passed to their methods.
        Parameters:
        path - The path to return the full path of.
        Returns:
        The full path of the given path.
      • parentPath

        protected final String parentPath​(Path path)
        Returns a path's parent path. This method should only be called by sub classes to retrieve the parent path of paths passed to their methods.
        Parameters:
        path - The path to return the parent path of.
        Returns:
        The parent path of the given path, or null if the path has no parent.
      • unix

        public static FTPFileStrategy unix()
        Returns a strategy for Unix-like FTP file systems. It is assumed that these return an entry for the current directory (.) when listing directories. It is also assumed that these support absolute paths to list files.
        Returns:
        A strategy for Unix-like FTP file systems.
      • nonUnix

        public static FTPFileStrategy nonUnix()
        Returns a strategy for non-Unix-like FTP file systems. It is assumed that these do not return an entry for the current directory (.) when listing directories. As a result, this strategy will list a file's parent to get information about a file.

        This strategy should be used for FTP file systems that do not support absolute paths to list files.

        Returns:
        A strategy for non-Unix-like FTP file systems.
      • autoDetect

        public static FTPFileStrategy autoDetect()
        Returns a strategy that will detect whether or not an FTP file system is Unix-like or not. It will do so by listing the root and checking for the presence of an entry for the current directory (.).
        Returns:
        A strategy that will detect whether or not an FTP file system is Unix-like or not.