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 void
checkAccess(Path path, AccessMode... modes)
void
copy(Path source, Path target, CopyOption... options)
Copy a file to a target file.void
createDirectory(Path dir, FileAttribute<?>... attrs)
Creates a new directory.void
delete(Path path)
<V extends FileAttributeView>
VgetFileAttributeView(Path path, Class<V> type, LinkOption... options)
Returns a file attribute view of a given type.FileStore
getFileStore(Path path)
FileSystem
getFileSystem(URI uri)
Returns an existingFileSystem
created by this provider.Path
getPath(URI uri)
Return aPath
object by converting the givenURI
.String
getScheme()
Returns the URI scheme that identifies this provider:ftp
.boolean
isHidden(Path path)
boolean
isSameFile(Path path, Path path2)
static void
keepAlive(FileSystem fs)
Send a keep-alive signal for an FTP file system.void
move(Path source, Path target, CopyOption... options)
Move or rename a file to a target file.SeekableByteChannel
newByteChannel(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)
FileSystem
newFileSystem(URI uri, Map<String,?> env)
Constructs a newFileSystem
object identified by a URI.InputStream
newInputStream(Path path, OpenOption... options)
Opens a file, returning an input stream to read from the file.OutputStream
newOutputStream(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.Path
readSymbolicLink(Path link)
void
setAttribute(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:
getScheme
in classFileSystemProvider
-
newFileSystem
public FileSystem newFileSystem(URI uri, Map<String,?> env) throws IOException
Constructs a newFileSystem
object identified by a URI.The URI must have a
scheme
equal togetScheme()
, and noquery
orfragment
. 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'spath
or 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:
newFileSystem
in classFileSystemProvider
- Throws:
IOException
-
getFileSystem
public FileSystem getFileSystem(URI uri)
Returns an existingFileSystem
created by this provider.The URI must have a
scheme
equal togetScheme()
, and no non-emptypath
,query
orfragment
. 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:
getFileSystem
in classFileSystemProvider
-
getPath
public Path getPath(URI uri)
Return aPath
object by converting the givenURI
. The resultingPath
is associated with aFileSystem
that already exists, or is constructed automatically.The URI must have a
scheme
equal 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
FTP
orFTPS
is used for this, to allow configuring the resulting file system. URI specific settings can also be provided through thequery
; see usages ofFTPEnvironment.QueryParam
andFTPEnvironment.QueryParams
for the possible query parameters.Remember to close any newly created file system.
- Specified by:
getPath
in 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
,FileStructure
andFileTransferMode
. These three option types, with defaults ofFileType.binary()
,FileStructure.FILE
andFileTransferMode.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:
newInputStream
in 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
,FileStructure
andFileTransferMode
. These three option types, with defaults ofFileType.binary()
,FileStructure.FILE
andFileTransferMode.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:
newOutputStream
in 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
,FileStructure
andFileTransferMode
. These three option types, with defaults ofFileType.binary()
,FileStructure.FILE
andFileTransferMode.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
UnsupportedOperationException
will 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:
newByteChannel
in classFileSystemProvider
- Throws:
IOException
-
newDirectoryStream
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException
- Specified by:
newDirectoryStream
in 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
UnsupportedOperationException
will be thrown.- Specified by:
createDirectory
in classFileSystemProvider
- Throws:
IOException
-
delete
public void delete(Path path) throws IOException
- Specified by:
delete
in classFileSystemProvider
- Throws:
IOException
-
readSymbolicLink
public Path readSymbolicLink(Path link) throws IOException
- Overrides:
readSymbolicLink
in 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
,FileStructure
andFileTransferMode
. These three option types, with defaults ofFileType.binary()
,FileStructure.FILE
andFileTransferMode.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_ATTRIBUTES
andStandardCopyOption.ATOMIC_MOVE
are not supported though.- Specified by:
copy
in 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
,FileStructure
andFileTransferMode
. These three option types, with defaults ofFileType.binary()
,FileStructure.FILE
andFileTransferMode.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_ATTRIBUTES
is not supported though.StandardCopyOption.ATOMIC_MOVE
is only supported if the paths have the same file system.- Specified by:
move
in classFileSystemProvider
- Throws:
IOException
-
isSameFile
public boolean isSameFile(Path path, Path path2) throws IOException
- Specified by:
isSameFile
in classFileSystemProvider
- Throws:
IOException
-
isHidden
public boolean isHidden(Path path) throws IOException
- Specified by:
isHidden
in classFileSystemProvider
- Throws:
IOException
-
getFileStore
public FileStore getFileStore(Path path) throws IOException
- Specified by:
getFileStore
in classFileSystemProvider
- Throws:
IOException
-
checkAccess
public void checkAccess(Path path, AccessMode... modes) throws IOException
- Specified by:
checkAccess
in 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
,FileOwnerAttributeView
andPosixFileAttributeView
. All other classes will result in anull
return value.Note that the returned
FileAttributeView
is read-only; any attempt to change any attributes through the view will result in anUnsupportedOperationException
to be thrown.- Specified by:
getFileAttributeView
in 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
BasicFileAttributes
andPosixFileAttributes
(there is noFileOwnerFileAttributes
). All other classes will result in anUnsupportedOperationException
to be thrown.- Specified by:
readAttributes
in 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
,owner
and {code posix}, wherebasic
will be used if no view is given. All other views will result in anUnsupportedOperationException
to be thrown.- Specified by:
readAttributes
in 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:
setAttribute
in 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.
-
-