Class FileStringParser
java.lang.Object
com.martiansoftware.jsap.StringParser
com.martiansoftware.jsap.PropertyStringParser
com.martiansoftware.jsap.stringparsers.FileStringParser
A StringParser for parsing
File objects. The parse() method
delegates the actual
parsing to new File(String). If new File(String)
throws a NullPointerException, it is encapsulated in a ParseException and
re-thrown.- Since:
- 1.4
- Author:
- Marty Lamb, Edward Glen (edward@glencomm.com) (modified URLStringParser), Eric Sword (made setters return "this", fixed bug triggered when file does not exist)
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FileStringParserReturns a newFileStringParser.booleanbooleanbooleanParses the specified argument into a File.setMustBeDirectory(boolean mustBeDirectory) setMustBeFile(boolean mustBeFile) setMustExist(boolean mustExist) voidsetUp()Performs any initialization not handled by this StringParser's constructor.voidtearDown()Performs any cleanup necessary for this StringParser.Methods inherited from class PropertyStringParser
getProperty, getProperty, setProperty
-
Field Details
-
MUSTBEFILE
- See Also:
-
MUSTBEDIRECTORY
- See Also:
-
MUSTEXIST
- See Also:
-
-
Constructor Details
-
FileStringParser
-
-
Method Details
-
getParser
Returns a newFileStringParser.- Returns:
- a new
FileStringParser.
-
setUp
Description copied from class:StringParserPerforms any initialization not handled by this StringParser's constructor. The contract for this method is that it will be called AT LEAST once before this object's parse() method is called.
In the JSAP API, this method is called every time an Option containing this StringParser is registered with a JSAP. If there is an initialization error, this method should throw a JSAPException to prevent the Option from being registered.- Overrides:
setUpin classStringParser- Throws:
ParseException
-
setMustBeDirectory
-
setMustBeFile
-
setMustExist
-
mustBeDirectory
public boolean mustBeDirectory() -
mustBeFile
public boolean mustBeFile() -
mustExist
public boolean mustExist() -
tearDown
public void tearDown()Description copied from class:StringParserPerforms any cleanup necessary for this StringParser. The contract for this method is that it MAY be called at any time after the setUp method has been called. It may be called more than once.
In the JSAP API, this method is called every time an Option containing this StringParser is unregistered from a JSAP. During finalization, any registered Options are unregistered from a JSAP.- Overrides:
tearDownin classStringParser
-
parse
Parses the specified argument into a File. This method delegates the actual parsing tonew File(arg). Ifnew File(arg)throws a NullPointerException, it is encapsulated in a ParseException and re-thrown.- Specified by:
parsein classStringParser- Parameters:
arg- the argument to parse- Returns:
- a File as specified by arg.
- Throws:
ParseException- ifnew File(arg)throws a NullPointerException.- See Also:
-
getParser().