public class FtpFileSystem extends FileSystem
Modifier and Type | Field and Description |
---|---|
private FtpFileAdaptor |
adaptor |
private Credential |
credential |
private org.apache.commons.net.ftp.FTPClient |
ftpClient |
private static org.slf4j.Logger |
LOGGER |
private static int[] |
PERMISSION_TYPES |
private static int[] |
USER_TYPES |
Modifier | Constructor and Description |
---|---|
protected |
FtpFileSystem(java.lang.String uniqueID,
java.lang.String name,
java.lang.String location,
Path entryPath,
int bufferSize,
org.apache.commons.net.ftp.FTPClient ftpClient,
Credential credential,
FtpFileAdaptor adaptor,
XenonProperties properties) |
Modifier and Type | Method and Description |
---|---|
java.io.OutputStream |
appendToFile(Path path)
Open an existing file and return an
OutputStream to append data to this file. |
private void |
checkClientReply(org.apache.commons.net.ftp.FTPClient client,
java.lang.String message) |
private void |
checkClientReply(java.lang.String message) |
void |
close()
Close this FileSystem.
|
private PathAttributes |
convertAttributes(Path path,
org.apache.commons.net.ftp.FTPFile attributes) |
void |
createDirectory(Path path)
Creates a new directory, failing if the directory already exists.
|
void |
createFile(Path path)
Creates a new empty file, failing if the file already exists.
|
void |
createSymbolicLink(Path link,
Path path)
Creates a new symbolic link, failing if the link already exists (optional operation).
|
protected void |
deleteDirectory(Path path)
Delete an empty directory.
|
protected void |
deleteFile(Path path)
Delete a file.
|
boolean |
exists(Path path)
Tests if a path exists.
|
private org.apache.commons.net.ftp.FTPFile |
findFTPFile(org.apache.commons.net.ftp.FTPFile[] files,
Path path) |
PathAttributes |
getAttributes(Path path)
Get the
PathAttributes of an existing path. |
private org.apache.commons.net.ftp.FTPFile |
getFTPFileInfo(Path path) |
private java.util.HashSet<PosixFilePermission> |
getPermissions(org.apache.commons.net.ftp.FTPFile attributes) |
private PosixFilePermission |
getPosixFilePermission(int userType,
int permissionType) |
boolean |
isOpen()
Return if the connection to the FileSystem is open.
|
protected java.util.List<PathAttributes> |
listDirectory(Path path)
Return the list of entries in a directory.
|
java.io.InputStream |
readFromFile(Path path)
Open an existing file and return an
InputStream to read from this file. |
Path |
readSymbolicLink(Path path)
Reads the target of a symbolic link (optional operation).
|
void |
rename(Path source,
Path target)
Rename an existing source path to a non-existing target path (optional operation).
|
void |
setPosixFilePermissions(Path path,
java.util.Set<PosixFilePermission> permissions)
Sets the POSIX permissions of a path (optional operation).
|
java.io.OutputStream |
writeToFile(Path path)
Open a file and return an
OutputStream to write to this file. |
java.io.OutputStream |
writeToFile(Path path,
long size)
Open a file and return an
OutputStream to write to this file. |
areSamePaths, assertDirectoryExists, assertFileExists, assertFileIsSymbolicLink, assertIsOpen, assertNotNull, assertParentDirectoryExists, assertPathExists, assertPathIsDirectory, assertPathIsFile, assertPathIsNotDirectory, assertPathNotExists, cancel, copy, copyFile, copySymbolicLink, create, create, create, create, createDirectories, delete, equals, getAdaptorDescription, getAdaptorDescriptions, getAdaptorName, getAdaptorNames, getCredential, getLocation, getPathSeparator, getProperties, getStatus, getWorkingDirectory, hashCode, isDotDot, list, list, performCopy, setWorkingDirectory, streamCopy, toAbsolutePath, waitUntilDone
private static final org.slf4j.Logger LOGGER
private static final int[] PERMISSION_TYPES
private static final int[] USER_TYPES
private final org.apache.commons.net.ftp.FTPClient ftpClient
private final Credential credential
private final FtpFileAdaptor adaptor
protected FtpFileSystem(java.lang.String uniqueID, java.lang.String name, java.lang.String location, Path entryPath, int bufferSize, org.apache.commons.net.ftp.FTPClient ftpClient, Credential credential, FtpFileAdaptor adaptor, XenonProperties properties)
public void close() throws XenonException
FileSystem
close
in interface java.lang.AutoCloseable
close
in class FileSystem
XenonException
- If the FileSystem failed to close or if an I/O error occurred.public boolean isOpen() throws XenonException
FileSystem
isOpen
in class FileSystem
XenonException
- if the test failed or an I/O error occurred.private java.util.HashSet<PosixFilePermission> getPermissions(org.apache.commons.net.ftp.FTPFile attributes)
private PosixFilePermission getPosixFilePermission(int userType, int permissionType)
private PathAttributes convertAttributes(Path path, org.apache.commons.net.ftp.FTPFile attributes)
private void checkClientReply(org.apache.commons.net.ftp.FTPClient client, java.lang.String message) throws XenonException
XenonException
private void checkClientReply(java.lang.String message) throws XenonException
XenonException
public void rename(Path source, Path target) throws XenonException
FileSystem
This method only implements a rename operation, not a move operation. Hence, this method will not copy files and should return (almost)
instantaneously.
The parent of the target path (e.g. target.getParent
) must exist.
If the target is equal to the source this method has no effect.
If the source is a link, the link itself will be renamed, not the path to which it refers.
If the source is a directory, it will be renamed to the target. This implies that a moving a directory between physical locations may fail.
rename
in class FileSystem
source
- the existing source path.target
- the non existing target path.UnsupportedOperationException
- If the adapter does not support renaming.NoSuchPathException
- If the source file does not exist or the target parent directory does not exist.PathAlreadyExistsException
- If the target file already exists.NotConnectedException
- If file system is closed.XenonException
- If the move failed.public void createDirectory(Path path) throws XenonException
FileSystem
createDirectory
in class FileSystem
path
- the directory to create.PathAlreadyExistsException
- If the directory already exists.NoSuchPathException
- If the parent directory does not exist.NotConnectedException
- If file system is closed.XenonException
- If an I/O error occurred.public void createFile(Path path) throws XenonException
FileSystem
createFile
in class FileSystem
path
- a path referring to the file to create.PathAlreadyExistsException
- If the file already exists.NoSuchPathException
- If the parent directory does not exist.NotConnectedException
- If file system is closed.XenonException
- If an I/O error occurred.public void createSymbolicLink(Path link, Path path) throws XenonException
FileSystem
createSymbolicLink
in class FileSystem
link
- the symbolic link to create.path
- the target the symbolic link should refer to.PathAlreadyExistsException
- If the link already exists.NoSuchPathException
- If the target or parent directory of link does not existInvalidPathException
- If parent of link is not a directoryNotConnectedException
- If file system is closed.XenonException
- If an I/O error occurred.protected void deleteDirectory(Path path) throws XenonException
FileSystem
rmdir
in Linux).
This operation must be implemented by the various implementations of FileSystem.deleteDirectory
in class FileSystem
path
- the directory to removeInvalidPathException
- if the provided path is not a directory.NoSuchPathException
- if the provided path does not exist.XenonException
- If the directory could not be removed.protected void deleteFile(Path path) throws XenonException
FileSystem
deleteFile
in class FileSystem
path
- the file to removeInvalidPathException
- if the provided path is not a file.NoSuchPathException
- if the provided file does not exist.XenonException
- If the file could not be removed.public boolean exists(Path path) throws XenonException
FileSystem
exists
in class FileSystem
path
- the path to test.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.private org.apache.commons.net.ftp.FTPFile findFTPFile(org.apache.commons.net.ftp.FTPFile[] files, Path path) throws NoSuchPathException
NoSuchPathException
private org.apache.commons.net.ftp.FTPFile getFTPFileInfo(Path path) throws XenonException
XenonException
public PathAttributes getAttributes(Path path) throws XenonException
FileSystem
PathAttributes
of an existing path.getAttributes
in class FileSystem
path
- the existing path.NoSuchPathException
- If the file does not exists.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.protected java.util.List<PathAttributes> listDirectory(Path path) throws XenonException
FileSystem
dir
will be returned as part of the list, but they will not be listed themselves.
This operation must be implemented by the various implementations of FileSystem.listDirectory
in class FileSystem
path
- the directory to listIterable
that iterates over all entries in dir
XenonException
- If the list could not be retrieved.public java.io.InputStream readFromFile(Path path) throws XenonException
FileSystem
InputStream
to read from this file.readFromFile
in class FileSystem
path
- the to read.InputStream
to read from the file.NoSuchPathException
- If the file does not exists.InvalidPathException
- If the file is not regular file.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.public java.io.OutputStream writeToFile(Path path, long size) throws XenonException
FileSystem
OutputStream
to write to this file.
The size of the file (once all data has been written) must be specified using the size
parameter. This is required by some implementations
(typically blob-stores).
writeToFile
in class FileSystem
path
- the target file for the OutputStream.size
- the size of the file once fully written.OutputStream
to write to the file.PathAlreadyExistsException
- If the target existed.NoSuchPathException
- if a parent directory does not exist.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.public java.io.OutputStream writeToFile(Path path) throws XenonException
FileSystem
OutputStream
to write to this file. (optional operation)
If the file already exists it will be replaced and its data will be lost. The amount of data that will be written to the file is not specified in advance. This operation may not be supported by all implementations.
writeToFile
in class FileSystem
path
- the target file for the OutputStream.OutputStream
to write to the file.PathAlreadyExistsException
- If the target existed.NoSuchPathException
- if a parent directory does not exist.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.public java.io.OutputStream appendToFile(Path path) throws XenonException
FileSystem
OutputStream
to append data to this file. (optional operation)
If the file does not exist, an exception will be thrown. This operation may not be supported by all implementations.
appendToFile
in class FileSystem
path
- the target file for the OutputStream.OutputStream
to write to the file.PathAlreadyExistsException
- If the target existed.NoSuchPathException
- if a parent directory does not exist.InvalidPathException
- if not a regular fileNotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.UnsupportedOperationException
- if the adaptor does not support appendingpublic Path readSymbolicLink(Path path) throws XenonException
FileSystem
readSymbolicLink
in class FileSystem
path
- the link to read.NoSuchPathException
- If the link does not exists.InvalidPathException
- If the source is not a link.UnsupportedOperationException
- If this FileSystem does not support symbolic links.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.public void setPosixFilePermissions(Path path, java.util.Set<PosixFilePermission> permissions) throws XenonException
FileSystem
setPosixFilePermissions
in class FileSystem
path
- the target path.permissions
- the permissions to set.NoSuchPathException
- If the target path does not exists.UnsupportedOperationException
- If this FileSystem does not support symbolic links.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.