public class ExcUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static ExcUtil |
assertObject |
private static java.io.PrintStream |
err
The System.err and System.out standard console outputs are copied to this class
able to use in its original output.
|
private static java.io.PrintStream |
out
The System.err and System.out standard console outputs are copied to this class
able to use in its original output.
|
static java.lang.String |
version
Version, history and license.
|
Constructor and Description |
---|
ExcUtil() |
Modifier and Type | Method and Description |
---|---|
protected void |
assertion(boolean shouldTrue)
This routine can handle a assertion to support debugging or reporting.
|
protected void |
assertion(boolean shouldTrue,
java.lang.String msg)
This routine can handle a assertion to support debugging or reporting.
|
protected void |
assertMsg(boolean shouldTrue,
java.lang.CharSequence msg)
Assert the condition, writes a message to System.err if it is false.
|
static void |
check(boolean shouldTrue)
Checks whether an assertion is met.
|
static void |
checkMsg(boolean shouldTrue,
java.lang.String msg)
Checks whether an assertion is met.
|
static void |
consoleErr(java.lang.String text,
java.lang.Object... args)
Output to the original System.err channel though
System.setErr(PrintStream)
was invoked with another channel after first usage of this class. |
static void |
consoleOut(java.lang.String text,
java.lang.Object... args)
Output to the original System.out channel though
System.setOut(PrintStream)
was invoked with another channel after first usage of this class. |
static java.lang.CharSequence |
exceptionInfo(java.lang.CharSequence startText,
java.lang.Throwable exc,
int firstLevel,
int nrofLevels)
Prepares an exception information inclusively some levels of stack trace in a short (one line) form.
|
static java.lang.CharSequence |
exceptionInfo(java.lang.CharSequence startText,
java.lang.Throwable exc,
int firstLevel,
int nrofLevels,
boolean bWithExceptiontext)
Prepares an exception information inclusively some levels of stack trace in a short (one line) form.
|
static void |
setAssertionInstance(ExcUtil instance)
This routine instantiates the assertion handling with a special user instance.
|
static java.lang.CharSequence |
stackInfo(java.lang.CharSequence startText,
int nrofLevel)
Prepares an information about the stack trace without occurring of a exception in a short (one line) form.
|
static java.lang.CharSequence |
stackInfo(java.lang.CharSequence startText,
int firstLevel,
int nrofLevel)
Prepares an information about the stack trace without occurring of a exception in a short (one line) form.
|
static void |
stop()
This is only a debug helper, an empty instruction.
|
static void |
throwCompleteExceptionMessage(java.lang.String sAdd,
java.lang.Exception exc)
Throws with the given exception but with a modified exception text and with a modified exception type.
|
static void |
throwUnexpect(java.lang.Exception exc)
This routine can be used in a catch block of an unexpected exception.
|
public static final java.lang.String version
exceptionInfo(CharSequence, Throwable, int, int, boolean)
without newline on end.
It should be clarified from the application. This is a feature change, should be adapted in the application.
Generally a function should not determine too much by itself. Whether of not the line should be terminated
is not a decision by exceptionInfo(), it is a decision by the application.
CheckVs
, a better name.
#stackInfo(String, int, int)
produces a text which supports hyperlinking
in Eclipse output output console window, like Throwable.printStackTrace()
.
throwCompleteExceptionMessage(String, Exception)
consoleErr(String, Object...)
, consoleOut(String, Object...)
:
Possibility to use the original System.out channel even System.setErr() etc. may be invoked.
assertion(boolean)
etc. are protected now and commented. That are the methods
which can be overridden in another class which is used by setAssertionInstance(ExcUtil)
.
#exceptionInfo(String, Throwable, int, int)
and #stackInfo(String, int)
to support a short info output for example for messages. Not the whole stacktrace!
private static java.io.PrintStream out
System.setErr(PrintStream)
with any other output channel, which may be redirected
to the message system itself.
If any output should be done while dispatching a message, a loop may be caused. In this case it is wrong
to use System.err or System.out. Then this references can be used.
Any user can use this references if an output should be done definitely without usage the message system.
private static java.io.PrintStream err
System.setErr(PrintStream)
with any other output channel, which may be redirected
to the message system itself.
If any output should be done while dispatching a message, a loop may be caused. In this case it is wrong
to use System.err or System.out. Then this references can be used.
Any user can use this references if an output should be done definitely without usage the message system.
private static ExcUtil assertObject
public static void stop()
public static void throwUnexpect(java.lang.Exception exc)
exc
- The originally thrown Exception.public static void setAssertionInstance(ExcUtil instance)
check(boolean)
invokes the user assertion(boolean)
routine up to now.instance
- The users assertion instance.public static void check(boolean shouldTrue)
shouldTrue
- public static void checkMsg(boolean shouldTrue, java.lang.String msg)
shouldTrue
- public static java.lang.CharSequence exceptionInfo(java.lang.CharSequence startText, java.lang.Throwable exc, int firstLevel, int nrofLevels)
startText
- Any start text of the returned text.
If this refers a StringBuilder, it is used to prepare the output text.
Note that the StringBuilder should be used only locally for that.
That is a typical practice if the text is assembled before.
It saves dynamic memory allocation operations.exc
- The exception, its getMessage() will be appendedfirstLevel
- First level of stack. 0 is the routine where the exception is thrown, 1 the caller etc.nrofLevels
- maximum of numbers of levels to show in stack. Use for example 10 to prevent to long lines if it may be deeper.public static java.lang.CharSequence exceptionInfo(java.lang.CharSequence startText, java.lang.Throwable exc, int firstLevel, int nrofLevels, boolean bWithExceptiontext)
startText
- Any start text of the returned text.
If this refers a StringBuilder, it is used to prepare the output text.
Note that the StringBuilder should be used only locally for that.
That is a typical practice if the text is assembled before.
It saves dynamic memory allocation operations.exc
- The exception, its getMessage() will be appendedfirstLevel
- First level of stack. 0 is the routine where the exception is thrown, 1 the caller etc.nrofLevels
- maximum of numbers of levels to show in stack. Use for example 10 to prevent to long lines if it may be deeper.public static void throwCompleteExceptionMessage(java.lang.String sAdd, java.lang.Exception exc) throws java.io.IOException
sAdd
- exc
- IOException,
- RuntimeExceptionjava.io.IOException
public static java.lang.CharSequence stackInfo(java.lang.CharSequence startText, int nrofLevel)
startText
- Any start text of the returned text
If this refers a StringBuilder, it is used to prepare the output text.
Note that the StringBuilder should be used only locally for that.
That is a typical practice if the text is assembled before.
It saves dynamic memory allocation operations.nrofLevels
- maximum of numbers of levels to show in stack. Use for example 10 to prevent to long lines if it may be deeper.
The first level is the caller of this routine.public static java.lang.CharSequence stackInfo(java.lang.CharSequence startText, int firstLevel, int nrofLevel)
startText
- Any start text of the returned text
If this refers a StringBuilder, it is used to prepare the output text.
Note that the StringBuilder should be used only locally for that.
That is a typical practice if the text is assembled before.
It saves dynamic memory allocation operations.firstLevel
- First level of stack. 0 is this routine, 1 the caller etc.nrofLevels
- maximum of numbers of levels to show in stack. Use for example 10 to prevent to long lines if it may be deeper.protected void assertion(boolean shouldTrue)
shouldTrue
- protected void assertion(boolean shouldTrue, java.lang.String msg)
shouldTrue
- protected void assertMsg(boolean shouldTrue, java.lang.CharSequence msg)
shouldTrue
- msg
- If it is null, an info from stacktrace is build.public static void consoleOut(java.lang.String text, java.lang.Object... args)
System.setOut(PrintStream)
was invoked with another channel after first usage of this class.
Note that the user should invoke any action from ExcUtil, for example ExcUtil.check(true);
as a first instruction in main(). Then this class saves the original System.out PrintStream object in this class
to use in this method.MsgPrintStream
. This method is independent of them.text
- Text to output. One should use "\n" to force a line feed. Format character can be used
in the same kind as PrintStream.printf(String, Object...)
.args
- The arguments for the formatted text.public static void consoleErr(java.lang.String text, java.lang.Object... args)
System.setErr(PrintStream)
was invoked with another channel after first usage of this class.
Note that the user should invoke any action from ExcUtil, for example ExcUtil.check(true);
as a first instruction in main(). Then this class saves the original System.err PrintStream object in this class
to use in this method.MsgPrintStream
. This method is independent of them.text
- Text to output. One should use "\n" to force a line feed. Format character can be used
in the same kind as PrintStream.printf(String, Object...)
.args
- The arguments for the formatted text.