com.crabshue.commons.file.FilenameUtils Maven / Gradle / Ivy
                 Go to download
                
        
                    Show more of this group  Show more artifacts with this name
Show all versions of commons-file Show documentation
                Show all versions of commons-file Show documentation
Library for file system operations.
                
             The newest version!
        
        package com.crabshue.commons.file;
import org.apache.commons.lang3.Validate;
import lombok.NonNull;
/**
 * Utility class for operations on file names.
 *
 */
public class FilenameUtils {
    /**
     * Encode a filename.
     * 
     * The provided filename cannot be null or empty, and its characters are replaced by "_" if different than alphanumeric (case insensitive) and
     * [_,.].
     * 
     *
     * @param filename the filename.
     * @return the encoded filename.
     */
    public static String encodeFilename(@NonNull final String filename) {
        Validate.notEmpty(filename);
        return filename.replaceAll("[^a-zA-Z0-9\\._]", "_");
    }
}
    © 2015 - 2025 Weber Informatics LLC | Privacy Policy