Class StreamingMarkupWriter
java.lang.Object
java.io.Writer
groovy.xml.streamingmarkupsupport.StreamingMarkupWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
Writer used by streaming markup support to escape XML lazily while honoring output encoding limits.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CharsetEncoderEncoder used to decide when numeric character references are required.protected final StringNormalized target encoding name.protected booleanWhether the target encoding was explicitly supplied or discovered from the wrapped writer.protected booleanWhether a high surrogate is buffered awaiting its matching low surrogate.protected StringBuilderTemporary buffer for surrogate pair handling.protected final WriterUnderlying destination writer.protected booleanWhether output is currently inside an attribute value. -
Constructor Summary
ConstructorsConstructorDescriptionStreamingMarkupWriter(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 TypeMethodDescriptionvoidclose()escaped()Returns a writer view that applies XML escaping before delegating here.voidflush()Returns the normalized target encoding used for numeric escape decisions.booleanReturns whether the encoding came from an explicit or discoverable source.voidsetWritingAttribute(boolean writingAttribute) Switches escaping rules between element text and attribute value output.Returns a writer view that bypasses the additional escaping layer.voidwrite(char[] cbuf, int off, int len) voidwrite(int c)
-
Field Details
-
writer
Underlying destination writer. -
encoding
Normalized target encoding name. -
encodingKnown
protected boolean encodingKnownWhether the target encoding was explicitly supplied or discovered from the wrapped writer. -
encoder
Encoder used to decide when numeric character references are required. -
writingAttribute
protected boolean writingAttributeWhether output is currently inside an attribute value. -
haveHighSurrogate
protected boolean haveHighSurrogateWhether a high surrogate is buffered awaiting its matching low surrogate. -
surrogatePair
Temporary buffer for surrogate pair handling.
-
-
Constructor Details
-
StreamingMarkupWriter
Creates a streaming writer using the supplied encoding name and single-quote attribute escaping.- Parameters:
writer- destination writerencoding- target encoding, ornullto infer it
-
StreamingMarkupWriter
Creates a streaming writer.- Parameters:
writer- destination writerencoding- target encoding, ornullto infer ituseDoubleQuotes- whether attribute escaping should target double quotes instead of single quotes
-
StreamingMarkupWriter
Creates a streaming writer that infers its encoding from the wrapped writer when possible.- Parameters:
writer- destination writer
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Specified by:
writein classWriter- Throws:
IOException
-
setWritingAttribute
public void setWritingAttribute(boolean writingAttribute) Switches escaping rules between element text and attribute value output.- Parameters:
writingAttribute-truewhen writing an attribute value
-
escaped
Returns a writer view that applies XML escaping before delegating here.- Returns:
- escaped writer view
-
unescaped
Returns a writer view that bypasses the additional escaping layer.- Returns:
- unescaped writer view
-
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:
trueif the encoding is known precisely
-