Class FTPFileStrategy
- java.lang.Object
-
- com.github.robtimus.filesystems.ftp.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 Summary
Constructors Constructor Description FTPFileStrategy()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static FTPFileStrategyautoDetect()Returns a strategy that will detect whether or not an FTP file system is Unix-like or not.protected StringfileName(Path path)Returns a path's file name.protected abstract List<FTPFile>getChildren(FTPClient client, Path path, FileSystemExceptionFactory exceptionFactory)Returns the direct children for a path.protected abstract FTPFilegetFTPFile(FTPClient client, Path path, FileSystemExceptionFactory exceptionFactory)Returns a single FTP file.protected abstract FTPFilegetLink(FTPClient client, FTPFile ftpFile, Path path, FileSystemExceptionFactory exceptionFactory)Returns an FTP file representing a link.protected voidinitialize(FTPClient client)Initializes the FTP file strategy.static FTPFileStrategynonUnix()Returns a strategy for non-Unix-like FTP file systems.protected StringparentPath(Path path)Returns a path's parent path.protected Stringpath(Path path)Returns a path's full path.protected voidthrowIfEmpty(FTPFile[] ftpFiles, Path path, FTPClient client, FileSystemExceptionFactory exceptionFactory)Throws aFileSystemExceptionif the given array of FTP files is empty.static FTPFileStrategyunix()Returns a strategy for Unix-like FTP file systems.
-
-
-
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 ifFTPFile.getLink()is notnull, 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
nullif 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
nullif the path has no parent.
-
throwIfEmpty
protected final void throwIfEmpty(FTPFile[] ftpFiles, Path path, FTPClient client, FileSystemExceptionFactory exceptionFactory) throws FileSystemException
Throws aFileSystemExceptionif the given array of FTP files is empty. This method will delegate toFileSystemExceptionFactory.createGetFileException(String, int, String)if needed.- Parameters:
ftpFiles- The array of FTP files to check.path- The path that was used to retrieve the FTP files.client- The FTP client that was used to retrieve the FTP files.exceptionFactory- The file system exception factory to use.- Throws:
FileSystemException- If the given array of FTP files is empty.
-
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.
-
-