Class HTMLWriter

java.lang.Object
java.io.Writer
org.omegat.filters2.html2.HTMLWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class HTMLWriter extends Writer
This class acts as an interceptor of output: First it collects all the output inside itself in a string. Then it adds a META with a given charset (or replaces the existing charset with a new one) and (if the file is XHTML and has XML header) adds encoding declaration (or replaces the encoding in the XML header). Next it writes out to the file.

Note that if encoding parameter of the constructor is null, no encoding declaration is added, and the file is written in OS-default encoding. This is done to fix a bug [1.6 RC2] Bug with Target Encoding set to <auto> for (x)HTML.

  • Constructor Details

  • Method Details

    • close

      public void close() throws IOException
      Flushes the writer (which does the real write-out of data) and closes the real writer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Does the real write-out of the data, first adding/replacing encoding statement.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
      Throws:
      IOException
    • write

      public void write(@NotNull @org.jetbrains.annotations.NotNull char[] cbuf, int off, int len) throws IOException
      Write a portion of an array of characters. Simply calls write(char[], int, int) of the internal StringWriter.
      Specified by:
      write in class Writer
      Parameters:
      cbuf - - Array of characters
      off - - Offset from which to start writing characters
      len - - Number of characters to write
      Throws:
      IOException - - If an I/O error occurs