@ThreadSafe public final class FileUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
changeLocalFileGroup(String path,
String group)
Changes the local file's group.
|
static void |
changeLocalFilePermission(String filePath,
String perms)
Changes local file's permission.
|
static void |
changeLocalFileToFullPermission(String filePath)
Changes local file's permission to be "rwxrwxrwx".
|
static void |
changeLocalFileUser(String path,
String user)
Changes the local file's user.
|
static void |
createBlockPath(String path,
String workerDataFolderPermissions)
Creates the local block path and all the parent directories.
|
static void |
createDir(String path)
Creates an empty directory and its intermediate directories if necessary.
|
static void |
createFile(String filePath)
Creates an empty file and its intermediate directories if necessary.
|
static boolean |
createStorageDirPath(String path,
String workerDataFolderPermissions)
Creates the storage directory path, including any necessary but nonexistent parent directories.
|
static void |
delete(String path)
Deletes the file or directory.
|
static void |
deletePathRecursively(String path)
Deletes a file or a directory, recursively if it is a directory.
|
static boolean |
exists(String path)
Checks if a path exists.
|
static short |
getLocalFileMode(String filePath)
Gets local file's permission mode.
|
static boolean |
isStorageDirAccessible(String path)
Checks if a storage directory path is accessible.
|
static void |
move(String srcPath,
String dstPath)
Moves file from one place to another, can across storage devices (e.g., from memory to SSD)
when
File.renameTo(java.io.File) may not work. |
static void |
setLocalDirStickyBit(String dir)
Sticky bit can be set primarily on directories in UNIX / Linux.
|
static Set<PosixFilePermission> |
translateModeToPosixPermissions(int mode)
Translate mode to posix file permissions.
|
static short |
translatePosixPermissionToMode(Set<PosixFilePermission> permission)
Translate posix file permissions to short mode.
|
public static void changeLocalFileGroup(String path, String group) throws IOException
path
- that will change ownergroup
- the new groupIOException
public static void changeLocalFilePermission(String filePath, String perms)
filePath
- that will change permissionperms
- the permission, e.g. "rwxr--r--"public static void changeLocalFileToFullPermission(String filePath)
filePath
- that will change permissionpublic static short getLocalFileMode(String filePath) throws IOException
filePath
- the file pathIOException
public static short translatePosixPermissionToMode(Set<PosixFilePermission> permission)
permission
- posix file permissionpublic static Set<PosixFilePermission> translateModeToPosixPermissions(int mode)
mode
- the file modepublic static void changeLocalFileUser(String path, String user) throws IOException
path
- that will change owneruser
- the new userIOException
public static void setLocalDirStickyBit(String dir)
dir
- absolute dir path to set the sticky bitpublic static void createBlockPath(String path, String workerDataFolderPermissions)
path
- the path of the blockworkerDataFolderPermissions
- The permissions to set on the worker's data folderpublic static void move(String srcPath, String dstPath) throws IOException
File.renameTo(java.io.File)
may not work.srcPath
- pathname string of source filedstPath
- pathname string of destination fileIOException
public static void delete(String path)
path
- pathname string of file or directorypublic static void deletePathRecursively(String path) throws IOException
path
- pathname to be deletedIOException
public static boolean createStorageDirPath(String path, String workerDataFolderPermissions)
path
- storage directory path to createworkerDataFolderPermissions
- the permissions to set for the worker's data folderpublic static void createFile(String filePath)
filePath
- pathname string of the file to createpublic static void createDir(String path) throws IOException
path
- path of the directory to createIOException
public static boolean exists(String path)
path
- the given pathpublic static boolean isStorageDirAccessible(String path)
path
- the given pathCopyright © 2023. All Rights Reserved.