Top Description Fields Constructors Methods
org.springframework.http.codec.multipart

public Class PartEventHttpMessageReader

extends LoggingCodecSupport
implements HttpMessageReader<PartEvent>
Class Inheritance
All Implemented Interfaces
org.springframework.http.codec.HttpMessageReader
Imports
java.nio.charset.Charset, .StandardCharsets, java.util.Collections, .List, .Map, java.util.concurrent.atomic.AtomicInteger, .AtomicLong, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.core.ResolvableType, org.springframework.core.codec.DecodingException, org.springframework.core.io.buffer.DataBuffer, .DataBufferLimitException, .DataBufferUtils, org.springframework.http.HttpHeaders, .MediaType, .ReactiveHttpInputMessage, org.springframework.http.codec.HttpMessageReader, .LoggingCodecSupport, org.springframework.lang.Nullable, org.springframework.util.Assert

HttpMessageReader for parsing "multipart/form-data" requests to a stream of PartEvent elements.
Author
Arjen Poutsma
Since
6.0
See Also
PartEvent

Field Summary

Modifier and TypeField and Description
private Charset
private int
private int
private int
private long
Inherited from org.springframework.http.codec.LoggingCodecSupport:
logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead(ResolvableType
the type of object to check
elementType
,
MediaType
the media type for the read (possibly null)
mediaType
)

Implements org.springframework.http.codec.HttpMessageReader.canRead.

Whether the given object type is supported by this reader.

private Publisher<? extends PartEvent>
public int
getMaxInMemorySize()

Get the configured maximum in-memory size.

public List<MediaType>
getReadableMediaTypes()

Implements org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Return the list of media types supported by this reader.

public Flux<PartEvent>
read(ResolvableType
the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)
elementType
,
ReactiveHttpInputMessage
the message to read from
message
,
Map<String, Object>
additional information about how to read and decode the input
hints
)

Implements org.springframework.http.codec.HttpMessageReader.read.

Read from the input message and decode to a stream of objects.

public Mono<PartEvent>
readMono(ResolvableType
the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)
elementType
,
ReactiveHttpInputMessage
the message to read from
message
,
Map<String, Object>
additional information about how to read and decode the input
hints
)

Implements org.springframework.http.codec.HttpMessageReader.readMono.

Read from the input message and decode to a single object.

public void
setHeadersCharset(Charset
the charset to use for decoding headers
headersCharset
)

Set the character set used to decode headers.

public void
setMaxHeadersSize(int
the maximum amount of memory for headers
byteCount
)

Configure the maximum amount of memory that is allowed per headers section of each part.

public void
setMaxInMemorySize(int
the in-memory limit in bytes; if set to -1 the entire contents will be stored in memory
maxInMemorySize
)

Configure the maximum amount of memory allowed for form fields.

public void
setMaxParts(int maxParts)

Specify the maximum number of parts allowed in a given multipart request.

public void
setMaxPartSize(long maxPartSize)

Configure the maximum size allowed for any part.

private boolean
tooLarge(AtomicLong partSize, DataBuffer buffer)

private boolean
Inherited from org.springframework.http.codec.LoggingCodecSupport:
isEnableLoggingRequestDetailssetEnableLoggingRequestDetails

Field Detail

headersCharsetback to summary
private Charset headersCharset
maxHeadersSizeback to summary
private int maxHeadersSize
maxInMemorySizeback to summary
private int maxInMemorySize
maxPartsback to summary
private int maxParts
maxPartSizeback to summary
private long maxPartSize

Constructor Detail

PartEventHttpMessageReaderback to summary
public PartEventHttpMessageReader()

Method Detail

canReadback to summary
public boolean canRead(ResolvableType elementType, MediaType mediaType)

Implements org.springframework.http.codec.HttpMessageReader.canRead.

Doc from org.springframework.http.codec.HttpMessageReader.canRead.

Whether the given object type is supported by this reader.

Parameters
elementType:ResolvableType

the type of object to check

mediaType:MediaType

the media type for the read (possibly null)

Returns:boolean

true if readable, false otherwise

Annotations
@Override
createEventsback to summary
private Publisher<? extends PartEvent> createEvents(HttpHeaders headers, Flux<MultipartParser.BodyToken> bodyTokens)
getMaxInMemorySizeback to summary
public int getMaxInMemorySize()

Get the configured maximum in-memory size.

getReadableMediaTypesback to summary
public List<MediaType> getReadableMediaTypes()

Implements org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Doc from org.springframework.http.codec.HttpMessageReader.getReadableMediaTypes.

Return the list of media types supported by this reader. The list may not apply to every possible target element type and calls to this method should typically be guarded via canWrite(elementType, null). The list may also exclude media types supported only for a specific element type. Alternatively, use getReadableMediaTypes(ResolvableType) for a more precise list.

Returns:List<MediaType>

the general list of supported media types

Annotations
@Override
readback to summary
public Flux<PartEvent> read(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints)

Implements org.springframework.http.codec.HttpMessageReader.read.

Doc from org.springframework.http.codec.HttpMessageReader.read.

Read from the input message and decode to a stream of objects.

Parameters
elementType:ResolvableType

the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)

message:ReactiveHttpInputMessage

the message to read from

hints:Map<String, Object>

additional information about how to read and decode the input

Returns:Flux<PartEvent>

the decoded stream of elements

Annotations
@Override
readMonoback to summary
public Mono<PartEvent> readMono(ResolvableType elementType, ReactiveHttpInputMessage message, Map<String, Object> hints)

Implements org.springframework.http.codec.HttpMessageReader.readMono.

Doc from org.springframework.http.codec.HttpMessageReader.readMono.

Read from the input message and decode to a single object.

Parameters
elementType:ResolvableType

the type of objects in the stream which must have been previously checked via canRead(ResolvableType, MediaType)

message:ReactiveHttpInputMessage

the message to read from

hints:Map<String, Object>

additional information about how to read and decode the input

Returns:Mono<PartEvent>

the decoded object

Annotations
@Override
setHeadersCharsetback to summary
public void setHeadersCharset(Charset headersCharset)

Set the character set used to decode headers.

Defaults to UTF-8 as per RFC 7578.

Parameters
headersCharset:Charset

the charset to use for decoding headers

See Also
RFC-7578 Section 5.1
setMaxHeadersSizeback to summary
public void setMaxHeadersSize(int byteCount)

Configure the maximum amount of memory that is allowed per headers section of each part. Defaults to 10K.

Parameters
byteCount:int

the maximum amount of memory for headers

setMaxInMemorySizeback to summary
public void setMaxInMemorySize(int maxInMemorySize)

Configure the maximum amount of memory allowed for form fields. When the limit is exceeded, form fields parts are rejected with DataBufferLimitException.

By default this is set to 256K.

Parameters
maxInMemorySize:int

the in-memory limit in bytes; if set to -1 the entire contents will be stored in memory

setMaxPartsback to summary
public void setMaxParts(int maxParts)

Specify the maximum number of parts allowed in a given multipart request.

By default this is set to -1, meaning that there is no maximum.

Since
6.1
setMaxPartSizeback to summary
public void setMaxPartSize(long maxPartSize)

Configure the maximum size allowed for any part.

By default this is set to -1, meaning that there is no maximum.

Since
6.1
tooLargeback to summary
private boolean tooLarge(AtomicLong partSize, DataBuffer buffer)
tooManyPartsback to summary
private boolean tooManyParts(AtomicInteger partCount)