Class LogOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable
    Direct Known Subclasses:
    Slf4jOutputStream

    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.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.ByteArrayOutputStream buffer
      the internal buffer
      private static int CR
      Carriage return
      private static int INTIAL_SIZE
      Initial buffer size.
      (package private) byte lastReceivedByte  
      private static int LF
      Linefeed
    • Constructor Summary

      Constructors 
      Constructor Description
      LogOutputStream()  
    • 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.
      protected void processBuffer()
      Converts the buffer to a string and sends it to processLine.
      protected abstract void processLine​(java.lang.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 stream
      void 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
      • Methods inherited from class java.lang.Object

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

      • buffer

        private final java.io.ByteArrayOutputStream buffer
        the internal buffer
      • lastReceivedByte

        byte lastReceivedByte
    • Constructor Detail

      • LogOutputStream

        public LogOutputStream()
    • 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 class java.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 interface java.io.Flushable
        Overrides:
        flush in class java.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 interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException
        See Also:
        OutputStream.close()
      • 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 class java.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)
      • processBuffer

        protected void processBuffer()
        Converts the buffer to a string and sends it to processLine.
      • processLine

        protected abstract void processLine​(java.lang.String line)
        Logs a line to the log system of the user.
        Parameters:
        line - the line to log.