public final class ExceptionUtil extends Object
Maybe not always the fastest solution to call in here, but working. Also usable for seeing examples and cutting code for manual inlining.
| 限定符和类型 | 类和说明 |
|---|---|
static class |
ExceptionUtil.InputStreamTracer
Helper runnable to find a String within an output stream.
|
| 构造器和说明 |
|---|
ExceptionUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static InputStream |
captureSystemErrForDebuggingPurposesOnly(boolean teeToOriginalSysErr)
Returns an input stream that contains what will written in this Application to
System.err. |
static InputStream |
captureSystemOutForDebuggingPurposesOnly(boolean teeToOriginalSysOut)
Returns an input stream that contains what will written in this Application to
System.out. |
static void |
dumpThreadStack(PrintStream outprint)
Prints out the current Thread stack to the given stream.
|
static ExceptionUtil.InputStreamTracer |
findMatchInSystemErr(String expectMatch)
Returns an instance to a runnable running in a separate Thread that tries to match the expected
output in
System.err. |
static ExceptionUtil.InputStreamTracer |
findMatchInSystemOut(String expectMatch)
Returns an instance to a runnable running in a separate Thread that tries to match the expected
output in
System.out. |
static ExceptionUtil |
instance()
Returns the singleton instance of this class.
|
public static InputStream captureSystemErrForDebuggingPurposesOnly(boolean teeToOriginalSysErr) throws IOException
System.err.
Caution
If you do not consume the bytes to read from the result you may block the whole application. Do
only use this for debugging purposes or end to end test code!
Attempting to read from the result in the same thread that called here is not recommended as it
may deadlock the thread. Also the thread reading from the stream result should not write
anything to System.err.
Prefer using findMatchInSystemErr(String) to avoid deadlocks.
teeToOriginalSysErr - if true, all writes to the newly installed System.err will also sent to the
original one (thus be visible on the console if the original one was untouched
before).System.err.IOException - if something goes wrong.public static InputStream captureSystemOutForDebuggingPurposesOnly(boolean teeToOriginalSysOut) throws IOException
System.out.
Caution
If you do not consume the bytes to read from the result you may block the whole application. Do
only use this for debugging purposes or end to end test code!
Attempting to read from the result in the same thread that called here is not recommended as it
may deadlock the thread. Also the thread reading from the stream result should not write
anything to System.out.
Prefer using findMatchInSystemOut(String) to avoid deadlocks.
teeToOriginalSysOut - if true, all writes to the newly installed System.out will also sent to the
original one (thus be visible on the console if the original one was untouched
before).System.out.IOException - if something goes wrong.public static ExceptionUtil.InputStreamTracer findMatchInSystemOut(String expectMatch) throws IOException
System.out.
Ensure that you found the expected String in the input stream given by calling
ExceptionUtil.InputStreamTracer.isMatched(). But take into account that it is time -
critical (concurrency) if your result was found.
Prefer this instead of captureSystemOutForDebuggingPurposesOnly(boolean) as this will
avoid blocking your application.
System.out.IOException - if something goes wrong.public static ExceptionUtil.InputStreamTracer findMatchInSystemErr(String expectMatch) throws IOException
System.err.
Ensure that you found the expected String in the input stream given by calling
ExceptionUtil.InputStreamTracer.isMatched(). But take into account that it is time -
critical (concurrency) if your result was found.
Prefer this instead of captureSystemErrForDebuggingPurposesOnly(boolean) as this will
avoid blocking your application.
System.out.IOException - if something goes wrong.public static void dumpThreadStack(PrintStream outprint)
outprint - the stream to print to (e.g. System.err).Thread.getStackTrace()public static ExceptionUtil instance()
This method is useless for now as all methods are static. It may be used in future if VM-global configuration will be put to the state of the instance.
Copyright © 2016. All rights reserved.