Package org.zeroturnaround.exec.stream
Class LogOutputStream
java.lang.Object
java.io.OutputStream
org.zeroturnaround.exec.stream.LogOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
- Direct Known Subclasses:
Slf4jOutputStream
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteArrayOutputStream
the internal bufferprivate static final int
Carriage returnprivate static final int
Initial buffer size.(package private) byte
private static final int
Linefeed -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Writes all remaining data from the buffer.void
flush()
Flush this log stream.protected void
Converts the buffer to a string and sends it toprocessLine
.protected abstract void
processLine
(String line) 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.Methods inherited from class java.io.OutputStream
nullOutputStream, 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 -
lastReceivedByte
byte lastReceivedByte
-
-
Constructor Details
-
LogOutputStream
public LogOutputStream()
-
-
Method Details
-
write
Write the data to the buffer and flush the buffer, if a line separator is detected.- Specified by:
write
in classOutputStream
- Parameters:
cc
- data to log (byte).- Throws:
IOException
- See Also:
-
flush
public void flush()Flush this log stream.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- See Also:
-
close
Writes all remaining data from the buffer.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
- See Also:
-
write
Write a block of characters to the output stream- Overrides:
write
in 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.
-