Package student.testingsupport
Class SystemIOUtilities
java.lang.Object
student.testingsupport.SystemIOUtilities
A utility class that provides functions for replacing
System
I/O streams with helpful alternative implementations to make some
testing jobs easier. This class is really for use by infrastructure
and support code, and students should never need to use it directly.
Since this class provides only static methods, clients should not create an instance. As a result, it provides no public constructors.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSince this class provides only static methods, clients should not create an instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidChecks to see if the calling program is running under the Apache Tomcat servlet container.static PrintStreamWithHistoryerr()Get a "wrapped" version ofSystem.errthat provides history recording functions.static booleanstatic booleanChecks to see if the calling program is running under the Apache Tomcat servlet container.static PrintStreamWithHistoryout()Get a "wrapped" version ofSystem.outthat provides history recording functions.static voidreplaceSystemInContents(String contents, Runnable readCallback) ReplaceSystem.inwith the contents of the given string.static voidreplaceSystemInContentsLineByLine(String contents, Runnable readCallback) ReplaceSystem.inwith the contents of the given string.static void"Unwrap"System.errby removing any history recording wrapper, and return it to its original state.static voidRestoreSystem.into its original value.static void"Unwrap"System.outby removing any history recording wrapper, and return it to its original state.
-
Constructor Details
-
SystemIOUtilities
protected SystemIOUtilities()Since this class provides only static methods, clients should not create an instance. This constructor is protected only to allow legacy/ deprecated subclass stubs, and it should never actually be called.- Throws:
UnsupportedOperationException- Always thrown if this constructor is invoked.
-
-
Method Details
-
out
Get a "wrapped" version ofSystem.outthat provides history recording functions.- Returns:
- a version of System.out that provides history features
-
restoreSystemOut
public static void restoreSystemOut()"Unwrap"System.outby removing any history recording wrapper, and return it to its original state. -
err
Get a "wrapped" version ofSystem.errthat provides history recording functions.- Returns:
- a version of System.err that provides history features
-
restoreSystemErr
public static void restoreSystemErr()"Unwrap"System.errby removing any history recording wrapper, and return it to its original state. -
replaceSystemInContents
ReplaceSystem.inwith the contents of the given string.- Parameters:
contents- The content to read fromreadCallback- will be called before every read operation. This can be used to prevent any reads by failing fast when running out of input data instead of timing out.
-
replaceSystemInContentsLineByLine
ReplaceSystem.inwith the contents of the given string.- Parameters:
contents- The content to read from
-
restoreSystemIn
public static void restoreSystemIn()RestoreSystem.into its original value. -
isOnServer
public static boolean isOnServer()Checks to see if the calling program is running under the Apache Tomcat servlet container.- Returns:
- True if running as a servlet
-
isInApplet
public static boolean isInApplet() -
assertNotOnServer
public static void assertNotOnServer()Checks to see if the calling program is running under the Apache Tomcat servlet container. When running in such an environment, some behaviors should be avoided. For example, it is not appropriate to modify globally shared resources like those in the class System.
-