Class 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 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.
    • Field Detail

      • acceptSystemIn

        private boolean acceptSystemIn
    • Constructor Detail

      • FileArgumentType

        public FileArgumentType()
    • 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 in ArgumentParserException and give simple error message to explain what happened briefly.

        Specified by:
        convert in interface ArgumentType<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)