Package org.apache.commons.exec
Class LogOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.commons.exec.LogOutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public abstract class LogOutputStream extends java.io.OutputStream
Base class to connect a logging system to the output and/or error stream of then external process. The implementation parses the incoming data to construct a line and passes the complete line to an user-defined implementation.- Version:
- $Id: LogOutputStream.java 1636056 2014-11-01 21:12:52Z ggregory $
-
-
Constructor Summary
Constructors Constructor Description LogOutputStream()
Creates a new instance of this class.LogOutputStream(int level)
Creates a new instance of this class.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
close()
Writes all remaining data from the buffer.void
flush()
Flush this log stream.int
getMessageLevel()
protected void
processBuffer()
Converts the buffer to a string and sends it toprocessLine
.protected void
processLine(java.lang.String line)
Logs a line to the log system of the user.protected abstract void
processLine(java.lang.String line, int logLevel)
Logs a line to the log system of the user.void
write(byte[] b, int off, int len)
Write a block of characters to the output streamvoid
write(int cc)
Write the data to the buffer and flush the buffer, if a line separator is detected.
-
-
-
Field Detail
-
INTIAL_SIZE
private static final int INTIAL_SIZE
Initial buffer size.- See Also:
- Constant Field Values
-
CR
private static final int CR
Carriage return- See Also:
- Constant Field Values
-
LF
private static final int LF
Linefeed- See Also:
- Constant Field Values
-
buffer
private final java.io.ByteArrayOutputStream buffer
the internal buffer
-
skip
private boolean skip
-
level
private final int level
-
-
Method Detail
-
write
public void write(int cc) throws java.io.IOException
Write the data to the buffer and flush the buffer, if a line separator is detected.- Specified by:
write
in classjava.io.OutputStream
- Parameters:
cc
- data to log (byte).- Throws:
java.io.IOException
- See Also:
OutputStream.write(int)
-
flush
public void flush()
Flush this log stream.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- See Also:
OutputStream.flush()
-
close
public void close() throws java.io.IOException
Writes all remaining data from the buffer.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
- See Also:
OutputStream.close()
-
getMessageLevel
public int getMessageLevel()
- Returns:
- the trace level of the log system
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
Write a block of characters to the output stream- Overrides:
write
in classjava.io.OutputStream
- Parameters:
b
- the array containing the dataoff
- the offset into the array where data startslen
- the length of block- Throws:
java.io.IOException
- if the data cannot be written into the stream.- See Also:
OutputStream.write(byte[], int, int)
-
processBuffer
protected void processBuffer()
Converts the buffer to a string and sends it toprocessLine
.
-
processLine
protected void processLine(java.lang.String line)
Logs a line to the log system of the user.- Parameters:
line
- the line to log.
-
processLine
protected abstract void processLine(java.lang.String line, int logLevel)
Logs a line to the log system of the user.- Parameters:
line
- the line to log.logLevel
- the log level to use
-
-