All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class EscapeHTMLWriterextends FilterWriter
Writer that escapes HTML characters during streaming. Streaming version of DataHelper.escapeHTML(), also escapes '--' for comment safety since '--' is disallowed inside HTML comments.
  • Field Details

  • Constructor Details

    • EscapeHTMLWriter

      public EscapeHTMLWriter(Writer out)
      Create an EscapeHTMLWriter wrapping the given writer.
      Parameters:
      out - the underlying writer
  • Method Details

    • write

      public void write(int c) throws IOException
      Write a single character, escaping HTML special characters.
      Overrides:
      write in class FilterWriter
      Parameters:
      c - the character value
      Throws:
      IOException - on I/O error
    • write

      public void write(char[] cbuf, int off, int len) throws IOException
      Write characters from a buffer, escaping HTML special characters.
      Overrides:
      write in class FilterWriter
      Parameters:
      cbuf - the character buffer
      off - the start offset in the buffer
      len - the number of characters to write
      Throws:
      IOException - on I/O error
    • write

      public void write(String str, int off, int len) throws IOException
      Write characters from a string, escaping HTML special characters.
      Overrides:
      write in class FilterWriter
      Parameters:
      str - the string to write
      off - the start offset in the string
      len - the number of characters to write
      Throws:
      IOException - on I/O error
    • close

      public void close()
      Does nothing. Does not close the underlying writer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class FilterWriter