Class XmlEventDecoder
java.lang.Object
org.springframework.core.codec.AbstractDecoder<XMLEvent>
org.springframework.http.codec.xml.XmlEventDecoder
Decodes a
DataBuffer stream into a stream of XMLEvents.
Given the following XML:
<root>
<child>foo</child>
<child>bar</child>
</root>
this decoder will produce a Flux with the following events:
StartDocumentStartElementrootStartElementchildCharactersfooEndElementchildStartElementchildCharactersbarEndElementchildEndElementroot
Note that this decoder is not registered by default but is used internally by other decoders which are registered by default.
- Since:
- 5.0
- Author:
- Arjen Poutsma, Sam Brannen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCallers ofXmlEventDecoderthat buffer emitted XML events at a higher level, can pass an instance of this tracker as anBYTE_TRACKER_HINTto monitor the total number of bytes received, and to reset periodically. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringHint key for aXmlEventDecoder.ReceivedByteTrackerinstance that callers can use to track the number of received bytes.Fields inherited from class AbstractDecoder
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Decode aDataBufferinput stream into a Flux ofT.intReturn theconfiguredbyte count limit.voidsetMaxInMemorySize(int byteCount) Set the max number of bytes this decoder should buffer in memory resulting in aDataBufferLimitExceptionwhen the limit is exceeded.Methods inherited from class AbstractDecoder
canDecode, decodeToMono, getDecodableMimeTypes, getLogger, setLoggerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Decoder
decode, getDecodableMimeTypes
-
Field Details
-
BYTE_TRACKER_HINT
Hint key for aXmlEventDecoder.ReceivedByteTrackerinstance that callers can use to track the number of received bytes.
-
-
Constructor Details
-
XmlEventDecoder
public XmlEventDecoder()
-
-
Method Details
-
setMaxInMemorySize
public void setMaxInMemorySize(int byteCount) Set the max number of bytes this decoder should buffer in memory resulting in aDataBufferLimitExceptionwhen the limit is exceeded.When joining all buffers and decoding as a whole, the limit is applied to the entire input.
>When using Aalto XML async parsing, the limit does not apply at the level of this decoder because the XML events parsed from each buffer are emitted immediately and the buffer is released.
By default this is set to 256K.
- Parameters:
byteCount- the max number of bytes to buffer, or -1 for unlimited- Since:
- 5.1.11
-
getMaxInMemorySize
-
decode
public Flux<XMLEvent> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Description copied from interface:DecoderDecode aDataBufferinput stream into a Flux ofT.- Parameters:
input- theDataBufferinput stream to decodeelementType- the expected type of elements in the output stream; this type must have been previously passed to theDecoder.canDecode(ResolvableType, MimeType)method and it must have returnedtrue.mimeType- the MIME type associated with the input stream (optional)hints- additional information about how to do decode- Returns:
- the output stream with decoded elements
-