public final class AsyncFile extends Object
| Modifier and Type | Method and Description |
|---|---|
Stage<Void> |
close()
Closes the channel
|
static Stage<Void> |
copy(ExecutorService executor,
Path source,
Path target,
CopyOption... options)
Copies a file to a target file.
|
static Stage<Void> |
createDirectories(ExecutorService executor,
Path dir,
FileAttribute<?>[] attrs)
Creates a directory by creating all nonexistent parent directories first.
|
static Stage<Void> |
createDirectory(ExecutorService executor,
Path dir,
FileAttribute<?>[] attrs)
Creates a new directory.
|
static Stage<Void> |
delete(ExecutorService executor,
Path path)
Concurrently deletes the file.
|
Stage<Void> |
force(boolean metaData)
Forces any updates to this file to be written to the storage device that contains it.
|
Stage<Void> |
forceAndClose(boolean forceMetadata)
Forces physical write and then closes the channel
|
FileChannel |
getChannel() |
ExecutorService |
getExecutor() |
boolean |
isOpen() |
static Stage<Void> |
move(ExecutorService executor,
Path source,
Path target,
CopyOption... options)
Moves or renames a file to a target file.
|
static AsyncFile |
open(ExecutorService executor,
Path path,
OpenOption[] openOptions)
Synchronously opens file
|
static AsyncFile |
open(ExecutorService executor,
Path path,
OpenOption[] openOptions,
Object mutexLock) |
static Stage<AsyncFile> |
openAsync(ExecutorService executor,
Path path,
OpenOption[] openOptions)
Asynchronously opens file
|
static Stage<AsyncFile> |
openAsync(ExecutorService executor,
Path path,
OpenOption[] openOptions,
Object mutexLock) |
Stage<ByteBuf> |
read()
Asynchronously reads all bytes from this file into a buffer.
|
Stage<Void> |
read(ByteBuf buf,
long position)
Asynchronously reads a sequence of bytes from this channel into the given buffer,
starting at the given position.
|
Stage<ByteBuf> |
read(long position)
Asynchronously reads all bytes from this file into a buffer starting at given position.
|
static Stage<ByteBuf> |
readFile(ExecutorService executor,
Path path)
Reads all bytes from this channel into the given buffer.
|
static Stage<Long> |
size(ExecutorService executor,
Path path)
Checks the file size.
|
String |
toString() |
Stage<Void> |
truncate(long size)
Truncates this file to the given size.
|
Stage<Void> |
write(ByteBuf buf)
Asynchronously writes all bytes of the buffer into this file at its internal position.
|
Stage<Void> |
write(ByteBuf buf,
long position)
Asynchronously writes all bytes of the buffer into this file starting at given position.
|
static Stage<Void> |
writeNewFile(ExecutorService executor,
Path path,
ByteBuf buf)
Creates new file and writes a sequence of bytes to this file from the given buffer, starting at the given file
position.
|
public static AsyncFile open(ExecutorService executor, Path path, OpenOption[] openOptions) throws IOException
executor - executor for running tasks in other threadpath - the path of the file to open or createopenOptions - options specifying how the file is openedIOExceptionpublic static AsyncFile open(ExecutorService executor, Path path, OpenOption[] openOptions, Object mutexLock) throws IOException
IOExceptionpublic static Stage<AsyncFile> openAsync(ExecutorService executor, Path path, OpenOption[] openOptions)
executor - executor for running tasks in other threadpath - the path of the file to open or createopenOptions - options specifying how the file is openedpublic static Stage<AsyncFile> openAsync(ExecutorService executor, Path path, OpenOption[] openOptions, Object mutexLock)
public static Stage<Void> delete(ExecutorService executor, Path path)
path - the path of the file to open or createpublic static Stage<Long> size(ExecutorService executor, Path path)
nullexecutor - executor for running tasks in other threadpath - the path of the file to checknull if it is a directory or it does not existpublic static Stage<Void> move(ExecutorService executor, Path source, Path target, CopyOption... options)
executor - executor for running tasks in other threadsource - the path to the file to movetarget - the path to the target file (may be associated with a different provider to the source path)options - options specifying how the move should be donepublic static Stage<Void> copy(ExecutorService executor, Path source, Path target, CopyOption... options)
executor - executor for running tasks in other threadsource - the path to the file to copytarget - the path to the target file (may be associated with a different provider to the source path)options - options specifying how the move should be donepublic static Stage<Void> createDirectory(ExecutorService executor, Path dir, @Nullable FileAttribute<?>[] attrs)
executor - executor for running tasks in other threaddir - the directory to createattrs - an optional list of file attributes to set atomically when creating the directorypublic static Stage<Void> createDirectories(ExecutorService executor, Path dir, @Nullable FileAttribute<?>[] attrs)
executor - executor for running tasks in other threaddir - the directory to createattrs - an optional list of file attributes to set atomically when creating the directorypublic static Stage<ByteBuf> readFile(ExecutorService executor, Path path)
path - the path of the file to readpublic static Stage<Void> writeNewFile(ExecutorService executor, Path path, ByteBuf buf)
path - the path of the file to create and writebuf - the buffer from which bytes are to be transferred byteBufferpublic Stage<Void> write(ByteBuf buf)
buf - byte buffer to be writtenpublic Stage<Void> write(ByteBuf buf, long position)
position - offset from which bytes will be written to the filebuf - byte buffer to be writtenpublic Stage<ByteBuf> read(long position)
position - offset from which bytes of the file will be readpublic Stage<Void> read(ByteBuf buf, long position)
buf - the buffer into which bytes are to be transferredposition - the file position at which the transfer is to begin; must be non-negativepublic Stage<Void> forceAndClose(boolean forceMetadata)
forceMetadata - whether or not to force metadata writes toopublic Stage<Void> truncate(long size)
size - the new size, a non-negative byte countpublic Stage<Void> force(boolean metaData)
metaData - if true then this method is required to force changes of both
file content and metadata to be written to storage;
otherwise, it need only force content changes to be writtenpublic ExecutorService getExecutor()
public FileChannel getChannel()
public boolean isOpen()
Copyright © 2019. All rights reserved.