Modifier and Type | Field and Description |
---|---|
static DirectoryStream.Filter |
ACCEPT_ALL_FILTER |
private XenonEngine |
xenonEngine |
Constructor and Description |
---|
FilesEngine(XenonEngine xenonEngine) |
Modifier and Type | Method and Description |
---|---|
CopyStatus |
cancelCopy(Copy copy)
Cancel a copy operation.
|
void |
close(FileSystem filesystem)
Close a FileSystem.
|
Copy |
copy(Path source,
Path target,
CopyOption... options)
Copy an existing source file or symbolic link to a target file.
|
void |
createDirectories(Path dir)
Creates a new directory, failing if the directory already exists.
|
void |
createDirectory(Path dir)
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 |
delete(Path path)
Deletes an existing path.
|
boolean |
exists(Path path)
Tests if a path exists.
|
FileAttributes |
getAttributes(Path path)
Get the
FileAttributes of an existing path. |
CopyStatus |
getCopyStatus(Copy copy)
Retrieve the status of an asynchronous copy.
|
private Files |
getFilesAdaptor(FileSystem filesystem) |
private Files |
getFilesAdaptor(Path path) |
private Files |
getFilesAdaptorFromEngine(FileSystem filesystem) |
boolean |
isOpen(FileSystem filesystem)
Test is a FileSystem is open.
|
void |
move(Path source,
Path target)
Move or rename an existing source path to a non-existing target path.
|
DirectoryStream<PathAttributesPair> |
newAttributesDirectoryStream(Path dir)
Create a DirectoryStream that iterates over all PathAttributePair entries in the directory
dir . |
DirectoryStream<PathAttributesPair> |
newAttributesDirectoryStream(Path dir,
DirectoryStream.Filter filter)
Create a DirectoryStream that iterates over all PathAttributePair entries in the directory
dir that are
accepted by the filter. |
DirectoryStream<Path> |
newDirectoryStream(Path dir)
Create a DirectoryStream that iterates over all entries in the directory
dir . |
DirectoryStream<Path> |
newDirectoryStream(Path dir,
DirectoryStream.Filter filter)
Create a DirectoryStream that iterates over all entries in the directory
dir that are accepted by the filter. |
FileSystem |
newFileSystem(java.lang.String scheme,
java.lang.String location,
Credential credential,
java.util.Map<java.lang.String,java.lang.String> properties)
Create a new FileSystem that represents a (possibly remote) data store
at the
location , using the scheme and
credentials to get access. |
java.io.InputStream |
newInputStream(Path path)
Open an existing file and return an
InputStream to read from this file. |
java.io.OutputStream |
newOutputStream(Path path,
OpenOption... options)
Open an file and return an
OutputStream to write to this file. |
Path |
newPath(FileSystem filesystem,
RelativePath location)
Create a new Path that represents a (possibly non existing) location on
filesystem. |
Path |
readSymbolicLink(Path link)
Reads the target of a symbolic link (optional operation).
|
void |
setPosixFilePermissions(Path path,
java.util.Set<PosixFilePermission> permissions)
Sets the POSIX permissions of a path.
|
java.lang.String |
toString() |
public static final DirectoryStream.Filter ACCEPT_ALL_FILTER
private final XenonEngine xenonEngine
public FilesEngine(XenonEngine xenonEngine)
private Files getFilesAdaptorFromEngine(FileSystem filesystem)
private Files getFilesAdaptor(FileSystem filesystem) throws XenonException
XenonException
private Files getFilesAdaptor(Path path) throws XenonException
XenonException
public FileSystem newFileSystem(java.lang.String scheme, java.lang.String location, Credential credential, java.util.Map<java.lang.String,java.lang.String> properties) throws XenonException
Files
location
, using the scheme
and
credentials
to get access. Make sure to always close
FileSystem
instances by calling close(FileSystem)
when
you no longer need them, otherwise their associated resources remain
allocated.newFileSystem
in interface Files
scheme
- the scheme to use to access the FileSystem.location
- the location of the FileSystem, may be null for a local file system.credential
- the Credentials to use to get access to the FileSystem.properties
- optional properties to use when creating the FileSystem.UnknownPropertyException
- If a unknown property was provided.InvalidPropertyException
- If a known property was provided with an invalid value.InvalidSchemeException
- If the scheme was invalid.InvalidLocationException
- If the location was invalid.InvalidCredentialException
- If the credential is invalid to access the location.XenonException
- If the creation of the FileSystem failed.public Path newPath(FileSystem filesystem, RelativePath location) throws XenonException
Files
filesystem.
newPath
in interface Files
filesystem
- the FileSystem for which to create the path.location
- the location relative to the root of the given FileSystem.XenonException
- If an I/O error occurred.public void close(FileSystem filesystem) throws XenonException
Files
close
in interface Files
filesystem
- the FileSystem to close.XenonException
- If the FileSystem failed to close or if an I/O error occurred.public boolean isOpen(FileSystem filesystem) throws XenonException
Files
isOpen
in interface Files
filesystem
- the FileSystem to test.XenonException
- If the test failed or an I/O error occurred.public void createDirectories(Path dir) throws XenonException
Files
createDirectories
in interface Files
dir
- the directory to create.PathAlreadyExistsException
- If the directory already exists or if a parent directory could not be created because a file with the same name
already exists.XenonException
- If an I/O error occurred.public void createDirectory(Path dir) throws XenonException
Files
createDirectory
in interface Files
dir
- the directory to create.PathAlreadyExistsException
- If the directory already exists.XenonException
- If an I/O error occurred.public void createFile(Path path) throws XenonException
Files
createFile
in interface Files
path
- the file to create.PathAlreadyExistsException
- If the directory already exists.XenonException
- If an I/O error occurred.public void delete(Path path) throws XenonException
Files
delete
in interface Files
path
- the path to delete.XenonException
- If an I/O error occurred.public boolean exists(Path path) throws XenonException
Files
exists
in interface Files
path
- the path to test.XenonException
- If an I/O error occurred.public Copy copy(Path source, Path target, CopyOption... options) throws XenonException
Files
When using copy, the following rules apply:
target.getParent
) must exist.
In addition, the options
parameter determines how the copy is performed:
CREATE
(default): Create a new target file and copy to it. Fail if the target already exists.REPLACE
: Replace target if it already exists. If the target does not exist it will be created.IGNORE
: Ignore copy if the target already exists. If the target does not exist it will be created.APPEND
: The data in source will appended to target. Fails if the target does not exist.RESUME
: A copy from source to target will be resumed. This fails if the target does not exist. To resume
a copy, the size of the target is used as the start position in the source. All data from the source after this start
position is append to the target. For example, if the target contains 100 bytes (0-99) and the source 200 bytes (0-199),
the data at bytes 100-199 in the source will be append to target. By default, there is no verification that the existing
data in target corresponds to the data in source.Note that the five options above are mutually exclusive. Only one can be selected at a time. If more than one of these options is provided, an exception will be thrown.
The following options modify the behavior of the copy operation:
VERIFY
(can only be used in combination with RESUME
): When resuming a copy, verify that the
existing data in target corresponds to the data in source.ASYNCHRONOUS
: Perform an asynchronous copy. Instead of blocking until the copy is complete, the call
returns immediately and the copy is performed in the background.
If the ASYNCHRONOUS
option is provided, a Copy
is returned that can be used to retrieve the status of
the copy operation (in a CopyStatus
) or cancel it. Any exceptions produced during the copy operation are also
stored in the CopyStatus
.
If the ASYNCHRONOUS
option is not provided, the copy will block until it is completed and null
will be returned.
copy
in interface Files
source
- the existing source file or link.target
- the target path.options
- options for the copy operation.CopyStatus
if the copy is asynchronous or null
if it is blocking.NoSuchPathException
- If the source file does not exist, the target parent directory does not exist, or the target file does not
exist and the APPEND
or RESUME
option is provided.PathAlreadyExistsException
- If the target file already exists.IllegalSourcePathException
- If the source is a directory.IllegalTargetPathException
- If the target is a directory.InvalidCopyOptionsException
- If a conflicting set of copy options is provided.InvalidResumeTargetException
- If the data in the target of a resume does not match the data in the source.XenonException
- If an I/O error occurred.public void move(Path source, Path target) throws XenonException
Files
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 moved, 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.
move
in interface Files
source
- the existing source path.target
- the non existing target path.NoSuchPathException
- If the source file does not exist or the target parent directory does not exist.PathAlreadyExistsException
- If the target file already exists.XenonException
- If the move failed.public CopyStatus getCopyStatus(Copy copy) throws XenonException
Files
getCopyStatus
in interface Files
copy
- the asynchronous copy for which to retrieve the status.CopyStatus
containing the status of the asynchronous copy.NoSuchCopyException
- If the copy is not known.XenonException
- If an I/O error occurred.public CopyStatus cancelCopy(Copy copy) throws XenonException
Files
cancelCopy
in interface Files
copy
- the asynchronous copy which to cancel.NoSuchCopyException
- If the copy is not known.XenonException
- If an I/O error occurred.public DirectoryStream<Path> newDirectoryStream(Path dir) throws XenonException
Files
dir
.newDirectoryStream
in interface Files
dir
- the target directory.NoSuchPathException
- If a directory does not exists.IllegalSourcePathException
- If dir is not a directory.XenonException
- If an I/O error occurred.public DirectoryStream<PathAttributesPair> newAttributesDirectoryStream(Path dir) throws XenonException
Files
dir
.newAttributesDirectoryStream
in interface Files
dir
- the target directory.dir
.NoSuchPathException
- If a directory does not exists.IllegalSourcePathException
- If dir is not a directory.XenonException
- If an I/O error occurred.public DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter filter) throws XenonException
Files
dir
that are accepted by the filter.newDirectoryStream
in interface Files
dir
- the target directory.filter
- the filter.dir
.NoSuchPathException
- If a directory does not exists.IllegalSourcePathException
- If dir is not a directory.XenonException
- If an I/O error occurred.public DirectoryStream<PathAttributesPair> newAttributesDirectoryStream(Path dir, DirectoryStream.Filter filter) throws XenonException
Files
dir
that are
accepted by the filter.newAttributesDirectoryStream
in interface Files
dir
- the target directory.filter
- the filter.dir
.NoSuchPathException
- If a directory does not exists.IllegalSourcePathException
- If dir is not a directory.XenonException
- If an I/O error occurred.public java.io.InputStream newInputStream(Path path) throws XenonException
Files
InputStream
to read from this file.newInputStream
in interface Files
path
- the existing file to read.InputStream
to read from the file.NoSuchPathException
- If a file does not exists.IllegalSourcePathException
- If path not file.XenonException
- If an I/O error occurred.public java.io.OutputStream newOutputStream(Path path, OpenOption... options) throws XenonException
Files
OutputStream
to write to this file.
The options determine how the file is opened, if a new file is created, if the existing data in the file is preserved, and if the file should be written or read:
CREATE
option is specified, a new file will be created and an exception is thrown if the file already
exists.
OPEN_EXISTING
option is specified, an existing file will be opened, and an exception is thrown if the
file does not exist.
OPEN_OR_CREATE
option is specified, an attempt will be made to open an existing file. If it does not
exist a new file will be created.
APPEND
option is specified, data will be added to the end of the file. No existing data will be
overwritten.
TRUNCATE
option is specified, any existing data in the file will be deleted (resulting in a file of
size 0). The data will then be appended from the beginning of the file.
One of CREATE
, OPEN_EXISTING
or OPEN_OR_CREATE
must be specified. Specifying more
than one will result in an exception.
Either APPEND
or TRUNCATE
must be specified. Specifying both will result in an exception.
The READ
option must not be set. If it is set, an exception will be thrown.
If the WRITE
option is specified, the file is opened for writing. As this is the default behavior, the
WRITE
option may be omitted.
newOutputStream
in interface Files
path
- the target file for the OutputStream.options
- the options to use for opening this file.OutputStream
to write to the file.IllegalSourcePathException
- If path is not a file.InvalidOpenOptionsException
- If an invalid combination of OpenOptions was provided.XenonException
- If an I/O error occurred.public FileAttributes getAttributes(Path path) throws XenonException
Files
FileAttributes
of an existing path.getAttributes
in interface Files
path
- the existing path.NoSuchPathException
- If a file does not exists.XenonException
- If an I/O error occurred.public Path readSymbolicLink(Path link) throws XenonException
Files
readSymbolicLink
in interface Files
link
- the link to read.NoSuchPathException
- If the link does not exists.IllegalSourcePathException
- If the source is not a link.XenonException
- If an I/O error occurred.public void setPosixFilePermissions(Path path, java.util.Set<PosixFilePermission> permissions) throws XenonException
Files
setPosixFilePermissions
in interface Files
path
- the target path.permissions
- the permissions to set.NoSuchPathException
- If the target path does not exists.XenonException
- If an I/O error occurred.public java.lang.String toString()
toString
in class java.lang.Object