Interface FileSystem
-
public interface FileSystem
Contains a broad set of operations for manipulating files on the file system.A (potential) blocking and non blocking version of each operation is provided.
The non blocking versions take a handler which is called when the operation completes or an error occurs.
The blocking versions are named
xxxBlocking
and return the results, or throw exceptions directly. In many cases, depending on the operating system and file system some of the potentially blocking operations can return quickly, which is why we provide them, but it's highly recommended that you test how long they take to return in your particular application before using them on an event loop.Please consult the documentation for more information on file system support.
- Author:
- Tim Fox
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Future<Void>
chmod(String path, String perms)
Change the permissions on the file represented bypath
toperms
, asynchronously.FileSystem
chmodBlocking(String path, String perms)
Blocking version ofchmod(String, String)
Future<Void>
chmodRecursive(String path, String perms, String dirPerms)
Change the permissions on the file represented bypath
toperms
, asynchronously.FileSystem
chmodRecursiveBlocking(String path, String perms, String dirPerms)
Blocking version ofchmodRecursive(String, String, String)
Future<Void>
chown(String path, String user, String group)
Change the ownership on the file represented bypath
touser
and {code group}, asynchronously.FileSystem
chownBlocking(String path, String user, String group)
Blocking version ofchown(String, String, String)
Future<Void>
copy(String from, String to)
Copy a file from the pathfrom
to pathto
, asynchronously.Future<Void>
copy(String from, String to, CopyOptions options)
Copy a file from the pathfrom
to pathto
, asynchronously.FileSystem
copyBlocking(String from, String to)
Blocking version ofcopy(String, String)
Future<Void>
copyRecursive(String from, String to, boolean recursive)
Copy a file from the pathfrom
to pathto
, asynchronously.FileSystem
copyRecursiveBlocking(String from, String to, boolean recursive)
Blocking version ofcopyRecursive(String, String, boolean)
Future<Void>
createFile(String path)
Creates an empty file with the specifiedpath
, asynchronously.Future<Void>
createFile(String path, String perms)
Creates an empty file with the specifiedpath
and permissionsperms
, asynchronously.FileSystem
createFileBlocking(String path)
Blocking version ofcreateFile(String)
FileSystem
createFileBlocking(String path, String perms)
Blocking version ofcreateFile(String, String)
Future<String>
createTempDirectory(String prefix)
Creates a new directory in the default temporary-file directory, using the given prefix to generate its name, asynchronously.Future<String>
createTempDirectory(String prefix, String perms)
Creates a new directory in the default temporary-file directory, using the given prefix to generate its name, asynchronously.Future<String>
createTempDirectory(String dir, String prefix, String perms)
Creates a new directory in the directory provided by the pathpath
, using the given prefix to generate its name, asynchronously.String
createTempDirectoryBlocking(String prefix)
Blocking version ofcreateTempDirectory(String)
String
createTempDirectoryBlocking(String prefix, String perms)
Blocking version ofcreateTempDirectory(String, String)
String
createTempDirectoryBlocking(String dir, String prefix, String perms)
Blocking version ofcreateTempDirectory(String, String, String)
Future<String>
createTempFile(String prefix, String suffix)
Creates a new file in the default temporary-file directory, using the given prefix and suffix to generate its name, asynchronously.Future<String>
createTempFile(String prefix, String suffix, String perms)
Creates a new file in the directory provided by the pathdir
, using the given prefix and suffix to generate its name, asynchronously.Future<String>
createTempFile(String dir, String prefix, String suffix, String perms)
Creates a new file in the directory provided by the pathdir
, using the given prefix and suffix to generate its name, asynchronously.String
createTempFileBlocking(String prefix, String suffix)
Blocking version ofcreateTempFile(String, String)
String
createTempFileBlocking(String prefix, String suffix, String perms)
Blocking version ofcreateTempFile(String, String, String)
String
createTempFileBlocking(String dir, String prefix, String suffix, String perms)
Blocking version ofcreateTempFile(String, String, String, String)
Future<Void>
delete(String path)
Deletes the file represented by the specifiedpath
, asynchronously.FileSystem
deleteBlocking(String path)
Blocking version ofdelete(String)
Future<Void>
deleteRecursive(String path, boolean recursive)
Deletes the file represented by the specifiedpath
, asynchronously.FileSystem
deleteRecursiveBlocking(String path, boolean recursive)
Blocking version ofdeleteRecursive(String, boolean)
Future<Boolean>
exists(String path)
Determines whether the file as specified by the pathpath
exists, asynchronously.boolean
existsBlocking(String path)
Blocking version ofexists(String)
Future<FileSystemProps>
fsProps(String path)
Returns properties of the file-system being used by the specifiedpath
, asynchronously.FileSystemProps
fsPropsBlocking(String path)
Blocking version offsProps(String)
Future<Void>
link(String link, String existing)
Create a hard link on the file system fromlink
toexisting
, asynchronously.FileSystem
linkBlocking(String link, String existing)
Blocking version oflink(String, String)
Future<FileProps>
lprops(String path)
Obtain properties for the link represented bypath
, asynchronously.FileProps
lpropsBlocking(String path)
Blocking version oflprops(String)
Future<Void>
mkdir(String path)
Create the directory represented bypath
, asynchronously.Future<Void>
mkdir(String path, String perms)
Create the directory represented bypath
, asynchronously.FileSystem
mkdirBlocking(String path)
Blocking version ofmkdir(String)
FileSystem
mkdirBlocking(String path, String perms)
Blocking version ofmkdir(String, String)
Future<Void>
mkdirs(String path)
Create the directory represented bypath
and any non existent parents, asynchronously.Future<Void>
mkdirs(String path, String perms)
Create the directory represented bypath
and any non existent parents, asynchronously.FileSystem
mkdirsBlocking(String path)
Blocking version ofmkdirs(String)
FileSystem
mkdirsBlocking(String path, String perms)
Blocking version ofmkdirs(String, String)
Future<Void>
move(String from, String to)
Move a file from the pathfrom
to pathto
, asynchronously.Future<Void>
move(String from, String to, CopyOptions options)
Move a file from the pathfrom
to pathto
, asynchronously.FileSystem
moveBlocking(String from, String to)
Blocking version ofmove(String, String)
Future<AsyncFile>
open(String path, OpenOptions options)
Open the file represented bypath
, asynchronously.AsyncFile
openBlocking(String path, OpenOptions options)
Blocking version ofopen(String, io.vertx.core.file.OpenOptions)
Future<FileProps>
props(String path)
Obtain properties for the file represented bypath
, asynchronously.FileProps
propsBlocking(String path)
Blocking version ofprops(String)
Future<List<String>>
readDir(String path)
Read the contents of the directory specified bypath
, asynchronously.Future<List<String>>
readDir(String path, String filter)
Read the contents of the directory specified bypath
, asynchronously.List<String>
readDirBlocking(String path)
Blocking version ofreadDir(String)
List<String>
readDirBlocking(String path, String filter)
Blocking version ofreadDir(String, String)
Future<Buffer>
readFile(String path)
Reads the entire file as represented by the pathpath
as aBuffer
, asynchronously.Buffer
readFileBlocking(String path)
Blocking version ofreadFile(String)
Future<String>
readSymlink(String link)
Returns the path representing the file that the symbolic link specified bylink
points to, asynchronously.String
readSymlinkBlocking(String link)
Blocking version ofreadSymlink(String)
Future<Void>
symlink(String link, String existing)
Create a symbolic link on the file system fromlink
toexisting
, asynchronously.FileSystem
symlinkBlocking(String link, String existing)
Blocking version oflink(String, String)
Future<Void>
truncate(String path, long len)
Truncate the file represented bypath
to lengthlen
in bytes, asynchronously.FileSystem
truncateBlocking(String path, long len)
Blocking version oftruncate(String, long)
Future<Void>
unlink(String link)
Unlinks the link on the file system represented by the pathlink
, asynchronously.FileSystem
unlinkBlocking(String link)
Blocking version ofunlink(String)
Future<Void>
writeFile(String path, Buffer data)
Creates the file, and writes the specifiedBuffer data
to the file represented by the pathpath
, asynchronously.FileSystem
writeFileBlocking(String path, Buffer data)
Blocking version ofwriteFile(String, Buffer)
-
-
-
Method Detail
-
copy
Future<Void> copy(String from, String to)
Copy a file from the pathfrom
to pathto
, asynchronously.The copy will fail if the destination already exists.
- Parameters:
from
- the path to copy fromto
- the path to copy to- Returns:
- a future notified on completion
-
copy
Future<Void> copy(String from, String to, CopyOptions options)
Copy a file from the pathfrom
to pathto
, asynchronously.- Parameters:
from
- the path to copy fromto
- the path to copy tooptions
- options describing how the file should be copied- Returns:
- a future notified on completion
-
copyBlocking
FileSystem copyBlocking(String from, String to)
Blocking version ofcopy(String, String)
-
copyRecursive
Future<Void> copyRecursive(String from, String to, boolean recursive)
Copy a file from the pathfrom
to pathto
, asynchronously.If
recursive
istrue
andfrom
represents a directory, then the directory and its contents will be copied recursively to the destinationto
.The copy will fail if the destination if the destination already exists.
- Parameters:
from
- the path to copy fromto
- the path to copy torecursive
-- Returns:
- a future notified on completion
-
copyRecursiveBlocking
FileSystem copyRecursiveBlocking(String from, String to, boolean recursive)
Blocking version ofcopyRecursive(String, String, boolean)
-
move
Future<Void> move(String from, String to)
Move a file from the pathfrom
to pathto
, asynchronously.The move will fail if the destination already exists.
- Parameters:
from
- the path to copy fromto
- the path to copy to- Returns:
- a future notified on completion
-
move
Future<Void> move(String from, String to, CopyOptions options)
Move a file from the pathfrom
to pathto
, asynchronously.- Parameters:
from
- the path to copy fromto
- the path to copy tooptions
- options describing how the file should be copied- Returns:
- a future notified on completion
-
moveBlocking
FileSystem moveBlocking(String from, String to)
Blocking version ofmove(String, String)
-
truncate
Future<Void> truncate(String path, long len)
Truncate the file represented bypath
to lengthlen
in bytes, asynchronously.The operation will fail if the file does not exist or
len
is less thanzero
.- Parameters:
path
- the path to the filelen
- the length to truncate it to- Returns:
- a future notified on completion
-
truncateBlocking
FileSystem truncateBlocking(String path, long len)
Blocking version oftruncate(String, long)
-
chmod
Future<Void> chmod(String path, String perms)
Change the permissions on the file represented bypath
toperms
, asynchronously.The permission String takes the form rwxr-x--- as specified here.
- Parameters:
path
- the path to the fileperms
- the permissions string- Returns:
- a future notified on completion
-
chmodBlocking
FileSystem chmodBlocking(String path, String perms)
Blocking version ofchmod(String, String)
-
chmodRecursive
Future<Void> chmodRecursive(String path, String perms, String dirPerms)
Change the permissions on the file represented bypath
toperms
, 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 toperms
.- Parameters:
path
- the path to the fileperms
- the permissions stringdirPerms
- the directory permissions- Returns:
- a future notified on completion
-
chmodRecursiveBlocking
FileSystem chmodRecursiveBlocking(String path, String perms, String dirPerms)
Blocking version ofchmodRecursive(String, String, String)
-
chown
Future<Void> chown(String path, String user, String group)
Change the ownership on the file represented bypath
touser
and {code group}, asynchronously.- Parameters:
path
- the path to the fileuser
- the user name,null
will not change the user namegroup
- the user group,null
will not change the user group name- Returns:
- a future notified on completion
-
chownBlocking
FileSystem chownBlocking(String path, String user, String group)
Blocking version ofchown(String, String, String)
-
props
Future<FileProps> props(String path)
Obtain properties for the file represented bypath
, asynchronously.If the file is a link, the link will be followed.
- Parameters:
path
- the path to the file- Returns:
- a future notified on completion
-
propsBlocking
FileProps propsBlocking(String path)
Blocking version ofprops(String)
-
lprops
Future<FileProps> lprops(String path)
Obtain properties for the link represented bypath
, asynchronously.The link will not be followed.
- Parameters:
path
- the path to the file- Returns:
- a future notified on completion
-
lpropsBlocking
FileProps lpropsBlocking(String path)
Blocking version oflprops(String)
-
link
Future<Void> link(String link, String existing)
Create a hard link on the file system fromlink
toexisting
, asynchronously.- Parameters:
link
- the linkexisting
- the link destination- Returns:
- a future notified on completion
-
linkBlocking
FileSystem linkBlocking(String link, String existing)
Blocking version oflink(String, String)
-
symlink
Future<Void> symlink(String link, String existing)
Create a symbolic link on the file system fromlink
toexisting
, asynchronously.- Parameters:
link
- the linkexisting
- the link destination- Returns:
- a future notified on completion
-
symlinkBlocking
FileSystem symlinkBlocking(String link, String existing)
Blocking version oflink(String, String)
-
unlink
Future<Void> unlink(String link)
Unlinks the link on the file system represented by the pathlink
, asynchronously.- Parameters:
link
- the link- Returns:
- a future notified on completion
-
unlinkBlocking
FileSystem unlinkBlocking(String link)
Blocking version ofunlink(String)
-
readSymlink
Future<String> readSymlink(String link)
Returns the path representing the file that the symbolic link specified bylink
points to, asynchronously.- Parameters:
link
- the link- Returns:
- a future notified on completion
-
readSymlinkBlocking
String readSymlinkBlocking(String link)
Blocking version ofreadSymlink(String)
-
delete
Future<Void> delete(String path)
Deletes the file represented by the specifiedpath
, asynchronously.- Parameters:
path
- path to the file- Returns:
- a future notified on completion
-
deleteBlocking
FileSystem deleteBlocking(String path)
Blocking version ofdelete(String)
-
deleteRecursive
Future<Void> deleteRecursive(String path, boolean recursive)
Deletes the file represented by the specifiedpath
, asynchronously.If the path represents a directory and
recursive = true
then the directory and its contents will be deleted recursively.- Parameters:
path
- path to the filerecursive
- delete recursively?- Returns:
- a future notified on completion
-
deleteRecursiveBlocking
FileSystem deleteRecursiveBlocking(String path, boolean recursive)
Blocking version ofdeleteRecursive(String, boolean)
-
mkdir
Future<Void> mkdir(String path)
Create the directory represented bypath
, asynchronously.The operation will fail if the directory already exists.
- Parameters:
path
- path to the file- Returns:
- a future notified on completion
-
mkdirBlocking
FileSystem mkdirBlocking(String path)
Blocking version ofmkdir(String)
-
mkdir
Future<Void> mkdir(String path, String perms)
Create the directory represented bypath
, 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.
- Parameters:
path
- path to the fileperms
- the permissions string- Returns:
- a future notified on completion
-
mkdirBlocking
FileSystem mkdirBlocking(String path, String perms)
Blocking version ofmkdir(String, String)
-
mkdirs
Future<Void> mkdirs(String path)
Create the directory represented bypath
and any non existent parents, asynchronously.The operation will fail if the
path
already exists but is not a directory.- Parameters:
path
- path to the file- Returns:
- a future notified on completion
-
mkdirsBlocking
FileSystem mkdirsBlocking(String path)
Blocking version ofmkdirs(String)
-
mkdirs
Future<Void> mkdirs(String path, String perms)
Create the directory represented bypath
and any non existent parents, 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
path
already exists but is not a directory.- Parameters:
path
- path to the fileperms
- the permissions string- Returns:
- a future notified on completion
-
mkdirsBlocking
FileSystem mkdirsBlocking(String path, String perms)
Blocking version ofmkdirs(String, String)
-
readDir
Future<List<String>> readDir(String path)
Read the contents of the directory specified bypath
, asynchronously.The result is an array of String representing the paths of the files inside the directory.
- Parameters:
path
- path to the file- Returns:
- a future notified on completion
-
readDirBlocking
List<String> readDirBlocking(String path)
Blocking version ofreadDir(String)
-
readDir
Future<List<String>> readDir(String path, String filter)
Read the contents of the directory specified bypath
, asynchronously.The parameter
filter
is a regular expression. Iffilter
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.
- Parameters:
path
- path to the directoryfilter
- the filter expression- Returns:
- a future notified on completion
-
readDirBlocking
List<String> readDirBlocking(String path, String filter)
Blocking version ofreadDir(String, String)
-
readFile
Future<Buffer> readFile(String path)
Reads the entire file as represented by the pathpath
as aBuffer
, asynchronously.Do not use this method to read very large files or you risk running out of available RAM.
- Parameters:
path
- path to the file- Returns:
- a future notified on completion
-
readFileBlocking
Buffer readFileBlocking(String path)
Blocking version ofreadFile(String)
-
writeFile
Future<Void> writeFile(String path, Buffer data)
Creates the file, and writes the specifiedBuffer data
to the file represented by the pathpath
, asynchronously.- Parameters:
path
- path to the file- Returns:
- a future notified on completion
-
writeFileBlocking
FileSystem writeFileBlocking(String path, Buffer data)
Blocking version ofwriteFile(String, Buffer)
-
open
Future<AsyncFile> open(String path, OpenOptions options)
Open the file represented bypath
, asynchronously.The file is opened for both reading and writing. If the file does not already exist it will be created.
- Parameters:
path
- path to the fileoptions
- options describing how the file should be opened- Returns:
- a future notified on completion
-
openBlocking
AsyncFile openBlocking(String path, OpenOptions options)
Blocking version ofopen(String, io.vertx.core.file.OpenOptions)
-
createFile
Future<Void> createFile(String path)
Creates an empty file with the specifiedpath
, asynchronously.- Parameters:
path
- path to the file- Returns:
- a future notified on completion
-
createFileBlocking
FileSystem createFileBlocking(String path)
Blocking version ofcreateFile(String)
-
createFile
Future<Void> createFile(String path, String perms)
Creates an empty file with the specifiedpath
and permissionsperms
, asynchronously.- Parameters:
path
- path to the fileperms
- the permissions string- Returns:
- a future notified on completion
-
createFileBlocking
FileSystem createFileBlocking(String path, String perms)
Blocking version ofcreateFile(String, String)
-
exists
Future<Boolean> exists(String path)
Determines whether the file as specified by the pathpath
exists, asynchronously.- Parameters:
path
- path to the file- Returns:
- a future notified on completion
-
existsBlocking
boolean existsBlocking(String path)
Blocking version ofexists(String)
-
fsProps
Future<FileSystemProps> fsProps(String path)
Returns properties of the file-system being used by the specifiedpath
, asynchronously.- Parameters:
path
- path to anywhere on the filesystem- Returns:
- a future notified on completion
-
fsPropsBlocking
FileSystemProps fsPropsBlocking(String path)
Blocking version offsProps(String)
-
createTempDirectory
Future<String> createTempDirectory(String prefix)
Creates a new directory in the default temporary-file directory, using the given prefix to generate its name, asynchronously.As with the
File.createTempFile
methods, this method is only part of a temporary-file facility.Ashutdown-hook
, or theFile.deleteOnExit()
mechanism may be used to delete the directory automatically.- Parameters:
prefix
- the prefix string to be used in generating the directory's name; may benull
- Returns:
- a future notified on completion
-
createTempDirectoryBlocking
String createTempDirectoryBlocking(String prefix)
Blocking version ofcreateTempDirectory(String)
-
createTempDirectory
Future<String> createTempDirectory(String prefix, String perms)
Creates a new directory in the default temporary-file directory, using the given prefix to generate its name, asynchronously.The new directory will be created with permissions as specified by
The permission String takes the form rwxr-x--- as specified in here.perms
.As with the
File.createTempFile
methods, this method is only part of a temporary-file facility.Ashutdown-hook
, or theFile.deleteOnExit()
mechanism may be used to delete the directory automatically.- Parameters:
prefix
- the prefix string to be used in generating the directory's name; may benull
perms
- the permissions string- Returns:
- a future notified on completion
-
createTempDirectoryBlocking
String createTempDirectoryBlocking(String prefix, String perms)
Blocking version ofcreateTempDirectory(String, String)
-
createTempDirectory
Future<String> createTempDirectory(String dir, String prefix, String perms)
Creates a new directory in the directory provided by the pathpath
, using the given prefix to generate its name, asynchronously.The new directory will be created with permissions as specified by
The permission String takes the form rwxr-x--- as specified in here.perms
.As with the
File.createTempFile
methods, this method is only part of a temporary-file facility.Ashutdown-hook
, or theFile.deleteOnExit()
mechanism may be used to delete the directory automatically.- Parameters:
dir
- the path to directory in which to create the directoryprefix
- the prefix string to be used in generating the directory's name; may benull
perms
- the permissions string- Returns:
- a future notified on completion
-
createTempDirectoryBlocking
String createTempDirectoryBlocking(String dir, String prefix, String perms)
Blocking version ofcreateTempDirectory(String, String, String)
-
createTempFile
Future<String> createTempFile(String prefix, String suffix)
Creates a new file in the default temporary-file directory, using the given prefix and suffix to generate its name, asynchronously.As with the
File.createTempFile
methods, this method is only part of a temporary-file facility.Ashutdown-hook
, or theFile.deleteOnExit()
mechanism may be used to delete the directory automatically.- Parameters:
prefix
- the prefix string to be used in generating the directory's name; may benull
suffix
- the suffix string to be used in generating the file's name; may benull
, in which case ".tmp
" is used- Returns:
- a future notified on completion
-
createTempFileBlocking
String createTempFileBlocking(String prefix, String suffix)
Blocking version ofcreateTempFile(String, String)
-
createTempFile
Future<String> createTempFile(String prefix, String suffix, String perms)
Creates a new file in the directory provided by the pathdir
, using the given prefix and suffix to generate its name, asynchronously.As with the
File.createTempFile
methods, this method is only part of a temporary-file facility.Ashutdown-hook
, or theFile.deleteOnExit()
mechanism may be used to delete the directory automatically.- Parameters:
prefix
- the prefix string to be used in generating the directory's name; may benull
suffix
- the suffix string to be used in generating the file's name; may benull
, in which case ".tmp
" is used- Returns:
- a future notified on completion
-
createTempFileBlocking
String createTempFileBlocking(String prefix, String suffix, String perms)
Blocking version ofcreateTempFile(String, String, String)
-
createTempFile
Future<String> createTempFile(String dir, String prefix, String suffix, String perms)
Creates a new file in the directory provided by the pathdir
, using the given prefix and suffix to generate its name, asynchronously.The new directory will be created with permissions as specified by
The permission String takes the form rwxr-x--- as specified in here.perms
.As with the
File.createTempFile
methods, this method is only part of a temporary-file facility.Ashutdown-hook
, or theFile.deleteOnExit()
mechanism may be used to delete the directory automatically.- Parameters:
dir
- the path to directory in which to create the directoryprefix
- the prefix string to be used in generating the directory's name; may benull
suffix
- the suffix string to be used in generating the file's name; may benull
, in which case ".tmp
" is usedperms
- the permissions string- Returns:
- a future notified on completion
-
-