Class LineOutputStream

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

    public abstract class LineOutputStream
    extends OutputStream
    This class hides a line-based output behind an OutputStream.

    Only the abstract method println(String) needs to be overridden; the other methods in OutputStream are overridden in this class already to buffer lines until they are complete and then flush them.

    Author:
    Johannes Schindelin
    • Field Summary

      Fields 
      Modifier and Type Field Description
      byte[] buffer  
      int len  
    • Field Detail

      • buffer

        public byte[] buffer
      • len

        public int len
    • Constructor Detail

      • LineOutputStream

        public LineOutputStream()
    • Method Detail

      • println

        public abstract void println​(String line)
                              throws IOException
        This method is all that needs to be implemented.
        Parameters:
        line - the line to print
        Throws:
        IOException
      • write

        public void write​(int b)
                   throws IOException
        Adds a single byte to the current line buffer, or flush() the current line if it is a new-line character.
        Specified by:
        write in class OutputStream
        Parameters:
        b - the byte to write
        Throws:
        IOException
      • write

        public void write​(byte[] buf)
                   throws IOException
        Adds bytes to the current line buffer. Whenever a new-line character is encountered, flush() the current line buffer.
        Overrides:
        write in class OutputStream
        Parameters:
        buf - the bytes to write
        Throws:
        IOException
      • write

        public void write​(byte[] buf,
                          int offset,
                          int length)
                   throws IOException
        Adds bytes to the current line buffer. Whenever a new-line character is encountered, flush() the current line buffer.
        Overrides:
        write in class OutputStream
        Parameters:
        buf - the bytes to write
        offset - the offset into the buffer
        length - how many bytes to add
        Throws:
        IOException
      • ensure

        protected void ensure​(int length)
        Increases the size of the line buffer if necessary.
        Parameters:
        length - the required minimal length