Class LineRedirectOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    class LineRedirectOutputStream
    extends java.io.OutputStream
    An output stream that captures one line of output at a time, and then redirects that line to some Consumer to act upon as it pleases. This class is not thread safe and expects to have only one active writer consuming it at any given time.
    Since:
    3.0.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.ByteArrayOutputStream buffer  
      private java.nio.charset.Charset charset  
      private java.util.function.Consumer<java.lang.String> linePrinter  
    • Constructor Summary

      Constructors 
      Constructor Description
      LineRedirectOutputStream​(java.util.function.Consumer<java.lang.String> linePrinter)  
      LineRedirectOutputStream​(java.util.function.Consumer<java.lang.String> linePrinter, java.nio.charset.Charset charset)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void flush()  
      private void printAndReset()  
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        nullOutputStream, write, write
      • Methods inherited from class java.lang.Object

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

      • linePrinter

        private final java.util.function.Consumer<java.lang.String> linePrinter
      • charset

        private final java.nio.charset.Charset charset
      • buffer

        private java.io.ByteArrayOutputStream buffer
    • Constructor Detail

      • LineRedirectOutputStream

        public LineRedirectOutputStream​(java.util.function.Consumer<java.lang.String> linePrinter)
      • LineRedirectOutputStream

        public LineRedirectOutputStream​(java.util.function.Consumer<java.lang.String> linePrinter,
                                        java.nio.charset.Charset charset)
    • Method Detail

      • write

        public void write​(int b)
        Specified by:
        write in class java.io.OutputStream
      • flush

        public void flush()
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
      • printAndReset

        private void printAndReset()