Module net.sourceforge.argparse4j
Class FileArgumentType
- java.lang.Object
-
- net.sourceforge.argparse4j.impl.type.FileArgumentType
-
- All Implemented Interfaces:
ArgumentType<java.io.File>
public class FileArgumentType extends java.lang.Object implements ArgumentType<java.io.File>
ArgumentType subclass for File type, using fluent style API. This object can convert path string toFile
object. The command-line programs traditionally accept the file path "-" as standard input. This object supports this whenacceptSystemIn()
is used. Also there are several convenient verification features such as checking readability or existence.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
acceptSystemIn
private FileVerification
currentFileVerification
private FileVerification
firstFileVerification
-
Constructor Summary
Constructors Constructor Description FileArgumentType()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileArgumentType
acceptSystemIn()
If the argument is "-", accept it as standard input.java.io.File
convert(ArgumentParser parser, Argument arg, java.lang.String value)
Convertsvalue
to appropriate type.private boolean
isSystemIn(java.io.File file)
FileArgumentType
or()
Start a new verification group.FileArgumentType
verifyCanCreate()
Verifies that the specified path is writable.FileArgumentType
verifyCanExecute()
Verifies that the specified path is executable.FileArgumentType
verifyCanRead()
Verifies that the specified path is readable.FileArgumentType
verifyCanWrite()
Verifies that the specified path is writable.FileArgumentType
verifyCanWriteParent()
Verifies that the parent directory of the specified path is writable.FileArgumentType
verifyExists()
Verifies that the specified path exists.FileArgumentType
verifyIsAbsolute()
Verifies that the specified path is an absolute path.FileArgumentType
verifyIsDirectory()
Verifies that the specified path is a directory.FileArgumentType
verifyIsFile()
Verifies that the specified path is a regular file.FileArgumentType
verifyNotExists()
Verifies that the specified path does not exist.
-
-
-
Field Detail
-
acceptSystemIn
private boolean acceptSystemIn
-
firstFileVerification
private final FileVerification firstFileVerification
-
currentFileVerification
private FileVerification currentFileVerification
-
-
Method Detail
-
acceptSystemIn
public FileArgumentType acceptSystemIn()
If the argument is "-", accept it as standard input. If this method is used, all verification methods will be ignored.- Returns:
- this
-
verifyExists
public FileArgumentType verifyExists()
Verifies that the specified path exists. If the verification fails, error will be reported.- Returns:
- this
-
verifyNotExists
public FileArgumentType verifyNotExists()
Verifies that the specified path does not exist. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsFile
public FileArgumentType verifyIsFile()
Verifies that the specified path is a regular file. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsDirectory
public FileArgumentType verifyIsDirectory()
Verifies that the specified path is a directory. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanRead
public FileArgumentType verifyCanRead()
Verifies that the specified path is readable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWrite
public FileArgumentType verifyCanWrite()
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanWriteParent
public FileArgumentType verifyCanWriteParent()
Verifies that the parent directory of the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanCreate
public FileArgumentType verifyCanCreate()
Verifies that the specified path is writable. If the verification fails, error will be reported.- Returns:
- this
-
verifyCanExecute
public FileArgumentType verifyCanExecute()
Verifies that the specified path is executable. If the verification fails, error will be reported.- Returns:
- this
-
verifyIsAbsolute
public FileArgumentType verifyIsAbsolute()
Verifies that the specified path is an absolute path. If the verification fails, error will be reported.- Returns:
- this
-
or
public FileArgumentType or()
Start a new verification group. Of all verification groups at least 1 must be verified successfully for the file to be accepted.- Returns:
- this
-
convert
public java.io.File convert(ArgumentParser parser, Argument arg, java.lang.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<java.io.File>
- Parameters:
parser
- The parser.arg
- The argument this type attached to.value
- The attribute value.- Returns:
- Converted object.
- Throws:
ArgumentParserException
- If conversion fails.
-
isSystemIn
private boolean isSystemIn(java.io.File file)
-
-