Class FileUtils

java.lang.Object
com.flir.thermalsdk.utils.FileUtils

public final class FileUtils extends Object
Helper for handling I/O operations.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static @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
    urlToName(@NotNull String url)
    Converts given URL to name.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 file
      extension - 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

      public static String prepareFileNameCopy(@NotNull @NotNull String absPath)
      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 stored
      filePrefix - a file prefix - can't be null, but can be empty
      fileExtension - 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

      public static boolean saveToFile(String absoluteFilePath, String data)
      Saves input data to a file.
      Parameters:
      absoluteFilePath - absolute path to the file
      data - a data to save
      Returns:
      Returns true on success, otherwise returns false.
    • saveToFile

      public static boolean saveToFile(String absoluteFilePath, byte[] data)
      Saves input data to a file.
      Parameters:
      absoluteFilePath - absolute path to the file
      data - a data to save
      Returns:
      Returns true on success, otherwise returns false.
    • urlToName

      @NotNull public static @NotNull String urlToName(@NotNull @NotNull String url)
      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

      @NotNull public static @NotNull String remotePathToName(@NotNull @NotNull String path)
      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

      @NotNull public static @NotNull String absolutePathToName(@NotNull @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"
      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 file
      nameSuffix - suffix to add
      Returns:
      Returns updated file path with suffix appended.