Module xaos.ui
Class TreeDirectoryAsynchronousIO<I,T>
- java.lang.Object
-
- eu.ess.xaos.ui.control.tree.directory.TreeDirectoryAsynchronousIO<I,T>
-
- Type Parameters:
I
- Type of the initiator of the I/O operation.T
- Type of the object returned byTreeItem.getValue()
.
- All Implemented Interfaces:
InitiatorAsynchronousIO<I>
public class TreeDirectoryAsynchronousIO<I,T> extends Object implements InitiatorAsynchronousIO<I>
Implementation of anInitiatorAsynchronousIO
that will update aDirectoryModel
on each operation.- Author:
- claudio.rosati@esss.se
- See Also:
- LiveDirsFX:org.fxmisc.livedirs.LiveDirsIO
-
-
Constructor Summary
Constructors Constructor Description TreeDirectoryAsynchronousIO(DirectoryWatcher directoryWatcher, TreeDirectoryModel<I,T> model, Executor clientThreadExecutor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletionStage<Void>
createDirectories(Path dir, I initiator, FileAttribute<?>... attrs)
Create a new directory by creating all nonexistent parent directories first.CompletionStage<Void>
createDirectory(Path dir, I initiator, FileAttribute<?>... attrs)
Creates a directory.CompletionStage<Void>
createFile(Path file, I initiator, FileAttribute<?>... attrs)
Creates an empty file.CompletionStage<Void>
delete(Path path, I initiator)
Deletes a file or an empty directory.CompletionStage<Void>
deleteTree(Path root, I initiator)
Deletes a file tree rooted at the given path.CompletionStage<byte[]>
readBinaryFile(Path file, I initiator)
Reads the contents of a binary file.CompletionStage<String>
readTextFile(Path file, Charset charset, I initiator)
Reads the contents of a text file.CompletionStage<Void>
writeBinaryFile(Path file, byte[] content, I initiator)
Writes binary file to disk.CompletionStage<Void>
writeTextFile(Path file, String content, Charset charset, I initiator)
Writes the given string in a text file to disk.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface eu.ess.xaos.core.util.io.InitiatorAsynchronousIO
readUTF8File, withInitiator, writeUTF8File
-
-
-
-
Constructor Detail
-
TreeDirectoryAsynchronousIO
public TreeDirectoryAsynchronousIO(DirectoryWatcher directoryWatcher, TreeDirectoryModel<I,T> model, Executor clientThreadExecutor)
-
-
Method Detail
-
createDirectories
public CompletionStage<Void> createDirectories(Path dir, I initiator, FileAttribute<?>... attrs)
Description copied from interface:InitiatorAsynchronousIO
Create a new directory by creating all nonexistent parent directories first. If an I/O error occurs, the returned completion stage is completed exceptionally with the encountered error.- Specified by:
createDirectories
in interfaceInitiatorAsynchronousIO<I>
- Parameters:
dir
- The pathname of the file to be created.initiator
- The initiator of the operation.attrs
- An optional list of file attributes to set atomically when creating the directory.- Returns:
- An exceptionally completed
CompletionStage
in case of an exception is thrown.
-
createDirectory
public CompletionStage<Void> createDirectory(Path dir, I initiator, FileAttribute<?>... attrs)
Description copied from interface:InitiatorAsynchronousIO
Creates a directory. If the directory already exists, or its parent directory does not exist, or another I/O error occurs, the returned completion stage is completed exceptionally with the encountered error.- Specified by:
createDirectory
in interfaceInitiatorAsynchronousIO<I>
- Parameters:
dir
- The pathname of the directory to be created.initiator
- The initiator of the operation.attrs
- An optional list of file attributes to set atomically when creating the directory.- Returns:
- An exceptionally completed
CompletionStage
in case the directory already exists, or its parent directory does not exist, or an exception is thrown.
-
createFile
public CompletionStage<Void> createFile(Path file, I initiator, FileAttribute<?>... attrs)
Description copied from interface:InitiatorAsynchronousIO
Creates an empty file. If file already exists or an I/O error occurs, the returned completion stage is completed exceptionally with the encountered error.- Specified by:
createFile
in interfaceInitiatorAsynchronousIO<I>
- Parameters:
file
- The pathname of the file to be created.initiator
- The initiator of the operation.attrs
- An optional list of file attributes to set atomically when creating the directory.- Returns:
- An exceptionally completed
CompletionStage
in case the file already exists, or an exception is thrown.
-
delete
public CompletionStage<Void> delete(Path path, I initiator)
Description copied from interface:InitiatorAsynchronousIO
Deletes a file or an empty directory. If an I/O error occurs, the returned completion stage is completed exceptionally with the encountered error.- Specified by:
delete
in interfaceInitiatorAsynchronousIO<I>
- Parameters:
path
- Pathname of the file or directory to be deleted.initiator
- The initiator of the operation.- Returns:
- An exceptionally completed
CompletionStage
in case an exception is thrown.
-
deleteTree
public CompletionStage<Void> deleteTree(Path root, I initiator)
Description copied from interface:InitiatorAsynchronousIO
Deletes a file tree rooted at the given path. If an I/O error occurs, the returned completion stage is completed exceptionally with the encountered error.- Specified by:
deleteTree
in interfaceInitiatorAsynchronousIO<I>
- Parameters:
root
- The path to the file tree root to be deleted.initiator
- The initiator of the operation.- Returns:
- An exceptionally completed
CompletionStage
in case an exception is thrown.
-
readBinaryFile
public CompletionStage<byte[]> readBinaryFile(Path file, I initiator)
Description copied from interface:InitiatorAsynchronousIO
Reads the contents of a binary file. The returned completion stage will contain the read content as a byte array or, if an I/O error occurs, it will be completed exceptionally with the encountered error.- Specified by:
readBinaryFile
in interfaceInitiatorAsynchronousIO<I>
- Parameters:
file
- The pathname of the file to be read.initiator
- The initiator of the operation.- Returns:
- A
CompletionStage
containing the read content as a byte array or, if an I/O error occurs, the encountered error.
-
readTextFile
public CompletionStage<String> readTextFile(Path file, Charset charset, I initiator)
Description copied from interface:InitiatorAsynchronousIO
Reads the contents of a text file. The returned completion stage will contain the read content as a string or, if an I/O error occurs, it will be completed exceptionally with the encountered error.- Specified by:
readTextFile
in interfaceInitiatorAsynchronousIO<I>
- Parameters:
file
- The pathname of the file to be read.charset
- TheCharset
used.initiator
- The initiator of the operation.- Returns:
- A
CompletionStage
containing the read content as a string or, if an I/O error occurs, the encountered error.
-
writeBinaryFile
public CompletionStage<Void> writeBinaryFile(Path file, byte[] content, I initiator)
Description copied from interface:InitiatorAsynchronousIO
Writes binary file to disk. If an I/O error occurs, the returned completion stage is completed exceptionally with the encountered error.- Specified by:
writeBinaryFile
in interfaceInitiatorAsynchronousIO<I>
- Parameters:
file
- The pathname of the file to be created.content
- The bytes to be written into the file.initiator
- The initiator of the operation.- Returns:
- An exceptionally completed
CompletionStage
in case an exception is thrown.
-
writeTextFile
public CompletionStage<Void> writeTextFile(Path file, String content, Charset charset, I initiator)
Description copied from interface:InitiatorAsynchronousIO
Writes the given string in a text file to disk. If an I/O error occurs, the returned completion stage is completed exceptionally with the encountered error.- Specified by:
writeTextFile
in interfaceInitiatorAsynchronousIO<I>
- Parameters:
file
- The pathname of the file to be created.content
- The String to be written in the file.charset
- TheCharset
used.initiator
- The initiator of the operation.- Returns:
- An exceptionally completed
CompletionStage
in case an exception is thrown.
-
-