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.OutputStreamBase 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 a user-defined implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classLogOutputStream.ByteArrayOutputStreamX
-
Field Summary
Fields Modifier and Type Field Description private LogOutputStream.ByteArrayOutputStreamXbufferThe internal buffer.private java.nio.charset.CharsetcharsetCharacter Set to use when processing lines.private static intCRCarriage return.private static intINITIAL_SIZEInitial buffer size.private intlevelLevel used to log data written to this stream.private static intLFLine-feed.private booleanskipLast written char was a CR.
-
Constructor Summary
Constructors Constructor Description LogOutputStream()Creates a new instance of this class.LogOutputStream(int level)Creates a new instance of this class.LogOutputStream(int level, java.nio.charset.Charset charset)Creates a new instance of this class, specifying the character set that should be used for outputting the string for each line
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Writes all remaining data from the buffer.voidflush()Flushes this log stream.intgetMessageLevel()Gets the trace level of the log system.protected voidprocessBuffer()Converts the buffer to a string and sends it toprocessLine.protected voidprocessLine(java.lang.String line)Logs a line to the log system of the user.protected abstract voidprocessLine(java.lang.String line, int logLevel)Logs a line to the log system of the user.voidwrite(byte[] b, int off, int len)Writes a block of characters to the output stream.voidwrite(int cc)Writes the data to the buffer and flush the buffer, if a line separator is detected.
-
-
-
Field Detail
-
INITIAL_SIZE
private static final int INITIAL_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
Line-feed.- See Also:
- Constant Field Values
-
buffer
private final LogOutputStream.ByteArrayOutputStreamX buffer
The internal buffer.
-
skip
private boolean skip
Last written char was a CR.
-
level
private final int level
Level used to log data written to this stream.
-
charset
private final java.nio.charset.Charset charset
Character Set to use when processing lines.
-
-
Constructor Detail
-
LogOutputStream
public LogOutputStream()
Creates a new instance of this class. Uses the default level of 999.
-
LogOutputStream
public LogOutputStream(int level)
Creates a new instance of this class.- Parameters:
level- level used to log data written to this stream.
-
LogOutputStream
public LogOutputStream(int level, java.nio.charset.Charset charset)Creates a new instance of this class, specifying the character set that should be used for outputting the string for each line- Parameters:
level- level used to log data written to this stream.charset- Character Set to use when processing lines.
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionWrites all remaining data from the buffer.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException- See Also:
OutputStream.close()
-
flush
public void flush()
Flushes this log stream.- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- See Also:
OutputStream.flush()
-
getMessageLevel
public int getMessageLevel()
Gets the trace level of the log system.- Returns:
- the trace level of the log system.
-
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
-
write
public void write(byte[] b, int off, int len) throws java.io.IOExceptionWrites a block of characters to the output stream.- Overrides:
writein classjava.io.OutputStream- Parameters:
b- the array containing the data.off- the offset into the array where data starts.len- the length of block.- Throws:
java.io.IOException- if the data cannot be written into the stream.- See Also:
OutputStream.write(byte[], int, int)
-
write
public void write(int cc) throws java.io.IOExceptionWrites the data to the buffer and flush the buffer, if a line separator is detected.- Specified by:
writein classjava.io.OutputStream- Parameters:
cc- data to log (byte).- Throws:
java.io.IOException- See Also:
OutputStream.write(int)
-
-