Package com.iizix
Class LogStreamRedirector
java.lang.Object
com.iizix.LogStreamRedirector
Input stream redirector class to the IIZI log. It is typically used to redirect the output of an external process to the log.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionLogStreamRedirector
(int level, String originator, InputStream inputStream) Creates a stream reader redirector to the IIZI log, running in a separate thread.LogStreamRedirector
(int level, String originator, String prefix, InputStream inputStream) Creates a stream reader redirector to the IIZI log, running in a separate thread.Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the stream reader redirector without completing potential pending unprocessed input in the stream.boolean
Waits indefinitely for the stream reader to complete all input reading by waiting for the input stream to be closed, then disposes of this instance.boolean
closeWait
(long timeout) Waits for the stream reader to complete all input reading by waiting for the input stream to be closed, then disposes of this instance.static void
createStreamReadirector
(int level, String originator, Process process) Helper to create a stdout stream reader redirecting to the log when the process stderr has been redirected to stdout.static void
createStreamReadirectors
(String originator, Process process) Helper to create stdout and stderr stream readers redirecting to the log.Gets the thread instance processing the stream.boolean
isClosed()
Checks whether this stream reader instance is disposed of or not.
Constructor Details
LogStreamRedirector
Creates a stream reader redirector to the IIZI log, running in a separate thread.- Parameters:
level
- Log level (1-7), e.g.ILog.INFO
orILog.SEVERE
.originator
- The originator.inputStream
- The input stream.
LogStreamRedirector
Creates a stream reader redirector to the IIZI log, running in a separate thread.- Parameters:
level
- Log level (1-7), e.g.ILog.INFO
orILog.SEVERE
.originator
- The originator.prefix
- Prefix for each line,null
or empty string for none.inputStream
- The input stream.
Method Details
createStreamReadirector
Helper to create a stdout stream reader redirecting to the log when the process stderr has been redirected to stdout.- Parameters:
level
- The log level.originator
- The originator.process
- The process.
createStreamReadirectors
Helper to create stdout and stderr stream readers redirecting to the log.- Parameters:
originator
- The originator.process
- The process.
getThread
Gets the thread instance processing the stream.- Returns:
- The thread, always in daemon mode.
closeWait
Waits indefinitely for the stream reader to complete all input reading by waiting for the input stream to be closed, then disposes of this instance.- Returns:
- Success flag.
- Throws:
InterruptedException
- In case the waiting was interrupted.
closeWait
Waits for the stream reader to complete all input reading by waiting for the input stream to be closed, then disposes of this instance.- Parameters:
timeout
- The timeout to wait for the thread,-1L
for indefinite wait.- Returns:
- Success flag.
- Throws:
InterruptedException
- In case the waiting was interrupted.
isClosed
public boolean isClosed()Checks whether this stream reader instance is disposed of or not.- Returns:
- The dispose state.
close
public void close()Closes the stream reader redirector without completing potential pending unprocessed input in the stream.