public final class DefaultCmdlineContext extends Object implements CmdlineContext
CmdlineContext.ExitWithNonZeroStatus, CmdlineContext.ExitWithZeroStatus
Constructor and Description |
---|
DefaultCmdlineContext()
Construct.
|
Modifier and Type | Method and Description |
---|---|
PrintStream |
err()
Error stream, usually mapped to
System.err . |
void |
exit(int status)
Terminate execution with given status code.
|
InputStream |
in()
Input stream, usually mapped to
System.in . |
boolean |
isFileExists(String name)
Check if a file exists.
|
InputStream |
openFileInput(String name)
Open a file for reading.
|
OutputStream |
openFileOutput(String name)
Open a file for writing.
|
InputStream |
openUrlStream(String spec)
Open a connection to an URL.
|
PrintStream |
out()
Output stream, usually mapped to
System.out . |
SeekableFileOutput |
seekableFileOutput(String name)
Open a seekable file for writing.
|
public PrintStream out()
CmdlineContext
System.out
.out
in interface CmdlineContext
public PrintStream err()
CmdlineContext
System.err
.err
in interface CmdlineContext
public InputStream in()
CmdlineContext
System.in
.in
in interface CmdlineContext
public InputStream openFileInput(String name) throws FileNotFoundException
CmdlineContext
FileInputStream.FileInputStream(java.lang.String)
.openFileInput
in interface CmdlineContext
name
- File name to openFileNotFoundException
public OutputStream openFileOutput(String name) throws FileNotFoundException
CmdlineContext
FileOutputStream.FileOutputStream(java.lang.String)
.openFileOutput
in interface CmdlineContext
name
- File name to openFileNotFoundException
public SeekableFileOutput seekableFileOutput(String name) throws FileNotFoundException
CmdlineContext
seekableFileOutput
in interface CmdlineContext
name
- File name to openFileNotFoundException
public void exit(int status) throws CmdlineContext.ExitWithZeroStatus, CmdlineContext.ExitWithNonZeroStatus
CmdlineContext
System.exit(int)
. Test time implementations might decide to throw
CmdlineContext.ExitWithZeroStatus
or CmdlineContext.ExitWithNonZeroStatus
instead of delegating to System.exit(int)
.
These RuntimeException
s are helps for test implementations, regular application code must not catch them.exit
in interface CmdlineContext
status
- Status code; by convention nonzero status code indicates abnormal terminationCmdlineContext.ExitWithZeroStatus
- Test time implementation might throw this instead of delegating to
System.exit(int)
Note that normal application code must not catch this.CmdlineContext.ExitWithNonZeroStatus
- Test time implementation might throw this instead of delegating to
System.exit(int)
Note that normal application code must not catch this.public boolean isFileExists(String name)
CmdlineContext
File.exists()
of an instance created by File.File(java.lang.String)
.isFileExists
in interface CmdlineContext
name
- File name to checktrue
when given file existspublic InputStream openUrlStream(String spec) throws IOException
CmdlineContext
URL.openStream()
of an instance created by URL.URL(java.lang.String)
.openUrlStream
in interface CmdlineContext
spec
- The String
to parse as an URL.IOException
- propagated