| 1 |
package morfologik.tools; |
| 2 |
|
| 3 |
import java.nio.file.Files; |
| 4 |
import java.nio.file.Path; |
| 5 |
import java.util.Locale; |
| 6 |
|
| 7 |
import com.beust.jcommander.IValueValidator; |
| 8 |
import com.beust.jcommander.ParameterException; |
| 9 |
|
| 10 |
public final class ValidateFileExists implements IValueValidator<Path> { |
| 11 |
@Override |
| 12 |
public void validate(String name, Path value) throws ParameterException { |
| 13 |
if (!Files.exists(value)) { |
| 14 |
throw new ParameterException(String.format(Locale.ROOT, "%s does not exist: %s", name, value)); |
| 15 |
} |
| 16 |
|
| 17 |
if (!Files.isRegularFile(value)) { |
| 18 |
throw new ParameterException(String.format(Locale.ROOT, "%s is not a file: %s", name, value)); |
| 19 |
} |
| 20 |
|
| 21 |
if (!Files.isReadable(value)) { |
| 22 |
throw new ParameterException(String.format(Locale.ROOT, "%s is not readable: %s", name, value)); |
| 23 |
} |
| 24 |
} |
| 25 |
} |