Polishing contribution
Closes gh-31970
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,12 +29,10 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
/**
|
||||
* An extension of {@link 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.
|
||||
* Uses {@link org.springframework.messaging.simp.stomp.StompDecoder} to decode
|
||||
* a {@link 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.
|
||||
*
|
||||
* <p>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
|
||||
|
||||
@@ -24,11 +24,12 @@ import java.util.Map;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* An extension of {@link org.springframework.messaging.simp.stomp.StompEncoder}
|
||||
* that splits the STOMP message to multiple incomplete STOMP frames
|
||||
* when the encoded bytes length exceeds {@link SplittingStompEncoder#bufferSizeLimit}.
|
||||
* Uses {@link org.springframework.messaging.simp.stomp.StompEncoder} to encode
|
||||
* a message and splits it into parts no larger than the configured
|
||||
* {@link SplittingStompEncoder#bufferSizeLimit}.
|
||||
*
|
||||
* @author Injae Kim
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 6.2
|
||||
* @see StompEncoder
|
||||
*/
|
||||
@@ -38,6 +39,7 @@ public class SplittingStompEncoder {
|
||||
|
||||
private final int bufferSizeLimit;
|
||||
|
||||
|
||||
public SplittingStompEncoder(StompEncoder encoder, int bufferSizeLimit) {
|
||||
Assert.notNull(encoder, "StompEncoder is required");
|
||||
Assert.isTrue(bufferSizeLimit > 0, "Buffer size limit must be greater than 0");
|
||||
@@ -45,11 +47,13 @@ public class SplittingStompEncoder {
|
||||
this.bufferSizeLimit = bufferSizeLimit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Encodes the given payload and headers into a list of one or more {@code byte[]}s.
|
||||
* @param headers the headers
|
||||
* @param payload the payload
|
||||
* @return the list of one or more encoded messages
|
||||
* Encode the given payload and headers to a STOMP frame, and split into a
|
||||
* list of parts based on the configured buffer size limit.
|
||||
* @param headers the STOMP message headers
|
||||
* @param payload the STOMP message payload
|
||||
* @return the parts of the encoded STOMP message
|
||||
*/
|
||||
public List<byte[]> encode(Map<String, Object> headers, byte[] payload) {
|
||||
byte[] result = this.encoder.encode(headers, payload);
|
||||
@@ -65,4 +69,5 @@ public class SplittingStompEncoder {
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -83,8 +83,8 @@ public class StompEncoder {
|
||||
|
||||
/**
|
||||
* Encodes the given payload and headers into a {@code byte[]}.
|
||||
* @param headers the headers
|
||||
* @param payload the payload
|
||||
* @param headers the STOMP message headers
|
||||
* @param payload the STOMP message payload
|
||||
* @return the encoded message
|
||||
*/
|
||||
public byte[] encode(Map<String, Object> headers, byte[] payload) {
|
||||
|
||||
Reference in New Issue
Block a user