Class FileUtils

java.lang.Object
com.example.blogs.app.util.FileUtils

@Component public class FileUtils extends Object
Utility class for file-related operations including content type detection, filename parsing, and path normalization.
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • detectContentType

      public String detectContentType(String extension)
      Detects the MIME content type based on file extension.
      Parameters:
      extension - the file extension including the dot (e.g., ".png")
      Returns:
      the MIME type string, or "application/octet-stream" if unknown
    • extractFileNameParts

      public FileNameParts extractFileNameParts(String originalFileName)
      Extracts the name and extension parts from a filename.
      Parameters:
      originalFileName - the original filename to parse
      Returns:
      file name parts with name and extension separated
    • normalizePath

      public String normalizePath(String filePath)
      Normalizes a file path by removing leading slash if present.
      Parameters:
      filePath - the file path to normalize
      Returns:
      normalized file path without leading slash