Package com.sk89q.worldedit.util.io.file
Class SafeFiles
java.lang.Object
com.sk89q.worldedit.util.io.file.SafeFiles
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
canonicalFileName
(Path path) Path.getFileName()
includes a slash sometimes for some reason.static FileAttribute<?>[]
getOwnerOnlyFileAttributes
(AttributeTarget attributeTarget) Get a set of file attributes for file creation with owner-only access, if possible.noLeakFileList
(Path dir) A version ofFiles.list(Path)
that won't leak resources.static void
tryHardToDelete
(Path path) Tries to delete a path.static void
tryHardToDeleteDir
(Path directory) Recursively usestryHardToDelete(Path)
to cleanup directories before deleting them.
-
Method Details
-
noLeakFileList
A version ofFiles.list(Path)
that won't leak resources.Instead, it immediately consumes the entire listing into a
List
and callsCollection.stream()
.- Parameters:
dir
- the directory to list- Returns:
- an I/O-resource-free stream of the files in the directory
- Throws:
IOException
- if an I/O error occurs
-
canonicalFileName
Path.getFileName()
includes a slash sometimes for some reason. This will get rid of it.- Parameters:
path
- the path to get the file name for- Returns:
- the file name of the given path
-
tryHardToDeleteDir
Recursively usestryHardToDelete(Path)
to cleanup directories before deleting them.- Parameters:
directory
- the directory to delete- Throws:
IOException
- if an error occurs trying to delete the directory
-
tryHardToDelete
Tries to delete a path. If it fails the first time, uses an implementation detail to try and make it possible to delete the path, and then tries again. If that fails, throws anIOException
with both errors.- Parameters:
path
- the path to delete- Throws:
IOException
- if the path could not be deleted after multiple attempts
-
getOwnerOnlyFileAttributes
Get a set of file attributes for file creation with owner-only access, if possible.On POSIX, this returns o+rw (and o+x if directory), on Windows it returns nothing.
- Returns:
- the owner-only file attributes
-