Package de.dlr.proseo.storagemgr.utils
Class FileUtils
java.lang.Object
de.dlr.proseo.storagemgr.utils.FileUtils
A utility class for common file operations. It provides methods to create,
manipulate, and delete files and directories, along with supporting
functionalities such as path handling and file property retrieval.
- Author:
- Denys Chaykovskiy
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCreate path directoriesbooleancreateFile(String content) Creates the file with the contentvoidCreate parent directoriesdelete()Delete the file or the directory with its sub-directories and contained filesvoiddeleteEmptyDirectoriesToTop(String directoryToDelete) Deletes empty directories recursively in the direction of rootDelete the fileGets the file contentlongGets the file sizegetPath()Gets the path to filebooleanChecks if the path points to an empty directoryvoidSets the path to filebooleansynchroCreateFile(String content, long waitTime, long fileCheckMaxCycles) Creates the file with the content in a synchronized modus.
-
Constructor Details
-
FileUtils
Constructor sets the path- Parameters:
path- Path to file
-
-
Method Details
-
getPath
Gets the path to file- Returns:
- the path to file
-
setPath
Sets the path to file- Parameters:
path- the path to set
-
createFile
Creates the file with the content- Parameters:
content- Content of the file- Returns:
- true if file was successfully created
-
synchroCreateFile
Creates the file with the content in a synchronized modus. Returns false if the file was not created/rewritten. creation of the file was not successfully. The waiting thread will unlock the file, which was locked in the locked thread in case of exception - Timeout or Interrupted exception. It is made for unlocking auxiliary files (status and accessed) of the storage manager. Please use this synchronized function carefully.- Parameters:
content- Content of the filewaitTime- the wait time between each cycle of checking the file lock statusfileCheckMaxCycles- file check max cycles- Returns:
- true if file was successfully created
-
getFileSize
public long getFileSize()Gets the file size- Returns:
- the file size
-
isEmptyDirectory
public boolean isEmptyDirectory()Checks if the path points to an empty directory- Returns:
- true if directory is empty
-
getFileContent
Gets the file content- Returns:
- the content of the file
-
createParentDirectories
Create parent directories- Throws:
IllegalStateException- if cannot create dirIllegalArgumentException
-
createDirectories
Create path directories- Throws:
IllegalStateException- if cannot create dirIllegalArgumentException
-
deleteFile
Delete the file- Returns:
- path to the deleted file
- Throws:
IOException- if the file cannot be deleted
-
delete
Delete the file or the directory with its sub-directories and contained files- Returns:
- the paths to the deleted files and directories
- Throws:
IOException- if the file or directory cannot be deleted
-
deleteEmptyDirectoriesToTop
Deletes empty directories recursively in the direction of root- Parameters:
directoryToDelete- the path to the directory
-