public class HDFSFileSystem extends FileSystem
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
closed |
private java.lang.String |
ERROR_MSG |
(package private) org.apache.hadoop.fs.FileSystem |
fs |
Modifier | Constructor and Description |
---|---|
protected |
HDFSFileSystem(java.lang.String uniqueID,
java.lang.String endPoint,
Credential credential,
org.apache.hadoop.fs.FileSystem fs,
int bufferSize,
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. |
(package private) void |
checkClosed() |
void |
close()
Close this FileSystem.
|
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 target)
Creates a new symbolic link, failing if the link already exists (optional operation).
|
void |
delete(Path path,
boolean recursive)
Deletes an existing path.
|
protected void |
deleteDirectory(Path path)
Delete an empty directory.
|
protected void |
deleteFile(Path file)
Delete a file.
|
boolean |
exists(Path path)
Tests if a path exists.
|
(package private) static Path |
fromHDFSPath(org.apache.hadoop.fs.Path p) |
PathAttributes |
getAttributes(Path path)
Get the
PathAttributes of an existing path. |
boolean |
isOpen()
Return if the connection to the FileSystem is open.
|
java.lang.Iterable<PathAttributes> |
list(Path dir,
boolean recursive)
List all entries in the directory
dir . |
protected java.lang.Iterable<PathAttributes> |
listDirectory(Path dir)
Return the list of entries in a directory.
|
private java.util.Iterator<PathAttributes> |
listIterator(Path dir) |
private java.util.Iterator<PathAttributes> |
listIteratorNoException(Path dir) |
java.io.InputStream |
readFromFile(Path path)
Open an existing file and return an
InputStream 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).
|
(package private) org.apache.hadoop.fs.Path |
toHDFSPath(Path p) |
private PathAttributes |
toPathAttributes(org.apache.hadoop.fs.FileStatus s) |
private java.util.Set<PosixFilePermission> |
toPermissionSet(org.apache.hadoop.fs.permission.FsPermission permission) |
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, equals, getAdaptorDescription, getAdaptorDescriptions, getAdaptorName, getAdaptorNames, getCredential, getLocation, getPathSeparator, getProperties, getStatus, getWorkingDirectory, hashCode, isDotDot, list, performCopy, setWorkingDirectory, streamCopy, toAbsolutePath, waitUntilDone
final org.apache.hadoop.fs.FileSystem fs
boolean closed
private final java.lang.String ERROR_MSG
protected HDFSFileSystem(java.lang.String uniqueID, java.lang.String endPoint, Credential credential, org.apache.hadoop.fs.FileSystem fs, int bufferSize, XenonProperties properties)
void checkClosed() throws XenonException
XenonException
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.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 dir) throws XenonException
FileSystem
createDirectory
in class FileSystem
dir
- 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 file) throws XenonException
FileSystem
createFile
in class FileSystem
file
- 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 target) throws XenonException
FileSystem
createSymbolicLink
in class FileSystem
link
- the symbolic link to create.target
- 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.public void delete(Path path, boolean recursive) throws XenonException
FileSystem
recursive
is set to true, the contents of the directory will also be deleted. If recursive
is
set to false
, a directory will only be removed if it is empty.delete
in class FileSystem
path
- the path to delete.recursive
- if the delete must be done recursivelyDirectoryNotEmptyException
- if the directory was not empty (and the delete was not recursive).NoSuchPathException
- if the provided path does not exist.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.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.public java.lang.Iterable<PathAttributes> list(Path dir, boolean recursive) throws XenonException
FileSystem
dir
.
All entries in the directory are returned, but subdirectories will not be traversed by default. Set recursive
to true
, include
the listing of all subdirectories.
Symbolic links are not followed.list
in class FileSystem
dir
- the target directory.recursive
- should the list recursively traverse the subdirectories ?List
of PathAttributes
that iterates over all entries in the directory dir
.NoSuchPathException
- If a directory does not exists.InvalidPathException
- If dir
is not a directory.NotConnectedException
- If file system is closed.XenonException
- if an I/O error occurred.private java.util.Iterator<PathAttributes> listIteratorNoException(Path dir)
private java.util.Iterator<PathAttributes> listIterator(Path dir) throws XenonException
XenonException
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 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 void deleteFile(Path file) throws XenonException
FileSystem
deleteFile
in class FileSystem
file
- 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.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 java.lang.Iterable<PathAttributes> listDirectory(Path dir) 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
dir
- the directory to listIterable
that iterates over all entries in dir
XenonException
- If the list could not be retrieved.org.apache.hadoop.fs.Path toHDFSPath(Path p)
static Path fromHDFSPath(org.apache.hadoop.fs.Path p)
private PathAttributes toPathAttributes(org.apache.hadoop.fs.FileStatus s)
private java.util.Set<PosixFilePermission> toPermissionSet(org.apache.hadoop.fs.permission.FsPermission permission)
public Path readSymbolicLink(Path link) throws XenonException
FileSystem
readSymbolicLink
in class FileSystem
link
- 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.