com.crabshue.commons.file.nio.validation.FileValidationUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-nio-file Show documentation
Show all versions of commons-nio-file Show documentation
Library for file system operations (using java.nio.file).
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);
}
}
}