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

com.github.swamim.media.organizer.utils.FileNameUtils Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
package com.github.swamim.media.organizer.utils;

import java.nio.file.Path;
import java.util.Optional;
import java.util.UUID;

public class FileNameUtils {

    private FileNameUtils() {
    }

    public static String getExtension(String filename) {
        return Optional.ofNullable(filename)
                .filter(f -> f.contains("."))
                .map(f -> f.substring(filename.lastIndexOf(".") + 1)).orElse("");
    }

    public static String getFileNameWithoutExtension(String filename) {
        return Optional.ofNullable(filename)
                .filter(f -> f.contains("."))
                .map(f -> f.substring(0, filename.lastIndexOf("."))).orElse("");
    }


    public static String getNameForFileCopy(Path src) {
        return getFileNameWithoutExtension(src.getFileName().toString()) + "_COPY_" + UUID.randomUUID().toString() + "."+
                getExtension(src.getFileName().toString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy