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

pack-priv final Class MultipartParser

extends BaseSubscriber<DataBuffer>
Class Inheritance
Imports
java.nio.charset.Charset, .StandardCharsets, java.util.ArrayDeque, .ArrayList, .Deque, .Iterator, .List, java.util.concurrent.ConcurrentLinkedDeque, java.util.concurrent.atomic.AtomicBoolean, .AtomicInteger, .AtomicReference, org.apache.commons.logging.Log, .LogFactory, org.reactivestreams.Subscription, reactor.core.publisher.BaseSubscriber, .Flux, .FluxSink, reactor.util.context.Context, org.springframework.core.codec.DecodingException, org.springframework.core.io.buffer.DataBuffer, .DataBufferLimitException, .DataBufferUtils, org.springframework.http.HttpHeaders, org.springframework.lang.Nullable

Subscribes to a buffer stream and produces a flux of Token instances.
Author
Arjen Poutsma
Since
5.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
MultipartParser.BodyState

The state of the parser dealing with multipart bodies.

public static class
MultipartParser.BodyToken

Represents a token that contains DataBuffer.

private static class
MultipartParser.DisposedState

The state of the parser when finished, either due to seeing the final boundary or to a malformed message.

private class
MultipartParser.HeadersState

The state of the parser dealing with part headers.

public static class
MultipartParser.HeadersToken

Represents a token that contains HttpHeaders.

private class
MultipartParser.PreambleState

The initial state of the parser.

private static interface
MultipartParser.State

Represents the internal state of the MultipartParser.

public abstract static class

Field Summary

Modifier and TypeField and Description
private final byte[]
private static final byte
private static final byte[]
private static final String
private final Charset
private static final byte
private static final byte
private static final Log
private final int
private final AtomicBoolean
private final FluxSink<MultipartParser.Token>
private final AtomicReference<MultipartParser.State>
private static final byte[]

Constructor Summary

AccessConstructor and Description
private
MultipartParser(FluxSink<MultipartParser.Token> sink, byte[] boundary, int maxHeadersSize, Charset headersCharset)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
public Context
currentContext()

Overrides default reactor.core.CoreSubscriber.currentContext.

Request a Context from dependent components which can include downstream operators during subscribing or a terminal org.reactivestreams.Subscriber.

pack-priv void
emitBody(DataBuffer buffer, boolean last)

pack-priv void
pack-priv void
pack-priv void
protected void
hookOnComplete()

Overrides reactor.core.publisher.BaseSubscriber.hookOnComplete.

Optional hook for completion processing.

protected void
hookOnError(Throwable
the error to process
throwable
)

Overrides reactor.core.publisher.BaseSubscriber.hookOnError.

Optional hook for error processing.

protected void
hookOnNext(DataBuffer
the emitted value to process
value
)

Overrides reactor.core.publisher.BaseSubscriber.hookOnNext.

Hook for processing of onNext values.

protected void
hookOnSubscribe(Subscription
the subscription to optionally process
subscription
)

Overrides reactor.core.publisher.BaseSubscriber.hookOnSubscribe.

Hook for further processing of onSubscribe's Subscription.

private void
public static Flux<MultipartParser.Token>

Returns:

a stream of parsed tokens
parse
(Flux<DataBuffer>
the input buffers
buffers
,
byte[]
the multipart boundary, as found in the Content-Type header
boundary
,
int
the maximum buffered header size
maxHeadersSize
,
Charset
the charset to use for decoding headers
headersCharset
)

Parses the given stream of DataBuffer objects into a stream of Token objects.

private void
Inherited from reactor.core.publisher.BaseSubscriber:
canceldisposehookFinallyhookOnCancelisDisposedonCompleteonErroronNextonSubscriberequestrequestUnboundedtoStringupstream

Field Detail

boundaryback to summary
private final byte[] boundary
CRback to summary
private static final byte CR
CR_LFback to summary
private static final byte[] CR_LF
HEADER_ENTRY_SEPARATORback to summary
private static final String HEADER_ENTRY_SEPARATOR
headersCharsetback to summary
private final Charset headersCharset
HYPHENback to summary
private static final byte HYPHEN
LFback to summary
private static final byte LF
loggerback to summary
private static final Log logger
maxHeadersSizeback to summary
private final int maxHeadersSize
requestOutstandingback to summary
private final AtomicBoolean requestOutstanding
sinkback to summary
private final FluxSink<MultipartParser.Token> sink
stateback to summary
private final AtomicReference<MultipartParser.State> state
TWO_HYPHENSback to summary
private static final byte[] TWO_HYPHENS

Constructor Detail

MultipartParserback to summary
private MultipartParser(FluxSink<MultipartParser.Token> sink, byte[] boundary, int maxHeadersSize, Charset headersCharset)

Method Detail

changeStateback to summary
pack-priv boolean changeState(MultipartParser.State oldState, MultipartParser.State newState, DataBuffer remainder)
currentContextback to summary
public Context currentContext()

Overrides default reactor.core.CoreSubscriber.currentContext.

Doc from reactor.core.CoreSubscriber.currentContext.

Request a Context from dependent components which can include downstream operators during subscribing or a terminal org.reactivestreams.Subscriber.

Returns:Context

a resolved context or Context#empty()

Annotations
@Override
emitBodyback to summary
pack-priv void emitBody(DataBuffer buffer, boolean last)
emitCompleteback to summary
pack-priv void emitComplete()
emitErrorback to summary
pack-priv void emitError(Throwable t)
emitHeadersback to summary
pack-priv void emitHeaders(HttpHeaders headers)
hookOnCompleteback to summary
protected void hookOnComplete()

Overrides reactor.core.publisher.BaseSubscriber.hookOnComplete.

Doc from reactor.core.publisher.BaseSubscriber.hookOnComplete.

Optional hook for completion processing. Defaults to doing nothing.

Annotations
@Override
hookOnErrorback to summary
protected void hookOnError(Throwable throwable)

Overrides reactor.core.publisher.BaseSubscriber.hookOnError.

Doc from reactor.core.publisher.BaseSubscriber.hookOnError.

Optional hook for error processing. Default is to call Exceptions#errorCallbackNotImplemented(Throwable).

Parameters
throwable:Throwable

the error to process

Annotations
@Override
hookOnNextback to summary
protected void hookOnNext(DataBuffer value)

Overrides reactor.core.publisher.BaseSubscriber.hookOnNext.

Doc from reactor.core.publisher.BaseSubscriber.hookOnNext.

Hook for processing of onNext values. You can call request(long) here to further request data from the source org.reactivestreams.Publisher if the initial request wasn't unbounded.

Defaults to doing nothing.

Parameters
value:DataBuffer

the emitted value to process

Annotations
@Override
hookOnSubscribeback to summary
protected void hookOnSubscribe(Subscription subscription)

Overrides reactor.core.publisher.BaseSubscriber.hookOnSubscribe.

Doc from reactor.core.publisher.BaseSubscriber.hookOnSubscribe.

Hook for further processing of onSubscribe's Subscription. Implement this method to call request(long) as an initial request. Values other than the unbounded Long.MAX_VALUE imply that you'll also call request in hookOnNext(Object).

Defaults to request unbounded Long.MAX_VALUE as in requestUnbounded()

Parameters
subscription:Subscription

the subscription to optionally process

Annotations
@Override
onSinkCancelback to summary
private void onSinkCancel()
parseback to summary
public static Flux<MultipartParser.Token> parse(Flux<DataBuffer> buffers, byte[] boundary, int maxHeadersSize, Charset headersCharset)

Parses the given stream of DataBuffer objects into a stream of Token objects.

Parameters
buffers:Flux<DataBuffer>

the input buffers

boundary:byte[]

the multipart boundary, as found in the Content-Type header

maxHeadersSize:int

the maximum buffered header size

headersCharset:Charset

the charset to use for decoding headers

Returns:Flux<MultipartParser.Token>

a stream of parsed tokens

requestBufferback to summary
private void requestBuffer()
org.springframework.http.codec.multipart back to summary

private final Class MultipartParser.BodyState

extends Object
implements State
Class Inheritance
  • java.lang.Object
  • org.springframework.http.codec.multipart.MultipartParser.BodyState
All Implemented Interfaces
org.springframework.http.codec.multipart.MultipartParser.State

The state of the parser dealing with multipart bodies. Relays data buffers as BodyToken until the boundary is found (or rather: CR LF - - boundary).

Field Summary

Modifier and TypeField and Description
private final DataBufferUtils.Matcher
private final int
private final Deque<DataBuffer>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
private void
enqueue(DataBuffer buf)

Store the given buffer.

private void
public void
public void
onNext(DataBuffer buffer)

Implements org.springframework.http.codec.multipart.MultipartParser.State.onNext.

Checks whether the (end of the) needle CR LF - - boundary can be found in buffer.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

boundaryback to summary
private final DataBufferUtils.Matcher boundary
boundaryLengthback to summary
private final int boundaryLength
queueback to summary
private final Deque<DataBuffer> queue

Constructor Detail

BodyStateback to summary
public BodyState()

Method Detail

disposeback to summary
public void dispose()

Overrides default org.springframework.http.codec.multipart.MultipartParser.State.dispose.

Annotations
@Override
enqueueback to summary
private void enqueue(DataBuffer buf)

Store the given buffer. Emit buffers that cannot contain boundary bytes, by iterating over the queue in reverse order, and summing buffer sizes. The first buffer that passes the boundary length and subsequent buffers are emitted (in the correct, non-reverse order).

