public class StreamingMarkupWriter
extends Writer
Writer used by streaming markup support to escape XML lazily while honoring output encoding limits.
| Modifiers | Name | Description |
|---|---|---|
protected CharsetEncoder |
encoder |
Encoder used to decide when numeric character references are required. |
protected 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 Writer |
writer |
Underlying destination writer. |
protected boolean |
writingAttribute |
Whether output is currently inside an attribute value. |
| Constructor and description |
|---|
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. |
StreamingMarkupWriter(Writer writer)Creates a streaming writer that infers its encoding from the wrapped writer when possible. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
close()Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.
|
|
public Writer |
escaped()Returns a writer view that applies XML escaping before delegating here. |
|
public void |
flush()Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams. If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.
|
|
public String |
getEncoding()Returns the normalized target encoding used for numeric escape decisions. |
|
public boolean |
getEncodingKnown()Returns whether the encoding came from an explicit or discoverable source. |
|
public void |
setWritingAttribute(boolean writingAttribute)Switches escaping rules between element text and attribute value output. |
|
public Writer |
unescaped()Returns a writer view that bypasses the additional escaping layer. |
|
public void |
write(int c)Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored. Subclasses that intend to support efficient single-character output should override this method.
|
|
public void |
write(char[] cbuf, int off, int len)Writes a portion of an array of characters.
|
Encoder used to decide when numeric character references are required.
Normalized target encoding name.
Whether the target encoding was explicitly supplied or discovered from the wrapped writer.
Whether a high surrogate is buffered awaiting its matching low surrogate.
Temporary buffer for surrogate pair handling.
Underlying destination writer.
Whether output is currently inside an attribute value.
Creates a streaming writer using the supplied encoding name and single-quote attribute escaping.
writer - destination writerencoding - target encoding, or null to infer itCreates a streaming writer.
writer - destination writerencoding - target encoding, or null to infer ituseDoubleQuotes - whether attribute escaping should target double quotes instead of single quotesCreates a streaming writer that infers its encoding from the wrapped writer when possible.
writer - destination writerCloses the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.
Returns a writer view that applies XML escaping before delegating here.
Flushes the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.
If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.
Returns the normalized target encoding used for numeric escape decisions.
Returns whether the encoding came from an explicit or discoverable source.
true if the encoding is known preciselySwitches escaping rules between element text and attribute value output.
writingAttribute - true when writing an attribute valueReturns a writer view that bypasses the additional escaping layer.
Writes a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored.
Subclasses that intend to support efficient single-character output should override this method.
c
- int specifying a character to be writtenWrites a portion of an array of characters.
off is negative, or len is negative,
or off + len is negative or greater than the length
of the given arraycbuf
- Array of charactersoff
- Offset from which to start writing characterslen
- Number of characters to writeCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.