Class BufferingStompDecoder

java.lang.Object
org.springframework.messaging.simp.stomp.BufferingStompDecoder

public class BufferingStompDecoder extends Object
Uses StompDecoder to decode a ByteBuffer to one or more STOMP message. If the message is incomplete, unused content is buffered and combined with the next input buffer, or if there is not enough data still, continues to buffer.

A single instance of this decoder can be invoked repeatedly to read all messages from a single stream (e.g. WebSocket session) as long as decoding does not fail. If there is an exception, StompDecoder instance should not be used any more as its internal state is not guaranteed to be consistent. It is expected that the underlying session is closed at that point.

Since:
4.0.3
Author:
Rossen Stoyanchev
See Also:
  • Constructor Details

    • BufferingStompDecoder

      public BufferingStompDecoder(StompDecoder stompDecoder, int bufferSizeLimit)
      Create a new BufferingStompDecoder wrapping the given StompDecoder.
      Parameters:
      stompDecoder - the target decoder to wrap
      bufferSizeLimit - the buffer size limit
  • Method Details

    • getStompDecoder

      public final StompDecoder getStompDecoder()
      Return the wrapped StompDecoder.
    • getBufferSizeLimit

      public final int getBufferSizeLimit()
      Return the configured buffer size limit.
    • decode

      public List<Message<byte[]>> decode(ByteBuffer newBuffer)
      Decodes one or more STOMP frames from the given ByteBuffer into a list of Messages.

      If there was enough data to parse a "content-length" header, then the value is used to determine how much more data is needed before a new attempt to decode is made.

      If there was not enough data to parse the "content-length", or if there is "content-length" header, every subsequent call to decode attempts to parse again with all available data. Therefore the presence of a "content-length" header helps to optimize the decoding of large messages.

      Parameters:
      newBuffer - a buffer containing new data to decode
      Returns:
      decoded messages or an empty list
      Throws:
      StompConversionException - raised in case of decoding issues
    • getBufferSize

      public int getBufferSize()
      Calculate the current buffer size.
    • getExpectedContentLength

      @Nullable public Integer getExpectedContentLength()
      Get the expected content length of the currently buffered, incomplete STOMP frame.