flushback to summary
private void flush()
onCompleteback to summary
public void onComplete()

Implements org.springframework.http.codec.multipart.MultipartParser.State.onComplete.

Annotations
@Override
onNextback to summary
public void onNext(DataBuffer buffer)

Implements org.springframework.http.codec.multipart.MultipartParser.State.onNext.

Checks whether the (end of the) needle CR LF - - boundary can be found in buffer. If found, the needle can overflow into the previous buffer, so we calculate the length and slice the current and previous buffers accordingly. We then change to HeadersState and pass on the remainder of buffer. If the needle is not found, we enqueue buffer.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.http.codec.multipart back to summary

public final Class MultipartParser.BodyToken

extends Token
Class Inheritance

Represents a token that contains DataBuffer.

Field Summary

Modifier and TypeField and Description
private final DataBuffer
private final boolean

Constructor Summary

AccessConstructor and Description
public
BodyToken(DataBuffer buffer, boolean last)

Method Summary

Modifier and TypeMethod and Description
public DataBuffer
public HttpHeaders
public boolean

Field Detail

bufferback to summary
private final DataBuffer buffer
lastback to summary
private final boolean last

Constructor Detail

BodyTokenback to summary
public BodyToken(DataBuffer buffer, boolean last)

Method Detail

bufferback to summary
public DataBuffer buffer()

Implements abstract org.springframework.http.codec.multipart.MultipartParser.Token.buffer.

Annotations
@Override
headersback to summary
public HttpHeaders headers()

Implements abstract org.springframework.http.codec.multipart.MultipartParser.Token.headers.

Annotations
@Override
isLastback to summary
public boolean isLast()

Implements abstract org.springframework.http.codec.multipart.MultipartParser.Token.isLast.

Annotations
@Override
org.springframework.http.codec.multipart back to summary

private final Class MultipartParser.DisposedState

extends Object
implements State
Class Inheritance
  • java.lang.Object
  • org.springframework.http.codec.multipart.MultipartParser.DisposedState
All Implemented Interfaces
org.springframework.http.codec.multipart.MultipartParser.State

The state of the parser when finished, either due to seeing the final boundary or to a malformed message. Releases all incoming buffers.

Field Summary

Modifier and TypeField and Description
public static final MultipartParser.DisposedState

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

INSTANCEback to summary
public static final MultipartParser.DisposedState INSTANCE

Constructor Detail

DisposedStateback to summary
private DisposedState()

Method Detail

onCompleteback to summary
public void onComplete()

Implements org.springframework.http.codec.multipart.MultipartParser.State.onComplete.

Annotations
@Override
onNextback to summary
public void onNext(DataBuffer buf)

Implements org.springframework.http.codec.multipart.MultipartParser.State.onNext.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.http.codec.multipart back to summary

private final Class MultipartParser.HeadersState

extends Object
implements State
Class Inheritance
  • java.lang.Object
  • org.springframework.http.codec.multipart.MultipartParser.HeadersState
All Implemented Interfaces
org.springframework.http.codec.multipart.MultipartParser.State

The state of the parser dealing with part headers. Parses header buffers into a HttpHeaders instance, making sure that the amount does not exceed maxHeadersSize.

Field Summary

Modifier and TypeField and Description
private final List<DataBuffer>
private final AtomicInteger
private final DataBufferUtils.Matcher

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private boolean
belowMaxHeaderSize(long count)

Checks whether the given count is below or equal to maxHeadersSize and emits a DataBufferLimitException if not.

public void
private boolean
isLastBoundary(DataBuffer buf)

If the given buffer is the first buffer, check whether it starts with --.

public void
public void
onNext(DataBuffer buf)

Implements org.springframework.http.codec.multipart.MultipartParser.State.onNext.

First checks whether the multipart boundary leading to this state was the final boundary.

private HttpHeaders
parseHeaders()

Parses the list of buffers into a HttpHeaders instance.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

buffersback to summary
private final List<DataBuffer> buffers
byteCountback to summary
private final AtomicInteger byteCount
endHeadersback to summary
private final DataBufferUtils.Matcher endHeaders

Constructor Detail

HeadersStateback to summary
private HeadersState()

Method Detail

belowMaxHeaderSizeback to summary
private boolean belowMaxHeaderSize(long count)

Checks whether the given count is below or equal to maxHeadersSize and emits a DataBufferLimitException if not.

disposeback to summary
public void dispose()

Overrides default org.springframework.http.codec.multipart.MultipartParser.State.dispose.

Annotations
@Override
isLastBoundaryback to summary
private boolean isLastBoundary(DataBuffer buf)

If the given buffer is the first buffer, check whether it starts with --. If it is the second buffer, check whether it makes up -- together with the first buffer.

