Package groovy.xml.streamingmarkupsupport

# 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 Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final CharsetEncoder`
  `encoder`
  Encoder used to decide when numeric character references are required.
  `protected final String`
  `encoding`
  Normalized target encoding name.
  `protected boolean`
  `encodingKnown`
  Whether the target encoding was explicitly supplied or discovered from the wrapped writer.
  `protected boolean`
  `haveHighSurrogate`
  Whether a high surrogate is buffered awaiting its matching low surrogate.
  `protected StringBuilder`
  `surrogatePair`
  Temporary buffer for surrogate pair handling.
  `protected final Writer`
  `writer`
  Underlying destination writer.
  `protected boolean`
  `writingAttribute`
  Whether output is currently inside an attribute value.

  ### Fields inherited from class java.io.Writer

  `lock`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StreamingMarkupWriter(Writer writer)`
  Creates a streaming writer that infers its encoding from the wrapped writer when possible.
  `StreamingMarkupWriter(Writer writer, String encoding)`
  Creates a streaming writer using the supplied encoding name and single-quote attribute escaping.
  `StreamingMarkupWriter(Writer writer, String encoding, boolean useDoubleQuotes)`
  Creates a streaming writer.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `Writer`
  `escaped()`
  Returns a writer view that applies XML escaping before delegating here.
  `void`
  `flush()`
  `String`
  `getEncoding()`
  Returns the normalized target encoding used for numeric escape decisions.
  `boolean`
  `getEncodingKnown()`
  Returns whether the encoding came from an explicit or discoverable source.
  `void`
  `setWritingAttribute(boolean writingAttribute)`
  Switches escaping rules between element text and attribute value output.
  `Writer`
  `unescaped()`
  Returns a writer view that bypasses the additional escaping layer.
  `void`
  `write(char[] cbuf, int off, int len)`
  `void`
  `write(int c)`

  ### Methods inherited from class java.io.Writer

  `append, append, append, nullWriter, write, write, write`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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