public class SFTPFileSystemProvider extends FileSystemProvider
Constructor and Description |
---|
SFTPFileSystemProvider() |
Modifier and Type | Method and 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> |
getFileAttributeView(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 existing
FileSystem created by this provider. |
Path |
getPath(URI uri)
Return a
Path object by converting the given URI . |
String |
getScheme()
Returns the URI scheme that identifies this provider:
sftp . |
boolean |
isHidden(Path path) |
boolean |
isSameFile(Path path,
Path path2) |
static void |
keepAlive(FileSystem fs)
Send a keep-alive signal for an SFTP 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 new
FileSystem 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> |
readAttributes(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.
|
createLink, createSymbolicLink, deleteIfExists, installedProviders, newAsynchronousFileChannel, newFileChannel, newFileSystem
public String getScheme()
sftp
.getScheme
in class FileSystemProvider
public FileSystem newFileSystem(URI uri, Map<String,?> env) throws IOException
FileSystem
object identified by a URI.
The URI must have a scheme
equal to getScheme()
, and no query
or
fragment
. Authentication credentials can be set either through the URI's user information
,
or through the given environment map, preferably through SFTPEnvironment
. The default directory can be set either through the URI's
path
or through the given environment map, preferably through SFTPEnvironment
.
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.
newFileSystem
in class FileSystemProvider
IOException
public FileSystem getFileSystem(URI uri)
FileSystem
created by this provider.
The URI must have a scheme
equal to getScheme()
, and no non-empty path
,
query
or fragment
. Because the original credentials were possibly provided through an
environment map, the URI can contain user information
, although this should not contain a password for security
reasons.
Once a file system is closed
, this provider will throw a FileSystemNotFoundException
.
getFileSystem
in class FileSystemProvider
public Path getPath(URI uri)
Path
object by converting the given URI
. The resulting Path
is associated with a FileSystem
that
already exists or is constructed automatically.
The URI must have a scheme
equal to getScheme()
, and no fragment
. Because the
original credentials were possibly provided through an environment map, the URI can contain user 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
is
used for this, to allow configuring the resulting file system. URI specific settings can also be provided through the
query
; see usages of SFTPEnvironment.QueryParam
and SFTPEnvironment.QueryParams
for the possible query parameters.
Remember to close any newly created file system.
getPath
in class FileSystemProvider
public InputStream newInputStream(Path path, OpenOption... options) throws IOException
Files.newInputStream(Path, OpenOption...)
method.
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.
newInputStream
in class FileSystemProvider
IOException
public OutputStream newOutputStream(Path path, OpenOption... options) throws IOException
Files.newOutputStream(Path, OpenOption...)
method.
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.
newOutputStream
in class FileSystemProvider
IOException
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
Files.newByteChannel(Path, Set, FileAttribute...)
method.
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.
newByteChannel
in class FileSystemProvider
IOException
public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException
newDirectoryStream
in class FileSystemProvider
IOException
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException
Files.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.
createDirectory
in class FileSystemProvider
IOException
public void delete(Path path) throws IOException
delete
in class FileSystemProvider
IOException
public Path readSymbolicLink(Path link) throws IOException
readSymbolicLink
in class FileSystemProvider
IOException
public void copy(Path source, Path target, CopyOption... options) throws IOException
Files.copy(Path, Path, CopyOption...)
method except that both the source and
target paths must be associated with this provider.
Most of the standard copy options are supported. StandardCopyOption.COPY_ATTRIBUTES
and StandardCopyOption.ATOMIC_MOVE
are not
supported though.
copy
in class FileSystemProvider
IOException
public void move(Path source, Path target, CopyOption... options) throws IOException
Files.move(Path, Path, CopyOption...)
method except that both the source and
target paths must be associated with this provider.
Most of the standard copy options are supported. StandardCopyOption.COPY_ATTRIBUTES
is not supported though.
StandardCopyOption.ATOMIC_MOVE
is only supported if the paths have the same file system.
move
in class FileSystemProvider
IOException
public boolean isSameFile(Path path, Path path2) throws IOException
isSameFile
in class FileSystemProvider
IOException
public boolean isHidden(Path path) throws IOException
isHidden
in class FileSystemProvider
IOException
public FileStore getFileStore(Path path) throws IOException
getFileStore
in class FileSystemProvider
IOException
public void checkAccess(Path path, AccessMode... modes) throws IOException
checkAccess
in class FileSystemProvider
IOException
public <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options)
Files.getFileAttributeView(Path, Class, LinkOption...)
method.
This provider supports BasicFileAttributeView
, FileOwnerAttributeView
and PosixFileAttributeView
.
All other classes will result in a null
return value.
Note: if the type is BasicFileAttributeView
or a sub type, the last access time and creation time must be null
when calling
BasicFileAttributeView.setTimes(FileTime, FileTime, FileTime)
, otherwise an exception will be thrown.
When setting the owner or group for the path, the name must be the UID/GID of the owner/group.
getFileAttributeView
in class FileSystemProvider
public <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options) throws IOException
Files.readAttributes(Path, Class, LinkOption...)
method.
This provider supports BasicFileAttributes
and PosixFileAttributes
(there is no FileOwnerFileAttributes
).
All other classes will result in an UnsupportedOperationException
to be thrown.
readAttributes
in class FileSystemProvider
IOException
public Map<String,Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException
Files.readAttributes(Path, String, LinkOption...)
method.
This provider supports views basic
, owner
and posix
, where basic
will be used if no view is given.
All other views will result in an UnsupportedOperationException
to be thrown.
readAttributes
in class FileSystemProvider
IOException
public void setAttribute(Path path, String attribute, Object value, LinkOption... options) throws IOException
Files.setAttribute(Path, String, Object, LinkOption...)
method.
This provider supports views basic
, owner
and posix
, where basic
will be used if no view is given.
All other views will result in an UnsupportedOperationException
to be thrown.
Note: updating the last access time or creation time is not supported. When setting the owner or group for the path, the name must be the UID/GID of the owner/group.
setAttribute
in class FileSystemProvider
IOException
public static void keepAlive(FileSystem fs) throws IOException
fs
- The SFTP file system to send a keep-alive signal for.ProviderMismatchException
- If the given file system is not an SFTP file system (not created by an SFTPFileSystemProvider
).IOException
- If an I/O error occurred.Copyright © 2016–2023. All rights reserved.