Class WebdavFileSystem
- java.lang.Object
-
- nl.esciencecenter.xenon.filesystems.FileSystem
-
- nl.esciencecenter.xenon.adaptors.filesystems.webdav.WebdavFileSystem
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class WebdavFileSystem extends FileSystem
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
WebdavFileSystem.StreamToFileWriter
-
Constructor Summary
Constructors Modifier Constructor Description protected
WebdavFileSystem(java.lang.String uniqueID, java.lang.String name, java.lang.String location, Credential credential, java.lang.String server, Path entryPath, int bufferSize, com.github.sardine.Sardine client, XenonProperties properties)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.OutputStream
appendToFile(Path file)
Open an existing file and return anOutputStream
to append data to this file.void
createDirectory(Path dir)
Creates a new directory, failing if the directory already exists.void
createFile(Path file)
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.PathAttributes
getAttributes(Path path)
Get thePathAttributes
of an existing path.private PathAttributes
getAttributes(Path path, com.github.sardine.DavResource p)
private java.lang.String
getDirectoryPath(Path path)
private java.lang.String
getFilePath(Path path)
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 anInputStream
to read from this file.Path
readSymbolicLink(Path link)
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 file)
Open a file and return anOutputStream
to write to this file.java.io.OutputStream
writeToFile(Path file, long size)
Open a file and return anOutputStream
to write to this file.-
Methods inherited from class nl.esciencecenter.xenon.filesystems.FileSystem
areSamePaths, assertDirectoryExists, assertFileExists, assertFileIsSymbolicLink, assertIsOpen, assertNotNull, assertParentDirectoryExists, assertPathExists, assertPathIsDirectory, assertPathIsFile, assertPathIsNotDirectory, assertPathNotExists, cancel, close, copy, copyFile, copySymbolicLink, create, create, create, create, createDirectories, delete, equals, getAdaptorDescription, getAdaptorDescriptions, getAdaptorName, getAdaptorNames, getBufferSize, getCredential, getLocation, getPathSeparator, getProperties, getStatus, getWorkingDirectory, hashCode, isDotDot, list, list, performCopy, setWorkingDirectory, streamCopy, toAbsolutePath, waitUntilDone
-
-
-
-
Constructor Detail
-
WebdavFileSystem
protected WebdavFileSystem(java.lang.String uniqueID, java.lang.String name, java.lang.String location, Credential credential, java.lang.String server, Path entryPath, int bufferSize, com.github.sardine.Sardine client, XenonProperties properties)
-
-
Method Detail
-
getFilePath
private java.lang.String getFilePath(Path path)
-
getDirectoryPath
private java.lang.String getDirectoryPath(Path path)
-
getAttributes
private PathAttributes getAttributes(Path path, com.github.sardine.DavResource p)
-
listDirectory
protected java.util.List<PathAttributes> listDirectory(Path path) throws XenonException
Description copied from class:FileSystem
Return the list of entries in a directory. This operation is non-recursive; any subdirectories indir
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.- Specified by:
listDirectory
in classFileSystem
- Parameters:
path
- the directory to list- Returns:
- a
Iterable
that iterates over all entries indir
- Throws:
XenonException
- If the list could not be retrieved.
-
isOpen
public boolean isOpen() throws XenonException
Description copied from class:FileSystem
Return if the connection to the FileSystem is open. An adaptor which does not support closing is always open.- Specified by:
isOpen
in classFileSystem
- Returns:
- if the connection to the FileSystem is open.
- Throws:
XenonException
- if the test failed or an I/O error occurred.
-
rename
public void rename(Path source, Path target) throws XenonException
Description copied from class:FileSystem
Rename an existing source path to a non-existing target path (optional operation).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.- Specified by:
rename
in classFileSystem
- Parameters:
source
- the existing source path.target
- the non existing target path.- Throws:
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.
-
createDirectory
public void createDirectory(Path dir) throws XenonException
Description copied from class:FileSystem
Creates a new directory, failing if the directory already exists. The parent directory of the file must already exists.- Specified by:
createDirectory
in classFileSystem
- Parameters:
dir
- the directory to create.- Throws:
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.
-
createFile
public void createFile(Path file) throws XenonException
Description copied from class:FileSystem
Creates a new empty file, failing if the file already exists. The parent directory of the file must already exists.- Specified by:
createFile
in classFileSystem
- Parameters:
file
- a path referring to the file to create.- Throws:
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.
-
createSymbolicLink
public void createSymbolicLink(Path link, Path path) throws XenonException
Description copied from class:FileSystem
Creates a new symbolic link, failing if the link already exists (optional operation). The target is taken as is. It may be absolute, relative path and/or non-normalized path and may or may not exist.- Specified by:
createSymbolicLink
in classFileSystem
- Parameters:
link
- the symbolic link to create.path
- the target the symbolic link should refer to.- Throws:
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.
-
deleteFile
protected void deleteFile(Path path) throws XenonException
Description copied from class:FileSystem
Delete a file. Is only called on existing files This operation must be implemented by the various implementations of FileSystem.- Specified by:
deleteFile
in classFileSystem
- Parameters:
path
- the file to remove- Throws:
InvalidPathException
- if the provided path is not a file.NoSuchPathException
- if the provided file does not exist.XenonException
- If the file could not be removed.
-
deleteDirectory
protected void deleteDirectory(Path path) throws XenonException
Description copied from class:FileSystem
Delete an empty directory. Is only called on empty directories This operation can only delete empty directories (analogous tormdir
in Linux). This operation must be implemented by the various implementations of FileSystem.- Specified by:
deleteDirectory
in classFileSystem
- Parameters:
path
- the directory to remove- Throws:
InvalidPathException
- if the provided path is not a directory.NoSuchPathException
- if the provided path does not exist.XenonException
- If the directory could not be removed.
-
exists
public boolean exists(Path path) throws XenonException
Description copied from class:FileSystem
Tests if a path exists.- Specified by:
exists
in classFileSystem
- Parameters:
path
- the path to test.- Returns:
- If the path exists.
- Throws:
NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.
-
readFromFile
public java.io.InputStream readFromFile(Path path) throws XenonException
Description copied from class:FileSystem
Open an existing file and return anInputStream
to read from this file.- Specified by:
readFromFile
in classFileSystem
- Parameters:
path
- the to read.- Returns:
- the
InputStream
to read from the file. - Throws:
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.
-
writeToFile
public java.io.OutputStream writeToFile(Path file, long size) throws XenonException
Description copied from class:FileSystem
Open a file and return anOutputStream
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).- Specified by:
writeToFile
in classFileSystem
- Parameters:
file
- the target file for the OutputStream.size
- the size of the file once fully written.- Returns:
- the
OutputStream
to write to the file. - Throws:
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.
-
appendToFile
public java.io.OutputStream appendToFile(Path file) throws XenonException
Description copied from class:FileSystem
Open an existing file and return anOutputStream
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.
- Specified by:
appendToFile
in classFileSystem
- Parameters:
file
- the target file for the OutputStream.- Returns:
- the
OutputStream
to write to the file. - Throws:
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 appending
-
writeToFile
public java.io.OutputStream writeToFile(Path file) throws XenonException
Description copied from class:FileSystem
Open a file and return anOutputStream
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.
- Specified by:
writeToFile
in classFileSystem
- Parameters:
file
- the target file for the OutputStream.- Returns:
- the
OutputStream
to write to the file. - Throws:
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.
-
getAttributes
public PathAttributes getAttributes(Path path) throws XenonException
Description copied from class:FileSystem
Get thePathAttributes
of an existing path.- Specified by:
getAttributes
in classFileSystem
- Parameters:
path
- the existing path.- Returns:
- the FileAttributes of the path.
- Throws:
NoSuchPathException
- If the file does not exists.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.
-
readSymbolicLink
public Path readSymbolicLink(Path link) throws XenonException
Description copied from class:FileSystem
Reads the target of a symbolic link (optional operation).- Specified by:
readSymbolicLink
in classFileSystem
- Parameters:
link
- the link to read.- Returns:
- a Path representing the target of the link.
- Throws:
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.
-
setPosixFilePermissions
public void setPosixFilePermissions(Path path, java.util.Set<PosixFilePermission> permissions) throws XenonException
Description copied from class:FileSystem
Sets the POSIX permissions of a path (optional operation).- Specified by:
setPosixFilePermissions
in classFileSystem
- Parameters:
path
- the target path.permissions
- the permissions to set.- Throws:
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.
-
-