public interface Environment
A Environment object is a substitute for the usual environment
as defined in the System class, most important the
stdin and stdout channels System.in
and System.out.
Environments are especially useful in classes that can be used both standalone
(having a main method) or in an application where the class is
only one of many. Another scenario would be a simple class designed for use
from the command line that should suddenly be invoked in GUI framework without
redirecting the default channels System.in and
System.out.
To obtain an Environment instance or to store such instances
use the class EnvironmentProvider:
Environment env = EnvironmentProvider.getEnvironment(this);
| Modifier and Type | Method and Description |
|---|---|
java.io.PrintStream |
err()
This method returns the substitution for
System.err, the
standard error channel. |
void |
exit()
This method exits the instance of its
Environment implementation. |
int |
getExitStatus()
Retrieving the currently set exit code.
|
java.io.InputStream |
in()
This method returns the substitution for
System.in, the
standard input channel. |
java.io.PrintStream |
out()
This method returns the substitution for
System.out, the
standard output channel. |
void |
setExitStatus(int status)
During different stages of program execution various exit codes can be set
using this method.
|
java.io.InputStream in()
throws java.lang.UnsupportedOperationException
System.in, the
standard input channel. Instead of a public member like in the System
class, we prefer the method version since it is more flexible.InputStream that serves as standard inputjava.lang.UnsupportedOperationException - if there is no stdin channel availableSystem.injava.io.PrintStream out()
throws java.lang.UnsupportedOperationException
System.out, the
standard output channel. Instead of a public member like in the System
class, we prefer the method version since it is more flexible.PrintStream that serves as standard outputjava.lang.UnsupportedOperationException - if there is no stdout channel availableSystem.outjava.io.PrintStream err()
throws java.lang.UnsupportedOperationException
System.err, the
standard error channel. Instead of a public member like in the System
class, we prefer the method version since it is more flexible.PrintStream that serves as standard error outputjava.lang.UnsupportedOperationException - if there is no stderr channel availableSystem.errvoid setExitStatus(int status)
status - the exit code of an applicationSystem.exit(int),
getExitStatus(),
exit()int getExitStatus()
void exit() throws java.lang.UnsupportedOperationException
Environment implementation.
After calling exit the Environment instance is
generally not any longer usable. In particular, an implementation can choose
to call System.exit(int).java.lang.UnsupportedOperationException - if the method is not availablesetExitStatus(int),
System.exit(int)