Package com.iizix
Class LogStreamRedirector
- java.lang.Object
- com.iizix.LogStreamRedirector
public class LogStreamRedirector extends java.lang.Object
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
Constructors Constructor Description LogStreamRedirector(int level, java.lang.String originator, java.io.InputStream inputStream)
Creates a stream reader redirector to the IIZI log, running in a separate thread.LogStreamRedirector(int level, java.lang.String originator, java.lang.String prefix, java.io.InputStream inputStream)
Creates a stream reader redirector to the IIZI log, running in a separate thread.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the stream reader redirector without completing potential pending unprocessed input in the stream.boolean
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.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, java.lang.String originator, java.lang.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(java.lang.String originator, java.lang.Process process)
Helper to create stdout and stderr stream readers redirecting to the log.java.lang.Thread
getThread()
Gets the thread instance processing the stream.boolean
isClosed()
Checks whether this stream reader instance is disposed of or not.
Constructor Detail
LogStreamRedirector
public LogStreamRedirector(int level, java.lang.String originator, java.io.InputStream inputStream)
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
public LogStreamRedirector(int level, java.lang.String originator, java.lang.String prefix, java.io.InputStream inputStream)
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 Detail
createStreamReadirector
public static void createStreamReadirector(int level, java.lang.String originator, java.lang.Process process)
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
public static void createStreamReadirectors(java.lang.String originator, java.lang.Process process)
Helper to create stdout and stderr stream readers redirecting to the log.- Parameters:
originator
- The originator.process
- The process.
getThread
public java.lang.Thread getThread()
Gets the thread instance processing the stream.- Returns:
- The thread, always in daemon mode.
closeWait
public boolean closeWait() throws java.lang.InterruptedException
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:
java.lang.InterruptedException
- In case the waiting was interrupted.
closeWait
public boolean closeWait(long timeout) throws java.lang.InterruptedException
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:
java.lang.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.