查看Spring Core 5.1.14.RELEASE的AbstractDataBufferDecoder类,发现以下说明:
设置maxInMemorySize值的说明原因:
/**
*配置可随时缓冲的字节数限制
*需要聚合输入流。这可能是
*解码为单个{@code DataBuffer},
*{@链接java.nio.ByteBuffer文件ByteBuffer},{@code byte[]},
*{@链接org.springframework.core.io.资源资源}、{@code String}等。
*分割输入流时也会发生这种情况,例如分隔文本,
*在这种情况下,限制适用于分隔符之间缓冲的数据。
*<p>在5.1中,默认设置为-1,无限制。在5.2中,默认
*此限制的值设置为256K。
*@param byteCount缓冲区的最大字节数,或-1表示无限
*@自5.1.11
*/
源码如下:
public abstract class AbstractDataBufferDecoder<T> extends AbstractDecoder<T> {
private int maxInMemorySize = -1;
protected AbstractDataBufferDecoder(MimeType... supportedMimeTypes) {
super(supportedMimeTypes);
}
/**
* Configure a limit on the number of bytes that can be buffered whenever
* the input stream needs to be aggregated. This can be a result of
* decoding to a single {@code DataBuffer},
* {@link java.nio.ByteBuffer ByteBuffer}, {@code byte[]},
* {@link org.springframework.core.io.Resource Resource}, {@code String}, etc.
* It can also occur when splitting the input stream, e.g. delimited text,
* in which case the limit applies to data buffered between delimiters.
* <p>By default in 5.1 this is set to -1, unlimited. In 5.2 the default
* value for this limit is set to 256K.
* @param byteCount the max number of bytes to buffer, or -1 for unlimited
* @since 5.1.11
*/
public void setMaxInMemorySize(int byteCount) {
this.maxInMemorySize = byteCount;
}
/**
* Return the {@link #setMaxInMemorySize configured} byte count limit.
* @since 5.1.11
*/
public int getMaxInMemorySize() {
return this.maxInMemorySize;
}
...
}
对比查看Spring Core 5.2.2.RELEASE的AbstractDataBufferDecoder类,发现虽然maxInMemorySize的默认值是262144,但是外部是可以调用它的setMaxInMemorySize()方法来设值的。但是不知道什么原因,设值就是不生效。
public abstract class AbstractDataBufferDecoder<T> extends AbstractDecoder<T> {
private int maxInMemorySize = 262144;
...
public void setMaxInMemorySize(int byteCount) {
this.maxInMemorySize = byteCount;
}
public int getMaxInMemorySize() {
return this.maxInMemorySize;
}
...
}