Class UTF8Writer

java.lang.Object
java.io.Writer
net.sf.saxon.serialize.UTF8Writer
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable, UnicodeWriter

public final class UTF8Writer extends Writer implements UnicodeWriter
Specialized buffering UTF-8 writer. The main reason for custom version is to allow for efficient buffer recycling; the second benefit is that encoder has less overhead for short content encoding (compared to JDK default codecs).
  • Constructor Details

  • Method Details

    • close

      public void close() throws IOException
      Description copied from interface: UnicodeWriter
      Complete the writing of characters to the result. The default implementation does nothing.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface UnicodeWriter
      Specified by:
      close in class Writer
      Throws:
      IOException - if processing fails for any reason
    • flush

      public void flush() throws IOException
      Description copied from interface: UnicodeWriter
      Flush the contents of any buffers. The default implementation does nothing.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in interface UnicodeWriter
      Specified by:
      flush in class Writer
      Throws:
      IOException - if processing fails for any reason
    • write

      public void write(char[] cbuf) throws IOException
      Overrides:
      write in class Writer
      Throws:
      IOException
    • write

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

      public void writeLatin1(byte[] bytes, int off, int len) throws IOException
      Throws:
      IOException
    • writeAscii

      public void writeAscii(byte[] content) throws IOException
      Write a sequence of ASCII characters. The caller is responsible for ensuring that each byte represents a character in the range 1-127
      Specified by:
      writeAscii in interface UnicodeWriter
      Parameters:
      content - the content to be written
      Throws:
      IOException - if processing fails for any reason
    • writeAscii

      public void writeAscii(byte[] chars, int off, int len) throws IOException
      Write a sequence of ASCII characters. The caller is responsible for ensuring that each byte represents a character in the range 1-127
      Parameters:
      chars - the characters to be written
      off - the offset of the first character to be included
      len - the number of characters to be written
      Throws:
      IOException
    • writeRepeatedAscii

      public void writeRepeatedAscii(byte ch, int repeat) throws IOException
      Write an ASCII character repeatedly. Used for serializing whitespace.
      Specified by:
      writeRepeatedAscii in interface UnicodeWriter
      Parameters:
      ch - the ASCII character to be serialized (must be less than 0x7f)
      repeat - the number of occurrences to output
      Throws:
      IOException - if it fails
    • writeCodePoint

      public void writeCodePoint(int codepoint) throws IOException
      Process a single character. Default implementation wraps the codepoint into a single-character UnicodeString
      Specified by:
      writeCodePoint in interface UnicodeWriter
      Parameters:
      codepoint - the character to be processed. Must not be a surrogate
      Throws:
      IOException - if processing fails for any reason
    • write

      public void write(int c) throws IOException
      Write a single char.

      Note (MHK) Although the Writer interface says that the top half of the int is ignored, this implementation appears to accept a Unicode codepoint which is output as a 4-byte UTF-8 sequence.

      Overrides:
      write in class Writer
      Parameters:
      c - the char to be written
      Throws:
      IOException - If an I/O error occurs
    • write

      public void write(UnicodeString chars) throws IOException
      Process a supplied string
      Specified by:
      write in interface UnicodeWriter
      Parameters:
      chars - the characters to be processed
      Throws:
      IOException - if processing fails for any reason
    • write

      public void write(String str) throws IOException
      Description copied from interface: UnicodeWriter
      Process a supplied string
      Specified by:
      write in interface UnicodeWriter
      Overrides:
      write in class Writer
      Parameters:
      str - the characters to be processed
      Throws:
      IOException - if processing fails for any reason
    • write

      public void write(String str, int off, int len) throws IOException
      Overrides:
      write in class Writer
      Throws:
      IOException