Class SafeFilenameSanitizer
java.lang.Object
io.github.rabinarayanpatra.sanitizer.builtin.SafeFilenameSanitizer
- All Implemented Interfaces:
FieldSanitizer<String>
Sanitizer that replaces characters not allowed in most filenames with
underscores.
This includes characters like \ / : * ? " < > |, which are restricted
on Windows and other common filesystems. Useful for safely storing
user-generated filenames or exporting reports.
String input = "user:data/report|2025?.pdf";
String safe = new SafeFilenameSanitizer().sanitize(input); // "user_data_report_2025_.pdf"
- Since:
- 1.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
SafeFilenameSanitizer
public SafeFilenameSanitizer()Default constructor.
-
-
Method Details
-
sanitize
Replaces filesystem-reserved characters with underscores in the input string.- Specified by:
sanitizein interfaceFieldSanitizer<String>- Parameters:
in- the proposed filename string- Returns:
- a sanitized filename-safe string, or
nullif input isnull
-