Class FileUtils

java.lang.Object
org.qubership.atp.itf.lite.backend.utils.FileUtils

public class FileUtils extends Object
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • deleteDirectoryRecursively

      public static void deleteDirectoryRecursively(Path directory) throws IOException
      Deletes directory recursively.
      Parameters:
      directory - directory
      Throws:
      IOException - IOException
    • prepareDirectoriesBeforeSave

      public static Path prepareDirectoriesBeforeSave(Path dictionariesFolder, UUID requestId) throws IOException
      Prepares directories before dictionary save.
      Parameters:
      dictionariesFolder - dictionaries folder
      requestId - request id
      Returns:
      Created request folder path
      Throws:
      IOException - could be problem with recording to file system
    • saveMultipartFileDictionaryToFileSystem

      public static void saveMultipartFileDictionaryToFileSystem(Path dictionariesFolder, UUID requestId, org.springframework.web.multipart.MultipartFile dictionary) throws IOException
      Saves multipart file dictionary to requestId's directory.
      Parameters:
      dictionariesFolder - dictionaries folder
      requestId - request id
      dictionary - zipped dictionary
      Throws:
      IOException - could be problem with recording to file system
    • saveMultipartFileFormDataToFileSystem

      public static void saveMultipartFileFormDataToFileSystem(Path formDataFolder, UUID requestId, org.springframework.web.multipart.MultipartFile file) throws IOException
      Saves multipart file form-data to requestId's directory.
      Parameters:
      formDataFolder - form-data folder
      requestId - request id
      file - zipped dictionary
      Throws:
      IOException - could be problem with recording to file system
    • saveFileDataDictionaryToFileSystem

      public static Path saveFileDataDictionaryToFileSystem(Path dictionariesFolder, UUID requestId, FileData dictionaryFileData) throws IOException
      Saves byte array dictionary to requestId's directory.
      Parameters:
      dictionariesFolder - dictionaries folder
      requestId - request id
      dictionaryFileData - zipped dictionary bytes
      Throws:
      IOException - could be problem with recording to file system
    • sanitizeFileName

      public static String sanitizeFileName(String fileName)
      Add fileName sanitation to avoid Path Traversal vulnerability.
      Parameters:
      fileName - fileName
      Returns:
      sanitized fileName
    • readFileToString

      public static Optional<String> readFileToString(org.springframework.web.multipart.MultipartFile file) throws IOException
      Get Multipart file how string.
      Throws:
      IOException
    • guessContentTypeFromName

      public static org.apache.http.entity.ContentType guessContentTypeFromName(String fileName)