java.lang.Object | |
↳ | com.atlassian.bitbucket.util.MoreFiles |
Additional utility methods missing from Files.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Deletes any files or subdirectories in the specified directory and leaves the directory empty.
| |||||||||||
Registers the provided path to be deleted when the JVM exits.
| |||||||||||
Recursively deletes the specified path, suppressing any IOException s
that are thrown. | |||||||||||
Recursively deletes the specified path.
| |||||||||||
Gets the
last modified time for the specified Path, in
milliseconds. | |||||||||||
Returns
true if the specified path is contained within the expectedParent . | |||||||||||
Creates the specified
child directory beneath the parent , if it does not already exist. | |||||||||||
Creates the specified
directory , if it does not already exist. | |||||||||||
Validates that the specified path is contained within the
expectedParent . | |||||||||||
Simplifies
resolving several subpaths in a single call. | |||||||||||
Sets the file permissions according to the specifications provided in the
request . | |||||||||||
Gets the
size of the specified Path. | |||||||||||
Reads the entire contents of the specified path using the provided character set.
| |||||||||||
Reads the entire contents of the specified path using the UTF-8 character set.
| |||||||||||
Calculates the total size of the specified path.
| |||||||||||
Creates the specified path, if it doesn't exist, or
sets its last modified time if it does. | |||||||||||
Writes the provided value to the specified path using the UTF-8 character set.
| |||||||||||
Writes the provided value to the specified path using the provided character set.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Deletes any files or subdirectories in the specified directory and leaves the directory empty.
directory | the directory to clean |
---|
IOException | if the path does not denote a directory, or the directory's contents could not be deleted |
---|
Registers the provided path to be deleted when the JVM exits.
Delete-on-exit is performed on a best-effort basis, and should not be relied upon as the primary solution for deleting files. Additionally, it only works for files and empty directories.
path | the path to register for deletion when the JVM exits |
---|
Recursively deletes
the specified path, suppressing any IOException
s
that are thrown.
path | the path to delete, which may be a file or a directory |
---|
true
if the path was deleted; otherwise, false
if it did not exist or could not
be deleted
Recursively deletes the specified path.
If the specified Path denotes a directory, the directory's contents are recursively deleted, depth-first, to empty the directory so it can be deleted. If any files or subdirectories can't be deleted, an exception will be thrown. Note that some files and subdirectories may have been deleted prior to the exception being thrown. Additionally, if the directory contains any symbolic links the links themselves are deleted, not their targets.
If the specified Path denotes a symbolic link, the symbolic link itself is deleted, rather than the target of the link. If the path is a symbolic link to a directory, that directory's contents are not removed.
If the specified Path denotes a file, it is deleted.
If the specified path does not exist, nothing happens and no exception is thrown.
path | the path to delete, which may be a file or a directory |
---|
IOException | if the specified path cannot be deleted |
---|
Gets the last modified time
for the specified Path, in
milliseconds.
Like lastModified()
, if the path does not exist or its attributes cannot be read, 0L
is returned rather than throwing an exception. Use getLastModifiedTime(Path, LinkOption...)
directly if an
exception is desired.
path | the path to retrieve the last modified time for |
---|
0L
if the time could not be determined
Returns true
if the specified path is contained within the expectedParent
. This should be
used to ensure paths created with user-entered data don't "escape" the specified parent, to prevent path
traversal attacks.
path | the path to validate |
---|---|
expectedParent | the required parent directory |
true
if path
is contained within expectedParent
; otherwise, false
IllegalArgumentException | if expectedParent does not exist or is not a directory |
---|---|
IOException | if the real path for either of the provided paths cannot be resolved |
Creates the specified child
directory beneath the parent
, if it does not already exist. If the
path does exist, it is validated that it is a directory and not a file.
parent | the base path for creating the new directory |
---|---|
child | the path beneath the parent for the new directory |
IllegalArgumentException | if the child path is blank or empty |
---|---|
IllegalStateException | if the child path already exists and is not a directory, or if the
directory cannot be created |
NullPointerException | if the provided parent or child is null
|
Creates the specified directory
, if it does not already exist. If the path does exist, it is validated
that it is a directory and not a file.
directory | the directory to create |
---|
IllegalStateException | if the directory path already exists and is not a directory, or if the
directory cannot be created |
---|---|
NullPointerException | if the provided directory is null
|
Validates that the specified path is contained within the expectedParent
. This should be used to
ensure paths created with user-entered data don't "escape" the specified parent, to prevent path traversal
attacks.
path | the path to validate |
---|---|
expectedParent | the required parent directory |
IllegalArgumentException | if expectedParent does not exist or is not a directory, or if
path is not contained within it |
---|---|
IOException | if the real path for either of the provided paths cannot be resolved |
Simplifies resolving
several subpaths in a single call.
path | the base path, from which subpaths should be resolved |
---|---|
first | the first subpath, used to enforce that at least a single subpath is provided |
more | zero or more additional subpaths |
Sets the file permissions according to the specifications provided in the request
.
For Unix systems this will map the provided permissions to the corresponding PosixFilePermission.
For Windows systems AclEntry ACL entries will be put together as follows:
Owner permissions
: These will be applied to the
Files#getOwner(Path, java.nio.file.LinkOption...) owner principal. Also, for convenience,
they will be applied to the Administrator
group (if it exists) since its members can override
ACLs anywayWorld permissions
: These will be applied to the
Everyone
group.Group permissions
: These will be ignored.
In POSIX-compliant OSes files and directories are associated with both a user and a group and
the permission model explicitly provides for setting a group permission agnostic of the group's name.
The ACL model used by Windows requires knowing the name of the group you want to provision.request | describes the file permissions to set |
---|
IllegalArgumentException | if the provided path does not exist,
or exists and is not a regular file
|
---|---|
IOException |
Gets the size
of the specified Path.
Like length()
, if the path does not exist or its attributes cannot be read, 0L
is
returned rather than throwing an exception. Use size(Path)
directly if an exception is desired.
path | the path to retrieve the size of |
---|
0L
if the size could not be determined
Reads the entire contents of the specified path using the provided character set.
Callers should exercise caution when using this method, as it may result in reading a significant amount of data into memory. Where possible, callers are encouraged to stream file contents instead.
path | the path to read |
---|---|
charset | the character set to use to decode the file's contents |
IOException | if the file cannot be read |
---|
Reads the entire contents of the specified path using the UTF-8 character set.
Callers should exercise caution when using this method, as it may result in reading a significant amount of data into memory. Where possible, callers are encouraged to stream file contents instead.
path | the path to read |
---|
IOException | if the file cannot be read |
---|
Calculates the total size of the specified path.
If the specified Path denotes a directory, its contents are recursively traversed to compute its overall size. For directories containing a large number of files this can be quite slow, so it should be used with caution.
If the specified Path denotes a symbolic link, its size (generally the length of its target path) is reported. Symbolic links are not followed.
If the specified Path denotes a file, its size is reported.
path | the path to calculate a size for |
---|
0L
if the size could not be calculated
Creates
the specified path, if it doesn't exist, or
sets its last modified time
if it does.
path | the path to create or set a last modification time for |
---|
IOException | if a nonexistent file cannot be created, or if the last modification time cannot be set for an existing file |
---|
Writes the provided value to the specified path using the UTF-8 character set.
path | the path to write |
---|---|
value | the value to write |
options | OpenOptions to control how the path is accessed |
IOException | if the file cannot be written |
---|
Writes the provided value to the specified path using the provided character set.
path | the path to write |
---|---|
value | the value to write |
charset | the character set to use to encode the value to bytes |
options | OpenOptions to control how the path is accessed |
IOException | if the file cannot be written |
---|