
morfologik.tools.ValidateFileExists Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of morfologik-tools Show documentation
Show all versions of morfologik-tools Show documentation
Morfologik Command Line Tools
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