onCompleteback to summary
public void onComplete()

Implements org.springframework.http.codec.multipart.MultipartParser.State.onComplete.

Annotations
@Override
onNextback to summary
public void onNext(DataBuffer buf)

Implements org.springframework.http.codec.multipart.MultipartParser.State.onNext.

First checks whether the multipart boundary leading to this state was the final boundary. Then looks for the header-body boundary (CR LF CR LF) in the given buffer. If found, checks whether the size of all header buffers does not exceed maxHeadersSize, converts all buffers collected so far into a HttpHeaders object and changes to BodyState, passing the remainder of the buffer. If the boundary is not found, the buffer is collected if its size does not exceed maxHeadersSize.

Annotations
@Override
parseHeadersback to summary
private HttpHeaders parseHeaders()

Parses the list of buffers into a HttpHeaders instance. Converts the joined buffers into a string using ISO=8859-1, and parses that string into key and values.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.http.codec.multipart back to summary

public final Class MultipartParser.HeadersToken

extends Token
Class Inheritance

Represents a token that contains HttpHeaders.

Field Summary

Modifier and TypeField and Description
private final HttpHeaders

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public DataBuffer
public HttpHeaders
public boolean

Field Detail

headersback to summary
private final HttpHeaders headers

Constructor Detail

HeadersTokenback to summary
public HeadersToken(HttpHeaders headers)

Method Detail

bufferback to summary
public DataBuffer buffer()

Implements abstract org.springframework.http.codec.multipart.MultipartParser.Token.buffer.

Annotations
@Override
headersback to summary
public HttpHeaders headers()

Implements abstract org.springframework.http.codec.multipart.MultipartParser.Token.headers.

Annotations
@Override
isLastback to summary
public boolean isLast()

Implements abstract org.springframework.http.codec.multipart.MultipartParser.Token.isLast.

Annotations
@Override
org.springframework.http.codec.multipart back to summary

private final Class MultipartParser.PreambleState

extends Object
implements State
Class Inheritance
  • java.lang.Object
  • org.springframework.http.codec.multipart.MultipartParser.PreambleState
All Implemented Interfaces
org.springframework.http.codec.multipart.MultipartParser.State

The initial state of the parser. Looks for the first boundary of the multipart message. Note that the first boundary is not necessarily prefixed with CR LF; only the prefix -- is required.

Field Summary

Modifier and TypeField and Description
private final DataBufferUtils.Matcher

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
onNext(DataBuffer buf)

Implements org.springframework.http.codec.multipart.MultipartParser.State.onNext.

Looks for the first boundary in the given buffer.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

firstBoundaryback to summary
private final DataBufferUtils.Matcher firstBoundary

Constructor Detail

PreambleStateback to summary
public PreambleState()

Method Detail

onCompleteback to summary
public void onComplete()

Implements org.springframework.http.codec.multipart.MultipartParser.State.onComplete.

Annotations
@Override
onNextback to summary
public void onNext(DataBuffer buf)

Implements org.springframework.http.codec.multipart.MultipartParser.State.onNext.

Looks for the first boundary in the given buffer. If found, changes state to HeadersState, and passes on the remainder of the buffer.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.http.codec.multipart back to summary

private Interface MultipartParser.State

Known Direct Implementers
org.springframework.http.codec.multipart.MultipartParser.PreambleState, org.springframework.http.codec.multipart.MultipartParser.HeadersState, org.springframework.http.codec.multipart.MultipartParser.BodyState, org.springframework.http.codec.multipart.MultipartParser.DisposedState

Represents the internal state of the MultipartParser. The flow for well-formed multipart messages is shown below:

    PREAMBLE
        |
        v
 +-->HEADERS--->DISPOSED
 |      |
 |      v
 +----BODY
 
For malformed messages the flow ends in DISPOSED, and also when the sink is cancelled.

Method Summary

Modifier and TypeMethod and Description
public default void
public void
public void

Method Detail

disposeback to summary
public default void dispose()
onCompleteback to summary
public void onComplete()
onNextback to summary
public void onNext(DataBuffer buf)
org.springframework.http.codec.multipart back to summary

public abstract Class MultipartParser.Token

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.http.codec.multipart.MultipartParser.Token
Known Direct Subclasses
org.springframework.http.codec.multipart.MultipartParser.HeadersToken, org.springframework.http.codec.multipart.MultipartParser.BodyToken

Represents the output of parse(Flux, byte[], int, Charset).

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract DataBuffer
public abstract HttpHeaders
public abstract boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Tokenback to summary
public Token()

Method Detail

bufferback to summary
public abstract DataBuffer buffer()
headersback to summary
public abstract HttpHeaders headers()
isLastback to summary
public abstract boolean isLast()