Class FileArgumentType
java.lang.Object
net.sourceforge.argparse4j.impl.type.FileArgumentType
- All Implemented Interfaces:
ArgumentType<File>
ArgumentType subclass for File type, using fluent style API.
This object can convert path string to
File
object. The
command-line programs traditionally accept the file path "-" as standard
input. This object supports this when
acceptSystemIn()
is used. Also there are several
convenient verification features such as checking readability or existence.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionIf the argument is "-", accept it as standard input.convert
(ArgumentParser parser, Argument arg, String value) Convertsvalue
to appropriate type.Verifies that the specified path is writable.Verifies that the specified path is executable.Verifies that the specified path is readable.Verifies that the specified path is writable.Verifies that the parent directory of the specified path is writable.Verifies that the specified path exists.Verifies that the specified path is an absolute path.Verifies that the specified path is a directory.Verifies that the specified path is a regular file.Verifies that the specified path does not exist.
-
Constructor Details
-
FileArgumentType
public FileArgumentType()
-
-
Method Details
-
acceptSystemIn
If the argument is "-", accept it as standard input. If this method is used, all verification methods will be ignored.- Returns:
- this
-
verifyExists
Verifies that the specified path exists. If the verification fails, error will be reported.- Returns:
- this
-
verifyNotExists
Verifies that the specified path does not exist. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsFile
Verifies that the specified path is a regular file. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsDirectory
Verifies that the specified path is a directory. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanRead
Verifies that the specified path is readable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWrite
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWriteParent
Verifies that the parent directory of the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanCreate
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanExecute
Verifies that the specified path is executable. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsAbsolute
Verifies that the specified path is an absolute path. If the verification fails, error will be reported.- Returns:
- this
-
convert
public File convert(ArgumentParser parser, Argument arg, String value) throws ArgumentParserException Description copied from interface:ArgumentType
Converts
value
to appropriate type.If the objects derived from
RuntimeException
are thrown in conversion because of invalid input from command line, subclass must catch these exceptions and wrap them inArgumentParserException
and give simple error message to explain what happened briefly.- Specified by:
convert
in interfaceArgumentType<File>
- Parameters:
parser
- The aprser.arg
- The argument this type attached to.value
- The attribute value.- Returns:
- Converted object.
- Throws:
ArgumentParserException
- If conversion fails.
-