Class LastTwoLinesAwareWriter

java.lang.Object
java.io.Writer
org.apache.maven.doxia.module.markdown.LastTwoLinesAwareWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class LastTwoLinesAwareWriter extends Writer
Decorates an existing writer to additionally temporarily buffer the last two lines written. Useful to collapse subsequent new lines or blank lines by evaluating isWriterAfterBlankLine() and isWriterAfterBlankLine(). The buffering does not affect or defer delegation to the underlying writer, though.
  • Field Details

    • out

      private final Writer out
    • previousLine

      private String previousLine
    • currentLine

      private StringBuilder currentLine
    • lineSeparator

      private final String lineSeparator
  • Constructor Details

    • LastTwoLinesAwareWriter

      public LastTwoLinesAwareWriter(Writer out)
    • LastTwoLinesAwareWriter

      LastTwoLinesAwareWriter(Writer out, String lineSeparator)
  • Method Details

    • isWriterAtStartOfNewLine

      public boolean isWriterAtStartOfNewLine()
    • isWriterAfterBlankLine

      public boolean isWriterAfterBlankLine()
    • isInBlankLine

      public boolean isInBlankLine()
    • write

      public void write(char[] cbuf, int off, int len) throws IOException
      Specified by:
      write in class Writer
      Throws:
      IOException
    • flushLine

      private void flushLine(char[] cbuf, int off, int len)
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException
    • isAfterDigit

      public boolean isAfterDigit()