Package org.apache.commons.exec
Class LogOutputStream
java.lang.Object
java.io.OutputStream
org.apache.commons.exec.LogOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
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 $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteArrayOutputStreamthe internal bufferprivate static final intCarriage returnprivate static final intInitial buffer size.private final intprivate static final intLinefeedprivate boolean -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of this class.LogOutputStream(int level) Creates a new instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Writes all remaining data from the buffer.voidflush()Flush this log stream.intprotected voidConverts the buffer to a string and sends it toprocessLine.protected voidprocessLine(String line) Logs a line to the log system of the user.protected abstract voidprocessLine(String line, int logLevel) Logs a line to the log system of the user.voidwrite(byte[] b, int off, int len) Write a block of characters to the output streamvoidwrite(int cc) Write the data to the buffer and flush the buffer, if a line separator is detected.Methods inherited from class java.io.OutputStream
write
-
Field Details
-
INTIAL_SIZE
private static final int INTIAL_SIZEInitial buffer size.- See Also:
-
CR
private static final int CRCarriage return- See Also:
-
LF
private static final int LFLinefeed- See Also:
-
buffer
the internal buffer -
skip
private boolean skip -
level
private final int level
-
-
Constructor Details
-
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- loglevel used to log data written to this stream.
-
-
Method Details
-
write
Write the data to the buffer and flush the buffer, if a line separator is detected.- Specified by:
writein classOutputStream- Parameters:
cc- data to log (byte).- Throws:
IOException- See Also:
-
flush
public void flush()Flush this log stream.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- See Also:
-
close
Writes all remaining data from the buffer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException- See Also:
-
getMessageLevel
public int getMessageLevel()- Returns:
- the trace level of the log system
-
write
Write a block of characters to the output stream- Overrides:
writein classOutputStream- Parameters:
b- the array containing the dataoff- the offset into the array where data startslen- the length of block- Throws:
IOException- if the data cannot be written into the stream.- See Also:
-
processBuffer
protected void processBuffer()Converts the buffer to a string and sends it toprocessLine. -
processLine
Logs a line to the log system of the user.- Parameters:
line- the line to log.
-
processLine
Logs a line to the log system of the user.- Parameters:
line- the line to log.logLevel- the log level to use
-