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

com.crabshue.commons.file.nio.validation.FileValidationUtils Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package com.crabshue.commons.file.nio.validation;

import java.nio.file.Files;
import java.nio.file.Path;

import com.crabshue.commons.exceptions.ValidationException;
import com.crabshue.commons.file.nio.exceptions.FileErrorContext;
import com.crabshue.commons.file.nio.exceptions.FileErrorType;
import lombok.NonNull;

public class FileValidationUtils {

    public static void validateFolder(@NonNull final Path folderPath) {

        if (!Files.isDirectory(folderPath)) {
            throw new ValidationException(FileErrorType.NOT_A_FOLDER)
                .addContextValue(FileErrorContext.FOLDER, folderPath);
        }
    }

    public static void validateFile(@NonNull final Path filePath) {

        if (!Files.isRegularFile(filePath)) {
            throw new ValidationException(FileErrorType.NOT_A_FILE)
                .addContextValue(FileErrorContext.FILE, filePath);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy