Class FTPFileSystemProvider
- java.lang.Object
-
- java.nio.file.spi.FileSystemProvider
-
- com.github.robtimus.filesystems.ftp.FTPFileSystemProvider
-
- Direct Known Subclasses:
FTPSFileSystemProvider
public class FTPFileSystemProvider extends FileSystemProvider
A provider for FTP file systems.- Author:
- Rob Spoor
-
-
Constructor Summary
Constructors Constructor Description FTPFileSystemProvider()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckAccess(Path path, AccessMode... modes)voidcopy(Path source, Path target, CopyOption... options)Copy a file to a target file.voidcreateDirectory(Path dir, FileAttribute<?>... attrs)Creates a new directory.voiddelete(Path path)<V extends FileAttributeView>
VgetFileAttributeView(Path path, Class<V> type, LinkOption... options)Returns a file attribute view of a given type.FileStoregetFileStore(Path path)FileSystemgetFileSystem(URI uri)Returns an existingFileSystemcreated by this provider.PathgetPath(URI uri)Return aPathobject by converting the givenURI.StringgetScheme()Returns the URI scheme that identifies this provider:ftp.booleanisHidden(Path path)booleanisSameFile(Path path, Path path2)static voidkeepAlive(FileSystem fs)Send a keep-alive signal for an FTP file system.voidmove(Path source, Path target, CopyOption... options)Move or rename a file to a target file.SeekableByteChannelnewByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs)Opens or creates a file, returning a seekable byte channel to access the file.DirectoryStream<Path>newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter)FileSystemnewFileSystem(URI uri, Map<String,?> env)Constructs a newFileSystemobject identified by a URI.InputStreamnewInputStream(Path path, OpenOption... options)Opens a file, returning an input stream to read from the file.OutputStreamnewOutputStream(Path path, OpenOption... options)Opens or creates a file, returning an output stream that may be used to write bytes to the file.<A extends BasicFileAttributes>
AreadAttributes(Path path, Class<A> type, LinkOption... options)Reads a file's attributes as a bulk operation.Map<String,Object>readAttributes(Path path, String attributes, LinkOption... options)Reads a set of file attributes as a bulk operation.PathreadSymbolicLink(Path link)voidsetAttribute(Path path, String attribute, Object value, LinkOption... options)Sets the value of a file attribute.-
Methods inherited from class java.nio.file.spi.FileSystemProvider
createLink, createSymbolicLink, deleteIfExists, installedProviders, newAsynchronousFileChannel, newFileChannel, newFileSystem
-
-
-
-
Method Detail
-
getScheme
public String getScheme()
Returns the URI scheme that identifies this provider:ftp.- Specified by:
getSchemein classFileSystemProvider
-
newFileSystem
public FileSystem newFileSystem(URI uri, Map<String,?> env) throws IOException
Constructs a newFileSystemobject identified by a URI.The URI must have a
schemeequal togetScheme(), and noqueryorfragment. Authentication credentials can be set either through the URI'suser information, or through the given environment map, preferably throughFTPEnvironment. The default directory can be set either through the URI'spathor through the given environment map, preferably throughFTPEnvironment.This provider allows multiple file systems per host, but only one file system per user on a host. Once a file system is
closed, this provider allows a new file system to be created with the same URI and credentials as the closed file system.- Specified by:
newFileSystemin classFileSystemProvider- Throws:
IOException
-
getFileSystem
public FileSystem getFileSystem(URI uri)
Returns an existingFileSystemcreated by this provider.The URI must have a
schemeequal togetScheme(), and no non-emptypath,queryorfragment. Because the original credentials were possibly provided through an environment map, the URI can containuser information, although this should not contain a password for security reasons.Once a file system is
closed, this provider will throw aFileSystemNotFoundException.- Specified by:
getFileSystemin classFileSystemProvider
-
getPath
public Path getPath(URI uri)
Return aPathobject by converting the givenURI. The resultingPathis associated with aFileSystemthat already exists, or is constructed automatically.The URI must have a
schemeequal togetScheme(), and nofragment. Because the original credentials were possibly provided through an environment map, the URI can containuser information, although for security reasons this should only contain a password to support automatically creating file systems.If no matching file system existed yet, a new one is created. The default environment for
FTPorFTPSis used for this, to allow configuring the resulting file system. URI specific settings can also be provided through thequery; see usages ofFTPEnvironment.QueryParamandFTPEnvironment.QueryParamsfor the possible query parameters.Remember to close any newly created file system.
- Specified by:
getPathin classFileSystemProvider
-
newInputStream
public InputStream newInputStream(Path path, OpenOption... options) throws IOException
Opens a file, returning an input stream to read from the file. This method works in exactly the manner specified by theFiles.newInputStream(Path, OpenOption...)method.In addition to the standard open options, this method also supports single occurrences of each of
FileType,FileStructureandFileTransferMode. These three option types, with defaults ofFileType.binary(),FileStructure.FILEandFileTransferMode.STREAM, persist for all calls that support file transfers:newInputStream(Path, OpenOption...)newOutputStream(Path, OpenOption...)newByteChannel(Path, Set, FileAttribute...)copy(Path, Path, CopyOption...)move(Path, Path, CopyOption...)
Note: while the returned input stream is not closed, the path's file system will have one available connection fewer. It is therefore essential that the input stream is closed as soon as possible.
- Overrides:
newInputStreamin classFileSystemProvider- Throws:
IOException
-
newOutputStream
public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException
Opens or creates a file, returning an output stream that may be used to write bytes to the file. This method works in exactly the manner specified by theFiles.newOutputStream(Path, OpenOption...)method.In addition to the standard open options, this method also supports single occurrences of each of
FileType,FileStructureandFileTransferMode. These three option types, with defaults ofFileType.binary(),FileStructure.FILEandFileTransferMode.STREAM, persist for all calls that support file transfers:newInputStream(Path, OpenOption...)newOutputStream(Path, OpenOption...)newByteChannel(Path, Set, FileAttribute...)copy(Path, Path, CopyOption...)move(Path, Path, CopyOption...)
Note: while the returned output stream is not closed, the path's file system will have one available connection fewer. It is therefore essential that the output stream is closed as soon as possible.
- Overrides:
newOutputStreamin classFileSystemProvider- Throws:
IOException
-
newByteChannel
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
Opens or creates a file, returning a seekable byte channel to access the file. This method works in exactly the manner specified by theFiles.newByteChannel(Path, Set, FileAttribute...)method.In addition to the standard open options, this method also supports single occurrences of each of
FileType,FileStructureandFileTransferMode. These three option types, with defaults ofFileType.binary(),FileStructure.FILEandFileTransferMode.STREAM, persist for all calls that support file transfers:newInputStream(Path, OpenOption...)newOutputStream(Path, OpenOption...)newByteChannel(Path, Set, FileAttribute...)copy(Path, Path, CopyOption...)move(Path, Path, CopyOption...)
This method does not support any file attributes to be set. If any file attributes are given, an
UnsupportedOperationExceptionwill be thrown.Note: while the returned channel is not closed, the path's file system will have one available connection fewer. It is therefore essential that the channel is closed as soon as possible.
- Specified by:
newByteChannelin classFileSystemProvider- Throws:
IOException
-
newDirectoryStream
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException
- Specified by:
newDirectoryStreamin classFileSystemProvider- Throws:
IOException
-
createDirectory
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException
Creates a new directory. This method works in exactly the manner specified by theFiles.createDirectory(Path, FileAttribute...)method.This method does not support any file attributes to be set. If any file attributes are given, an
UnsupportedOperationExceptionwill be thrown.- Specified by:
createDirectoryin classFileSystemProvider- Throws:
IOException
-
delete
public void delete(Path path) throws IOException
- Specified by:
deletein classFileSystemProvider- Throws:
IOException
-
readSymbolicLink
public Path readSymbolicLink(Path link) throws IOException
- Overrides:
readSymbolicLinkin classFileSystemProvider- Throws:
IOException
-
copy
public void copy(Path source, Path target, CopyOption... options) throws IOException
Copy a file to a target file. This method works in exactly the manner specified by theFiles.copy(Path, Path, CopyOption...)method except that both the source and target paths must be associated with this provider.In addition to the standard copy options, this method also supports single occurrences of each of
FileType,FileStructureandFileTransferMode. These three option types, with defaults ofFileType.binary(),FileStructure.FILEandFileTransferMode.STREAM, persist for all calls that support file transfers:newInputStream(Path, OpenOption...)newOutputStream(Path, OpenOption...)newByteChannel(Path, Set, FileAttribute...)copy(Path, Path, CopyOption...)move(Path, Path, CopyOption...)
StandardCopyOption.COPY_ATTRIBUTESandStandardCopyOption.ATOMIC_MOVEare not supported though.- Specified by:
copyin classFileSystemProvider- Throws:
IOException
-
move
public void move(Path source, Path target, CopyOption... options) throws IOException
Move or rename a file to a target file. This method works in exactly the manner specified by theFiles.move(Path, Path, CopyOption...)method except that both the source and target paths must be associated with this provider.In addition to the standard copy options, this method also supports single occurrences of each of
FileType,FileStructureandFileTransferMode. These three option types, with defaults ofFileType.binary(),FileStructure.FILEandFileTransferMode.STREAM, persist for all calls that support file transfers:newInputStream(Path, OpenOption...)newOutputStream(Path, OpenOption...)newByteChannel(Path, Set, FileAttribute...)copy(Path, Path, CopyOption...)move(Path, Path, CopyOption...)
StandardCopyOption.COPY_ATTRIBUTESis not supported though.StandardCopyOption.ATOMIC_MOVEis only supported if the paths have the same file system.- Specified by:
movein classFileSystemProvider- Throws:
IOException
-
isSameFile
public boolean isSameFile(Path path, Path path2) throws IOException
- Specified by:
isSameFilein classFileSystemProvider- Throws:
IOException
-
isHidden
public boolean isHidden(Path path) throws IOException
- Specified by:
isHiddenin classFileSystemProvider- Throws:
IOException
-
getFileStore
public FileStore getFileStore(Path path) throws IOException
- Specified by:
getFileStorein classFileSystemProvider- Throws:
IOException
-
checkAccess
public void checkAccess(Path path, AccessMode... modes) throws IOException
- Specified by:
checkAccessin classFileSystemProvider- Throws:
IOException
-
getFileAttributeView
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options)
Returns a file attribute view of a given type. This method works in exactly the manner specified by theFiles.getFileAttributeView(Path, Class, LinkOption...)method.This provider supports
BasicFileAttributeView,FileOwnerAttributeViewandPosixFileAttributeView. All other classes will result in anullreturn value.Note that the returned
FileAttributeViewis read-only; any attempt to change any attributes through the view will result in anUnsupportedOperationExceptionto be thrown.- Specified by:
getFileAttributeViewin classFileSystemProvider
-
readAttributes
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException
Reads a file's attributes as a bulk operation. This method works in exactly the manner specified by theFiles.readAttributes(Path, Class, LinkOption...)method.This provider supports
BasicFileAttributesandPosixFileAttributes(there is noFileOwnerFileAttributes). All other classes will result in anUnsupportedOperationExceptionto be thrown.- Specified by:
readAttributesin classFileSystemProvider- Throws:
IOException
-
readAttributes
public Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException
Reads a set of file attributes as a bulk operation. This method works in exactly the manner specified by theFiles.readAttributes(Path, String, LinkOption...)method.This provider supports views
basic,ownerand {code posix}, wherebasicwill be used if no view is given. All other views will result in anUnsupportedOperationExceptionto be thrown.- Specified by:
readAttributesin classFileSystemProvider- Throws:
IOException
-
setAttribute
public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException
Sets the value of a file attribute. This method works in exactly the manner specified by theFiles.setAttribute(Path, String, Object, LinkOption...)method.This provider does not support attributes for paths to be set. This method will always throw an
UnsupportedOperationException.- Specified by:
setAttributein classFileSystemProvider- Throws:
IOException
-
keepAlive
public static void keepAlive(FileSystem fs) throws IOException
Send a keep-alive signal for an FTP file system.- Parameters:
fs- The FTP file system to send a keep-alive signal for.- Throws:
ProviderMismatchException- If the given file system is not an FTP file system (not created by anFTPFileSystemProvider).IOException- If an I/O error occurred.
-
-