Class XmlEventDecoder

java.lang.Object
org.springframework.core.codec.AbstractDecoder<XMLEvent>
org.springframework.http.codec.xml.XmlEventDecoder
All Implemented Interfaces:
org.springframework.core.codec.Decoder<XMLEvent>

public class XmlEventDecoder extends org.springframework.core.codec.AbstractDecoder<XMLEvent>
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:
  1. StartDocument
  2. StartElement root
  3. StartElement child
  4. Characters foo
  5. EndElement child
  6. StartElement child
  7. Characters bar
  8. EndElement child
  9. EndElement root

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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Callers of XmlEventDecoder that buffer emitted XML events at a higher level, can pass an instance of this tracker as an BYTE_TRACKER_HINT to monitor the total number of bytes received, and to reset periodically.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Hint key for a XmlEventDecoder.ReceivedByteTracker instance that callers can use to track the number of received bytes.

    Fields inherited from class org.springframework.core.codec.AbstractDecoder

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    decode(Publisher<org.springframework.core.io.buffer.DataBuffer> input, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String,Object> hints)
     
    int
    Return the configured byte count limit.
    void
    setMaxInMemorySize(int byteCount)
    Set the max number of bytes this decoder should buffer in memory resulting in a DataBufferLimitException when the limit is exceeded.

    Methods inherited from class org.springframework.core.codec.AbstractDecoder

    canDecode, decodeToMono, getDecodableMimeTypes, getLogger, setLogger

    Methods inherited from class Object

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

    Methods inherited from interface org.springframework.core.codec.Decoder

    decode, getDecodableMimeTypes
  • Field Details

  • 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 a DataBufferLimitException when 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

      public int getMaxInMemorySize()
      Return the configured byte count limit.
      Since:
      5.1.11
    • decode

      public Flux<XMLEvent> decode(Publisher<org.springframework.core.io.buffer.DataBuffer> input, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String,Object> hints)