Package com.flir.thermalsdk.utils
Class FileUtils
java.lang.Object
com.flir.thermalsdk.utils.FileUtils
Helper for handling I/O operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull String
absolutePathToName
(@NotNull String absolutePath) Converts given absolute file path to name, i.e.: - Windows OS: "C:\images\custom\my-file.jpg" to "my-file.jpg" - Unix-based OS: "/home/myuser/dev/images/custom/my-file.jpg" to "my-file.jpg"static @NotNull String
addNameSuffix
(@NotNull String originalAbsolutePath, @NotNull String nameSuffix) Adds a given suffix to the file name keeping file extension, i.e.:
"/home/user1/fileOne.png" is converted into "/home/user1/fileOne_extra.png" if the given suffix was "_extra".static String
prepareFileNameCopy
(@NotNull String absPath) Prepares a unique file name based on the given absolute file path and returns it's absolute path.static String
prepareFileNameCopy
(@NotNull String absPath, @NotNull String extension) Prepares a unique file name based on the given absolute file path and returns it's absolute path.static String
prepareUniqueFileName
(@NotNull String parentDir, @NotNull String filePrefix, @NotNull String fileExtension) Prepares a unique file name and returns it's absolute path.static @NotNull String
remotePathToName
(@NotNull String path) Converts given path to name.static boolean
saveToFile
(String absoluteFilePath, byte[] data) Saves input data to a file.static boolean
saveToFile
(String absoluteFilePath, String data) Saves input data to a file.static @NotNull String
Converts given URL to name.
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
prepareFileNameCopy
public static String prepareFileNameCopy(@NotNull @NotNull String absPath, @NotNull @NotNull String extension) Prepares a unique file name based on the given absolute file path and returns it's absolute path. The file name is based on the given absolute file path. I.e. for the given "my-image.jpg" it returns "my-image_X.jpg", where X is a number uniquely identifying the new file.- Parameters:
absPath
- an absolute file path to original fileextension
- an extension for the new file- Returns:
- Returns new file absolute path or null if the given parent directory is incorrect (not existing or not a directory).
-
prepareFileNameCopy
Prepares a unique file name based on the given absolute file path and returns it's absolute path. The file name is based on the given absolute file path. I.e. for the given "my-image.jpg" it returns "my-image_X.jpg", where X is a number uniquely identifying the new file.- Parameters:
absPath
- an absolute file path to original file- Returns:
- Returns new file absolute path or null if the given parent directory is incorrect (not existing or not a directory).
-
prepareUniqueFileName
public static String prepareUniqueFileName(@NotNull @NotNull String parentDir, @NotNull @NotNull String filePrefix, @NotNull @NotNull String fileExtension) Prepares a unique file name and returns it's absolute path. The file name is based on current time and already existing files in the given directory. The file prefix is optional - may be empty. The file extension is mandatory - it may start with a dot '.'.- Parameters:
parentDir
- a directory where the file will be storedfilePrefix
- a file prefix - can't be null, but can be emptyfileExtension
- file extension - can't be null or empty, may start with a dot '.'- Returns:
- Returns file absolute path or null if the given parent directory is incorrect (not existing or not a directory).
-
saveToFile
Saves input data to a file.- Parameters:
absoluteFilePath
- absolute path to the filedata
- a data to save- Returns:
- Returns true on success, otherwise returns false.
-
saveToFile
Saves input data to a file.- Parameters:
absoluteFilePath
- absolute path to the filedata
- a data to save- Returns:
- Returns true on success, otherwise returns false.
-
urlToName
Converts given URL to name. I.e. "https://www.google.com/my-file.jpg" to "my-file.jpg".- Parameters:
url
- input URL to parse- Returns:
- Returns a plain item/file name.
-
remotePathToName
Converts given path to name. I.e. "\\some\\path\\my-file.jpg" to "my-file.jpg".- Parameters:
path
- input path to parse- Returns:
- Returns a plain item/file name.
-
absolutePathToName
Converts given absolute file path to name, i.e.: - Windows OS: "C:\images\custom\my-file.jpg" to "my-file.jpg" - Unix-based OS: "/home/myuser/dev/images/custom/my-file.jpg" to "my-file.jpg"- Parameters:
absolutePath
- absolute path to parse- Returns:
- Returns a plain item/file name.
-
addNameSuffix
@NotNull public static @NotNull String addNameSuffix(@NotNull @NotNull String originalAbsolutePath, @NotNull @NotNull String nameSuffix) Adds a given suffix to the file name keeping file extension, i.e.:
"/home/user1/fileOne.png" is converted into "/home/user1/fileOne_extra.png" if the given suffix was "_extra".- Parameters:
originalAbsolutePath
- absolute path to the original filenameSuffix
- suffix to add- Returns:
- Returns updated file path with suffix appended.
-