|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.io.ConsoleUtil
public final class ConsoleUtil
Provides static utility methods for dealing with consoles (i.e. the default System.in and System.out).
One problem that must be dealt with is if output requests occur very rapidly:
there is no way that the human eye can meaningfully keep up with the changes,
but to insist that every line be output drains cpu resources for no human benefit.
To deal with this, the output method overwriteLine
merely notes output requests as its only immediate action.
An internal thread will take care of periodically writing the last requested line,
and will disregard any other requested lines.
Thus, the output will appear to be changing as rapidly as is meaningful to the human eye,
yet the cpu usage will be limited.
In contrast, the eraseLine
method always immediately executes.
This class is multithread safe: every method is synchronized on this class.
Nested Class Summary | |
---|---|
private static class |
ConsoleUtil.LineWriterTask
|
static class |
ConsoleUtil.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private static String |
backspacesLine
|
private static String |
blankLine
|
static String |
clearLine
A piece of text that when printed clears the current line on the console. |
private static long |
delay
|
private static String |
line
|
private static int |
lineLength
|
static int |
maxCharsPerLine
Maximum number of chars that will appear on a line of console output. |
private static long |
period
|
private static Timer |
timer
|
Constructor Summary | |
---|---|
private |
ConsoleUtil()
This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class. |
Method Summary | |
---|---|
static void |
eraseLine()
Erases the console's current line. |
static void |
overwriteLine(String s)
Merely records a request to replace the current line with s. |
private static void |
writeLine()
Writes line . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int lineLength
public static final int maxCharsPerLine
Contract: is > 0.
private static final String backspacesLine
private static final String blankLine
public static final String clearLine
Contract: is never null.
private static final long delay
private static final long period
private static final Timer timer
private static String line
Constructor Detail |
---|
private ConsoleUtil()
Method Detail |
---|
public static void overwriteLine(String s)
public static void eraseLine()
private static void writeLine()
line
.
If line is longer than maxCharsPerLine
,
it will be truncated by a call to StringUtil.keepWithinLength
.
Should only be called by timer
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |