All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.mmsparams.api.utils.FileHelper Maven / Gradle / Ivy

package cz.mmsparams.api.utils;

import java.io.File;
import java.util.Optional;

import cz.mmsparams.api.constants.GenericConstants;
import cz.mmsparams.api.constants.MimeTypeMap;

public class FileHelper
{
    private FileHelper()
    {
    }

    public static Optional getExtension(final File file)
    {
        Preconditions.checkNotNull(file, GenericConstants.FILE);

        final String fileName = file.getName();
        return Optional.ofNullable(fileName).filter(f -> f.contains(".")).map(f -> f.substring(fileName.lastIndexOf('.') + 1));
    }

    public static String getMimeType(final File file)
    {
        Preconditions.checkNotNull(file, GenericConstants.FILE);
        Optional fileExt = getExtension(file);
        String val = Preconditions.checkOptionalFilled(fileExt, GenericConstants.FILE_EXTENSION);
        return MimeTypeMap.getMimeType(val);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy