Package com.example.blogs.app.util
Class FileUtils
java.lang.Object
com.example.blogs.app.util.FileUtils
Utility class for file-related operations including content type detection, filename parsing, and path normalization.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondetectContentType(String extension) Detects the MIME content type based on file extension.extractFileNameParts(String originalFileName) Extracts the name and extension parts from a filename.normalizePath(String filePath) Normalizes a file path by removing leading slash if present.
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
detectContentType
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
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
Normalizes a file path by removing leading slash if present.- Parameters:
filePath- the file path to normalize- Returns:
- normalized file path without leading slash
-