Top Description Fields Constructors Methods
org.springframework.messaging.simp.stomp

public Class BufferingStompDecoder

extends Object
Class Inheritance
Imports
java.nio.ByteBuffer, java.util.Collections, .List, .Queue, java.util.concurrent.LinkedBlockingQueue, org.springframework.lang.Nullable, org.springframework.messaging.Message, org.springframework.util.Assert, .LinkedMultiValueMap, .MultiValueMap

An extension of org.springframework.messaging.simp.stomp.StompDecoder that buffers content remaining in the input ByteBuffer after the parent class has read all (complete) STOMP frames from it. The remaining content represents an incomplete STOMP frame. When called repeatedly with additional data, the decode method returns one or more messages 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.

Author
Rossen Stoyanchev
Since
4.0.3
See Also
StompDecoder

Field Summary

Modifier and TypeField and Description
private final int
private final Queue<ByteBuffer>
private volatile Integer
private final StompDecoder

Constructor Summary

AccessConstructor and Description
public
BufferingStompDecoder(StompDecoder
the target decoder to wrap
stompDecoder
,
int
the buffer size limit
bufferSizeLimit
)

Create a new BufferingStompDecoder wrapping the given StompDecoder.

Method Summary

Modifier and TypeMethod and Description
private ByteBuffer
private void
public List<Message<byte[]>>

Returns:

decoded messages or an empty list
decode
(ByteBuffer
a buffer containing new data to decode
newBuffer
)

Decodes one or more STOMP frames from the given ByteBuffer into a list of Messages.

public int
getBufferSize()

Calculate the current buffer size.

public final int
getBufferSizeLimit()

Return the configured buffer size limit.

public Integer
getExpectedContentLength()

Get the expected content length of the currently buffered, incomplete STOMP frame.

public final StompDecoder
getStompDecoder()

Return the wrapped StompDecoder.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferSizeLimitback to summary
private final int bufferSizeLimit
chunksback to summary
private final Queue<ByteBuffer> chunks
expectedContentLengthback to summary
private volatile Integer expectedContentLength
Annotations
@Nullable
stompDecoderback to summary
private final StompDecoder stompDecoder

Constructor Detail

BufferingStompDecoderback to summary
public BufferingStompDecoder(StompDecoder stompDecoder, int bufferSizeLimit)

Create a new BufferingStompDecoder wrapping the given StompDecoder.

Parameters
stompDecoder:StompDecoder

the target decoder to wrap

bufferSizeLimit:int

the buffer size limit

Method Detail

assembleChunksAndResetback to summary
private ByteBuffer assembleChunksAndReset()
checkBufferLimitsback to summary
private void checkBufferLimits()
decodeback to summary
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:ByteBuffer

a buffer containing new data to decode

Returns:List<Message<byte[]>>

decoded messages or an empty list

Exceptions
StompConversionException:
raised in case of decoding issues
getBufferSizeback to summary
public int getBufferSize()

Calculate the current buffer size.

getBufferSizeLimitback to summary
public final int getBufferSizeLimit()

Return the configured buffer size limit.

getExpectedContentLengthback to summary
public Integer getExpectedContentLength()

Get the expected content length of the currently buffered, incomplete STOMP frame.

Annotations
@Nullable
getStompDecoderback to summary
public final StompDecoder getStompDecoder()

Return the wrapped StompDecoder.