Package com.castlabs.utils
Class FileHelper
java.lang.Object
com.castlabs.utils.FileHelper
The file helper contains utility functions to work with files and folders, including recursive
listings, recursive deletes and file and folder copy.
- Since:
- 2.0.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Converts remote URI to local file pathstatic void
Copies files and directories.static String
decodeApid
(String encodedApi) Decodes the given apidstatic void
deleteRecursive
(File fileOrDirectory) Recursively delete the given file or directorystatic String
encodeApid
(String apid) Encodes teh given apidstatic String
encodeFileName
(String fileName) Remove illegal characters from file nameslistFiles
(File rootDir, FileFilter filter, boolean recursive) List all the files in a given folder.
-
Constructor Details
-
FileHelper
public FileHelper()
-
-
Method Details
-
encodeFileName
Remove illegal characters from file names- Parameters:
fileName
- the file name- Returns:
- the cleaned file name
-
listFiles
List all the files in a given folder. If the root folder is not a directory or does not exists, an empty list is returned. If a file filter is given here, the filter is only applied to files in the result list. It is not used to filter folder during recursive search.- Parameters:
rootDir
- the root folderfilter
- the file filter applied to limit the results (optional)recursive
- if true, the folder is searched recursively- Returns:
- list of files in the given root folder
-
copy
Copies files and directories.- Parameters:
sourceLocation
- the source file or directorytargetLocation
- the target- Throws:
IOException
- in case an error occurred
-
encodeApid
Encodes teh given apid- Parameters:
apid
- the apid- Returns:
- encoded apid
-
decodeApid
Decodes the given apid- Parameters:
encodedApi
- the encoded apid- Returns:
- the decoded apid
-
deleteRecursive
Recursively delete the given file or directory- Parameters:
fileOrDirectory
- the file or directory
-
readLines
- Parameters:
file
- the source file- Returns:
- list of lines of the given file
- Throws:
IOException
- in case of an error while reading the file- Since:
- 2.1.7
-
convertToLocalFilePath
Converts remote URI to local file path- Parameters:
uri
- the URI- Returns:
- local file path
-