Class LogOutputStream

java.lang.Object
java.io.OutputStream
org.apache.commons.exec.LogOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public abstract class LogOutputStream extends 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.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The internal buffer.
    private final Charset
     
    private static final int
    Carriage return.
    private static final int
    Initial buffer size.
    private final int
     
    private static final int
    Line-feed.
    private boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of this class.
    LogOutputStream(int level)
    Creates a new instance of this class.
    LogOutputStream(int level, 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

    Modifier and Type
    Method
    Description
    void
    Writes all remaining data from the buffer.
    void
    Flushes this log stream.
    int
    Gets the trace level of the log system.
    protected void
    Converts the buffer to a string and sends it to processLine.
    protected void
    Logs a line to the log system of the user.
    protected abstract void
    processLine(String line, int logLevel)
    Logs a line to the log system of the user.
    void
    write(byte[] b, int off, int len)
    Writes a block of characters to the output stream.
    void
    write(int cc)
    Writes the data to the buffer and flush the buffer, if a line separator is detected.

    Methods inherited from class java.io.OutputStream

    write

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 - level used to log data written to this stream.
    • LogOutputStream

      public LogOutputStream(int level, 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 Details

    • close

      public void close() throws IOException
      Writes all remaining data from the buffer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException
      See Also:
    • flush

      public void flush()
      Flushes this log stream.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      See Also:
    • 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 to processLine.
    • processLine

      protected void processLine(String line)
      Logs a line to the log system of the user.
      Parameters:
      line - the line to log.
    • processLine

      protected abstract void processLine(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 IOException
      Writes a block of characters to the output stream.
      Overrides:
      write in class OutputStream
      Parameters:
      b - the array containing the data.
      off - the offset into the array where data starts.
      len - the length of block.
      Throws:
      IOException - if the data cannot be written into the stream.
      See Also:
    • write

      public void write(int cc) throws IOException
      Writes the data to the buffer and flush the buffer, if a line separator is detected.
      Specified by:
      write in class OutputStream
      Parameters:
      cc - data to log (byte).
      Throws:
      IOException
      See Also: