Class LineReadingOutputStream

java.lang.Object
java.io.OutputStream
com.avrix.logs.LineReadingOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class LineReadingOutputStream extends OutputStream
An OutputStream implementation that reads byte arrays, interprets them as lines of text, and processes each line based on specific rules for logging or consumption.
  • Constructor Details

    • LineReadingOutputStream

      public LineReadingOutputStream(Consumer<String> consumer)
      Constructs a LineReadingOutputStream with the specified consumer.
      Parameters:
      consumer - The consumer to accept processed lines.
      Throws:
      NullPointerException - if the consumer is null.
  • Method Details

    • write

      public void write(int b) throws IOException
      Writes a single byte to this output stream.
      Specified by:
      write in class OutputStream
      Parameters:
      b - The byte to be written.
      Throws:
      IOException - if an I/O error occurs.
    • write

      public void write(byte[] b, int start, int len)
      Writes a portion of a byte array to this output stream.
      Overrides:
      write in class OutputStream
      Parameters:
      b - The data.
      start - The start offset in the data.
      len - The number of bytes to write.
      Throws:
      IllegalArgumentException - if the start or len is negative, or end exceeds the array length.
    • close

      public void close()
      Closes this output stream and flushes any accumulated data if present.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream