Class StreamingMarkupWriter

java.lang.Object
java.io.Writer
groovy.xml.streamingmarkupsupport.StreamingMarkupWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class StreamingMarkupWriter extends Writer
Writer used by streaming markup support to escape XML lazily while honoring output encoding limits.
  • Field Details

    • writer

      protected final Writer writer
      Underlying destination writer.
    • encoding

      protected final String encoding
      Normalized target encoding name.
    • encodingKnown

      protected boolean encodingKnown
      Whether the target encoding was explicitly supplied or discovered from the wrapped writer.
    • encoder

      protected final CharsetEncoder encoder
      Encoder used to decide when numeric character references are required.
    • writingAttribute

      protected boolean writingAttribute
      Whether output is currently inside an attribute value.
    • haveHighSurrogate

      protected boolean haveHighSurrogate
      Whether a high surrogate is buffered awaiting its matching low surrogate.
    • surrogatePair

      protected StringBuilder surrogatePair
      Temporary buffer for surrogate pair handling.
  • Constructor Details

    • StreamingMarkupWriter

      public StreamingMarkupWriter(Writer writer, String encoding)
      Creates a streaming writer using the supplied encoding name and single-quote attribute escaping.
      Parameters:
      writer - destination writer
      encoding - target encoding, or null to infer it
    • StreamingMarkupWriter

      public StreamingMarkupWriter(Writer writer, String encoding, boolean useDoubleQuotes)
      Creates a streaming writer.
      Parameters:
      writer - destination writer
      encoding - target encoding, or null to infer it
      useDoubleQuotes - whether attribute escaping should target double quotes instead of single quotes
    • StreamingMarkupWriter

      public StreamingMarkupWriter(Writer writer)
      Creates a streaming writer that infers its encoding from the wrapped writer when possible.
      Parameters:
      writer - destination writer
  • Method Details

    • 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
    • flush

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

      public void write(int c) 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
    • setWritingAttribute

      public void setWritingAttribute(boolean writingAttribute)
      Switches escaping rules between element text and attribute value output.
      Parameters:
      writingAttribute - true when writing an attribute value
    • escaped

      public Writer escaped()
      Returns a writer view that applies XML escaping before delegating here.
      Returns:
      escaped writer view
    • unescaped

      public Writer unescaped()
      Returns a writer view that bypasses the additional escaping layer.
      Returns:
      unescaped writer view
    • getEncoding

      public String getEncoding()
      Returns the normalized target encoding used for numeric escape decisions.
      Returns:
      target encoding name
    • getEncodingKnown

      public boolean getEncodingKnown()
      Returns whether the encoding came from an explicit or discoverable source.
      Returns:
      true if the encoding is known precisely