Class FileArgumentType

java.lang.Object
net.sourceforge.argparse4j.impl.type.FileArgumentType
All Implemented Interfaces:
ArgumentType<File>

public class FileArgumentType extends Object implements 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 Details

    • FileArgumentType

      public FileArgumentType()
  • Method Details

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

      Specified by:
      convert in interface ArgumentType<File>
      Parameters:
      parser - The aprser.
      arg - The argument this type attached to.
      value - The attribute value.
      Returns:
      Converted object.
      Throws:
      ArgumentParserException - If conversion fails.