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

morfologik.tools.ValidateFileExists Maven / Gradle / Ivy

There is a newer version: 2.1.9
Show newest version
package morfologik.tools;

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

import com.beust.jcommander.IValueValidator;
import com.beust.jcommander.ParameterException;

public final class ValidateFileExists implements IValueValidator {
  @Override
  public void validate(String name, Path value) throws ParameterException {
    if (!Files.exists(value)) {
      throw new ParameterException(String.format(Locale.ROOT, "%s does not exist: %s", name, value));
    }

    if (!Files.isRegularFile(value)) {
      throw new ParameterException(String.format(Locale.ROOT, "%s is not a file: %s", name, value));
    }

    if (!Files.isReadable(value)) {
      throw new ParameterException(String.format(Locale.ROOT, "%s is not readable: %s", name, value));
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy