public interface FileSystem
An asynchronous and a synchronous version of each operation is provided.
The asynchronous versions take a handler which is called when the operation completes or an error occurs.
The synchronous versions return the results, or throw exceptions directly.
It is highly recommended the asynchronous versions are used unless you are sure the operation will not block for a significant period of time.
Instances of FileSystem are thread-safe.
Modifier and Type | Method and Description |
---|---|
FileSystem |
chmod(java.lang.String path,
java.lang.String perms,
Handler<AsyncResult<java.lang.Void>> handler)
Change the permissions on the file represented by
path to perms , asynchronously. |
FileSystem |
chmod(java.lang.String path,
java.lang.String perms,
java.lang.String dirPerms,
Handler<AsyncResult<java.lang.Void>> handler)
Change the permissions on the file represented by
path to perms , asynchronously. |
FileSystem |
chmodSync(java.lang.String path,
java.lang.String perms)
Synchronous version of
chmod(String, String, Handler) |
FileSystem |
chmodSync(java.lang.String path,
java.lang.String perms,
java.lang.String dirPerms)
Synchronous version of
chmod(String, String, String, Handler) |
FileSystem |
chown(java.lang.String path,
java.lang.String user,
java.lang.String group,
Handler<AsyncResult<java.lang.Void>> handler)
Change the ownership on the file represented by
path to user and {code group}, asynchronously. |
FileSystem |
chownSync(java.lang.String path,
java.lang.String user,
java.lang.String group)
Synchronous version of
chown(String, String, String, Handler) |
FileSystem |
copy(java.lang.String from,
java.lang.String to,
boolean recursive,
Handler<AsyncResult<java.lang.Void>> handler)
Copy a file from the path
from to path to , asynchronously. |
FileSystem |
copy(java.lang.String from,
java.lang.String to,
Handler<AsyncResult<java.lang.Void>> handler)
Copy a file from the path
from to path to , asynchronously. |
FileSystem |
copySync(java.lang.String from,
java.lang.String to)
Synchronous version of
copy(String, String, Handler) |
FileSystem |
copySync(java.lang.String from,
java.lang.String to,
boolean recursive)
Synchronous version of
copy(String, String, boolean, Handler) |
FileSystem |
createFile(java.lang.String path,
Handler<AsyncResult<java.lang.Void>> handler)
Creates an empty file with the specified
path , asynchronously. |
FileSystem |
createFile(java.lang.String path,
java.lang.String perms,
Handler<AsyncResult<java.lang.Void>> handler)
Creates an empty file with the specified
path and permissions perms , asynchronously. |
FileSystem |
createFileSync(java.lang.String path)
Synchronous version of
createFile(String, Handler) |
FileSystem |
createFileSync(java.lang.String path,
java.lang.String perms)
Synchronous version of
createFile(String, String, Handler) |
FileSystem |
delete(java.lang.String path,
boolean recursive,
Handler<AsyncResult<java.lang.Void>> handler)
Deletes the file represented by the specified
path , asynchronously. |
FileSystem |
delete(java.lang.String path,
Handler<AsyncResult<java.lang.Void>> handler)
Deletes the file represented by the specified
path , asynchronously. |
FileSystem |
deleteSync(java.lang.String path)
Synchronous version of
delete(String, Handler) |
FileSystem |
deleteSync(java.lang.String path,
boolean recursive)
Synchronous version of
delete(String, boolean, Handler) |
FileSystem |
exists(java.lang.String path,
Handler<AsyncResult<java.lang.Boolean>> handler)
Determines whether the file as specified by the path
path exists, asynchronously. |
boolean |
existsSync(java.lang.String path)
Synchronous version of
exists(String, Handler) |
FileSystem |
fsProps(java.lang.String path,
Handler<AsyncResult<FileSystemProps>> handler)
Returns properties of the file-system being used by the specified
path , asynchronously. |
FileSystemProps |
fsPropsSync(java.lang.String path)
Synchronous version of
fsProps(String, Handler) |
FileSystem |
link(java.lang.String link,
java.lang.String existing,
Handler<AsyncResult<java.lang.Void>> handler)
Create a hard link on the file system from
link to existing , asynchronously. |
FileSystem |
linkSync(java.lang.String link,
java.lang.String existing)
Synchronous version of
link(String, String, Handler) |
FileSystem |
lprops(java.lang.String path,
Handler<AsyncResult<FileProps>> handler)
Obtain properties for the link represented by
path , asynchronously. |
FileProps |
lpropsSync(java.lang.String path)
Synchronous version of
lprops(String, Handler) |
FileSystem |
mkdir(java.lang.String path,
boolean createParents,
Handler<AsyncResult<java.lang.Void>> handler)
Create the directory represented by
path , asynchronously. |
FileSystem |
mkdir(java.lang.String path,
Handler<AsyncResult<java.lang.Void>> handler)
Create the directory represented by
path , asynchronously. |
FileSystem |
mkdir(java.lang.String path,
java.lang.String perms,
boolean createParents,
Handler<AsyncResult<java.lang.Void>> handler)
Create the directory represented by
path , asynchronously. |
FileSystem |
mkdir(java.lang.String path,
java.lang.String perms,
Handler<AsyncResult<java.lang.Void>> handler)
Create the directory represented by
path , asynchronously. |
FileSystem |
mkdirSync(java.lang.String path)
Synchronous version of
mkdir(String, Handler) |
FileSystem |
mkdirSync(java.lang.String path,
boolean createParents)
Synchronous version of
mkdir(String, boolean, Handler) |
FileSystem |
mkdirSync(java.lang.String path,
java.lang.String perms)
Synchronous version of
mkdir(String, String, Handler) |
FileSystem |
mkdirSync(java.lang.String path,
java.lang.String perms,
boolean createParents)
Synchronous version of
mkdir(String, String, boolean, Handler) |
FileSystem |
move(java.lang.String from,
java.lang.String to,
Handler<AsyncResult<java.lang.Void>> handler)
Move a file from the path
from to path to , asynchronously. |
FileSystem |
moveSync(java.lang.String from,
java.lang.String to)
Synchronous version of
move(String, String, Handler) |
FileSystem |
open(java.lang.String path,
Handler<AsyncResult<AsyncFile>> handler)
Open the file represented by
path , asynchronously. |
FileSystem |
open(java.lang.String path,
java.lang.String perms,
boolean read,
boolean write,
boolean createNew,
boolean flush,
Handler<AsyncResult<AsyncFile>> handler)
Open the file represented by
path , asynchronously. |
FileSystem |
open(java.lang.String path,
java.lang.String perms,
boolean read,
boolean write,
boolean createNew,
Handler<AsyncResult<AsyncFile>> handler)
Open the file represented by
path , asynchronously. |
FileSystem |
open(java.lang.String path,
java.lang.String perms,
boolean createNew,
Handler<AsyncResult<AsyncFile>> handler)
Open the file represented by
path , asynchronously. |
FileSystem |
open(java.lang.String path,
java.lang.String perms,
Handler<AsyncResult<AsyncFile>> handler)
Open the file represented by
path , asynchronously. |
AsyncFile |
openSync(java.lang.String path)
Synchronous version of
open(String, Handler) |
AsyncFile |
openSync(java.lang.String path,
java.lang.String perms)
Synchronous version of
open(String, String, Handler) |
AsyncFile |
openSync(java.lang.String path,
java.lang.String perms,
boolean createNew)
Synchronous version of
open(String, String, boolean, Handler) |
AsyncFile |
openSync(java.lang.String path,
java.lang.String perms,
boolean read,
boolean write,
boolean createNew)
Synchronous version of
open(String, String, boolean, boolean, boolean, Handler) |
AsyncFile |
openSync(java.lang.String path,
java.lang.String perms,
boolean read,
boolean write,
boolean createNew,
boolean flush)
Synchronous version of
open(String, String, boolean, boolean, boolean, boolean, Handler) |
FileSystem |
props(java.lang.String path,
Handler<AsyncResult<FileProps>> handler)
Obtain properties for the file represented by
path , asynchronously. |
FileProps |
propsSync(java.lang.String path)
Synchronous version of
props(String, Handler) |
FileSystem |
readDir(java.lang.String path,
Handler<AsyncResult<java.lang.String[]>> handler)
Read the contents of the directory specified by
path , asynchronously. |
FileSystem |
readDir(java.lang.String path,
java.lang.String filter,
Handler<AsyncResult<java.lang.String[]>> handler)
Read the contents of the directory specified by
path , asynchronously. |
java.lang.String[] |
readDirSync(java.lang.String path)
Synchronous version of
readDir(String, Handler) |
java.lang.String[] |
readDirSync(java.lang.String path,
java.lang.String filter)
Synchronous version of
readDir(String, String, Handler) |
FileSystem |
readFile(java.lang.String path,
Handler<AsyncResult<Buffer>> handler)
Reads the entire file as represented by the path
path as a Buffer , asynchronously. |
Buffer |
readFileSync(java.lang.String path)
Synchronous version of
readFile(String, Handler) |
FileSystem |
readSymlink(java.lang.String link,
Handler<AsyncResult<java.lang.String>> handler)
Returns the path representing the file that the symbolic link specified by
link points to, asynchronously. |
java.lang.String |
readSymlinkSync(java.lang.String link)
Synchronous version of
readSymlink(String, Handler) |
FileSystem |
symlink(java.lang.String link,
java.lang.String existing,
Handler<AsyncResult<java.lang.Void>> handler)
Create a symbolic link on the file system from
link to existing , asynchronously. |
FileSystem |
symlinkSync(java.lang.String link,
java.lang.String existing)
Synchronous version of
link(String, String, Handler) |
FileSystem |
truncate(java.lang.String path,
long len,
Handler<AsyncResult<java.lang.Void>> handler)
Truncate the file represented by
path to length len in bytes, asynchronously. |
FileSystem |
truncateSync(java.lang.String path,
long len)
Synchronous version of
truncate(String, long, Handler) |
FileSystem |
unlink(java.lang.String link,
Handler<AsyncResult<java.lang.Void>> handler)
Unlinks the link on the file system represented by the path
link , asynchronously. |
FileSystem |
unlinkSync(java.lang.String link)
Synchronous version of
unlink(String, Handler) |
FileSystem |
writeFile(java.lang.String path,
Buffer data,
Handler<AsyncResult<java.lang.Void>> handler)
Creates the file, and writes the specified
Buffer data to the file represented by the path path ,
asynchronously. |
FileSystem |
writeFileSync(java.lang.String path,
Buffer data)
Synchronous version of
writeFile(String, Buffer, Handler) |
FileSystem copy(java.lang.String from, java.lang.String to, Handler<AsyncResult<java.lang.Void>> handler)
from
to path to
, asynchronously.The copy will fail if the destination already exists.
FileSystem copySync(java.lang.String from, java.lang.String to)
copy(String, String, Handler)
FileSystem copy(java.lang.String from, java.lang.String to, boolean recursive, Handler<AsyncResult<java.lang.Void>> handler)
from
to path to
, asynchronously.
If recursive
is true
and from
represents a directory, then the directory and its contents
will be copied recursively to the destination to
.
The copy will fail if the destination if the destination already exists.
FileSystem copySync(java.lang.String from, java.lang.String to, boolean recursive)
copy(String, String, boolean, Handler)
FileSystem move(java.lang.String from, java.lang.String to, Handler<AsyncResult<java.lang.Void>> handler)
from
to path to
, asynchronously.The move will fail if the destination already exists.
FileSystem moveSync(java.lang.String from, java.lang.String to)
move(String, String, Handler)
FileSystem truncate(java.lang.String path, long len, Handler<AsyncResult<java.lang.Void>> handler)
path
to length len
in bytes, asynchronously.
The operation will fail if the file does not exist or len
is less than zero
.
FileSystem truncateSync(java.lang.String path, long len)
truncate(String, long, Handler)
FileSystem chmod(java.lang.String path, java.lang.String perms, Handler<AsyncResult<java.lang.Void>> handler)
path
to perms
, asynchronously.
The permission String takes the form rwxr-x--- as
specified here.FileSystem chmodSync(java.lang.String path, java.lang.String perms)
chmod(String, String, Handler)
FileSystem chmod(java.lang.String path, java.lang.String perms, java.lang.String dirPerms, Handler<AsyncResult<java.lang.Void>> handler)
path
to perms
, asynchronously.
The permission String takes the form rwxr-x--- as
specified in {here}.
If the file is directory then all contents will also have their permissions changed recursively. Any directory permissions will
be set to dirPerms
, whilst any normal file permissions will be set to perms
.
FileSystem chmodSync(java.lang.String path, java.lang.String perms, java.lang.String dirPerms)
chmod(String, String, String, Handler)
FileSystem chown(java.lang.String path, java.lang.String user, java.lang.String group, Handler<AsyncResult<java.lang.Void>> handler)
path
to user
and {code group}, asynchronously.FileSystem chownSync(java.lang.String path, java.lang.String user, java.lang.String group)
chown(String, String, String, Handler)
FileSystem props(java.lang.String path, Handler<AsyncResult<FileProps>> handler)
path
, asynchronously.
If the file is a link, the link will be followed.FileProps propsSync(java.lang.String path)
props(String, Handler)
FileSystem lprops(java.lang.String path, Handler<AsyncResult<FileProps>> handler)
path
, asynchronously.
The link will not be followed.FileProps lpropsSync(java.lang.String path)
lprops(String, Handler)
FileSystem link(java.lang.String link, java.lang.String existing, Handler<AsyncResult<java.lang.Void>> handler)
link
to existing
, asynchronously.FileSystem linkSync(java.lang.String link, java.lang.String existing)
link(String, String, Handler)
FileSystem symlink(java.lang.String link, java.lang.String existing, Handler<AsyncResult<java.lang.Void>> handler)
link
to existing
, asynchronously.FileSystem symlinkSync(java.lang.String link, java.lang.String existing)
link(String, String, Handler)
FileSystem unlink(java.lang.String link, Handler<AsyncResult<java.lang.Void>> handler)
link
, asynchronously.FileSystem unlinkSync(java.lang.String link)
unlink(String, Handler)
FileSystem readSymlink(java.lang.String link, Handler<AsyncResult<java.lang.String>> handler)
link
points to, asynchronously.java.lang.String readSymlinkSync(java.lang.String link)
readSymlink(String, Handler)
FileSystem delete(java.lang.String path, Handler<AsyncResult<java.lang.Void>> handler)
path
, asynchronously.FileSystem deleteSync(java.lang.String path)
delete(String, Handler)
FileSystem delete(java.lang.String path, boolean recursive, Handler<AsyncResult<java.lang.Void>> handler)
path
, asynchronously.
If the path represents a directory and recursive = true
then the directory and its contents will be
deleted recursively.
FileSystem deleteSync(java.lang.String path, boolean recursive)
delete(String, boolean, Handler)
FileSystem mkdir(java.lang.String path, Handler<AsyncResult<java.lang.Void>> handler)
path
, asynchronously.The operation will fail if the directory already exists.
FileSystem mkdirSync(java.lang.String path)
mkdir(String, Handler)
FileSystem mkdir(java.lang.String path, boolean createParents, Handler<AsyncResult<java.lang.Void>> handler)
path
, asynchronously.
If createParents
is set to true
then any non-existent parent directories of the directory
will also be created.
The operation will fail if the directory already exists.
FileSystem mkdirSync(java.lang.String path, boolean createParents)
mkdir(String, boolean, Handler)
FileSystem mkdir(java.lang.String path, java.lang.String perms, Handler<AsyncResult<java.lang.Void>> handler)
path
, asynchronously.
The new directory will be created with permissions as specified by perms
.
The permission String takes the form rwxr-x--- as specified
in here.
The operation will fail if the directory already exists.
FileSystem mkdirSync(java.lang.String path, java.lang.String perms)
mkdir(String, String, Handler)
FileSystem mkdir(java.lang.String path, java.lang.String perms, boolean createParents, Handler<AsyncResult<java.lang.Void>> handler)
path
, asynchronously.
The new directory will be created with permissions as specified by perms
.
The permission String takes the form rwxr-x--- as specified
in here.
If createParents
is set to true
then any non-existent parent directories of the directory
will also be created.
The operation will fail if the directory already exists.
FileSystem mkdirSync(java.lang.String path, java.lang.String perms, boolean createParents)
mkdir(String, String, boolean, Handler)
FileSystem readDir(java.lang.String path, Handler<AsyncResult<java.lang.String[]>> handler)
path
, asynchronously.The result is an array of String representing the paths of the files inside the directory.
java.lang.String[] readDirSync(java.lang.String path)
readDir(String, Handler)
FileSystem readDir(java.lang.String path, java.lang.String filter, Handler<AsyncResult<java.lang.String[]>> handler)
path
, asynchronously.
The parameter filter
is a regular expression. If filter
is specified then only the paths that
match @{filter}will be returned.
The result is an array of String representing the paths of the files inside the directory.
java.lang.String[] readDirSync(java.lang.String path, java.lang.String filter)
readDir(String, String, Handler)
FileSystem readFile(java.lang.String path, Handler<AsyncResult<Buffer>> handler)
path
as a Buffer
, asynchronously.Do not user this method to read very large files or you risk running out of available RAM.
Buffer readFileSync(java.lang.String path)
readFile(String, Handler)
FileSystem writeFile(java.lang.String path, Buffer data, Handler<AsyncResult<java.lang.Void>> handler)
Buffer data
to the file represented by the path path
,
asynchronously.FileSystem writeFileSync(java.lang.String path, Buffer data)
writeFile(String, Buffer, Handler)
FileSystem open(java.lang.String path, Handler<AsyncResult<AsyncFile>> handler)
path
, asynchronously.The file is opened for both reading and writing. If the file does not already exist it will be created. Write operations will not automatically flush to storage.
AsyncFile openSync(java.lang.String path)
open(String, Handler)
FileSystem open(java.lang.String path, java.lang.String perms, Handler<AsyncResult<AsyncFile>> handler)
path
, asynchronously.
The file is opened for both reading and writing. If the file does not already exist it will be created with the
permissions as specified by perms
.
Write operations will not automatically flush to storage.
AsyncFile openSync(java.lang.String path, java.lang.String perms)
open(String, String, Handler)
FileSystem open(java.lang.String path, java.lang.String perms, boolean createNew, Handler<AsyncResult<AsyncFile>> handler)
path
, asynchronously.
The file is opened for both reading and writing. If the file does not already exist and
createNew
is true
it will be created with the permissions as specified by perms
, otherwise
the operation will fail.
Write operations will not automatically flush to storage.
AsyncFile openSync(java.lang.String path, java.lang.String perms, boolean createNew)
open(String, String, boolean, Handler)
FileSystem open(java.lang.String path, java.lang.String perms, boolean read, boolean write, boolean createNew, Handler<AsyncResult<AsyncFile>> handler)
path
, asynchronously.
If read
is true
the file will be opened for reading. If write
is true
the file
will be opened for writing.
If the file does not already exist and
createNew
is true
it will be created with the permissions as specified by perms
, otherwise
the operation will fail.
Write operations will not automatically flush to storage.
AsyncFile openSync(java.lang.String path, java.lang.String perms, boolean read, boolean write, boolean createNew)
open(String, String, boolean, boolean, boolean, Handler)
FileSystem open(java.lang.String path, java.lang.String perms, boolean read, boolean write, boolean createNew, boolean flush, Handler<AsyncResult<AsyncFile>> handler)
path
, asynchronously.
If read
is true
the file will be opened for reading. If write
is true
the file
will be opened for writing.
If the file does not already exist and
createNew
is true
it will be created with the permissions as specified by perms
, otherwise
the operation will fail.
If flush
is true
then all writes will be automatically flushed through OS buffers to the underlying
storage on each write.
AsyncFile openSync(java.lang.String path, java.lang.String perms, boolean read, boolean write, boolean createNew, boolean flush)
open(String, String, boolean, boolean, boolean, boolean, Handler)
FileSystem createFile(java.lang.String path, Handler<AsyncResult<java.lang.Void>> handler)
path
, asynchronously.FileSystem createFileSync(java.lang.String path)
createFile(String, Handler)
FileSystem createFile(java.lang.String path, java.lang.String perms, Handler<AsyncResult<java.lang.Void>> handler)
path
and permissions perms
, asynchronously.FileSystem createFileSync(java.lang.String path, java.lang.String perms)
createFile(String, String, Handler)
FileSystem exists(java.lang.String path, Handler<AsyncResult<java.lang.Boolean>> handler)
path
exists, asynchronously.boolean existsSync(java.lang.String path)
exists(String, Handler)
FileSystem fsProps(java.lang.String path, Handler<AsyncResult<FileSystemProps>> handler)
path
, asynchronously.FileSystemProps fsPropsSync(java.lang.String path)
fsProps(String, Handler)