Class AbstractDataBufferDecoder<T>

java.lang.Object
org.springframework.core.codec.AbstractDecoder<T>
org.springframework.core.codec.AbstractDataBufferDecoder<T>
Type Parameters:
T - the element type
All Implemented Interfaces:
Decoder<T>
Direct Known Subclasses:
AbstractCharSequenceDecoder, ByteArrayDecoder, ByteBufferDecoder, DataBufferDecoder, GsonDecoder, NettyByteBufDecoder, ResourceDecoder

public abstract class AbstractDataBufferDecoder<T> extends AbstractDecoder<T>
Abstract base class for Decoder implementations that can decode a DataBuffer directly to the target element type.

Sub-classes must implement decodeDataBuffer(DataBuffer, ResolvableType, MimeType, Map) to provide a way to transform a DataBuffer to the target data type. The default decode(Publisher, ResolvableType, MimeType, Map) implementation transforms each individual data buffer while decodeToMono(Publisher, ResolvableType, MimeType, Map) applies "reduce" and transforms the aggregated buffer.

Sub-classes can override decode(Publisher, ResolvableType, MimeType, Map) in order to split the input stream along different boundaries (for example, on new line characters for String) or always reduce to a single data buffer (for example, Resource).

Since:
5.0
Author:
Rossen Stoyanchev
  • Constructor Details

    • AbstractDataBufferDecoder

      protected AbstractDataBufferDecoder(MimeType... supportedMimeTypes)
  • Method Details

    • setMaxInMemorySize

      public void setMaxInMemorySize(int byteCount)
      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 DataBuffer, ByteBuffer, byte[], Resource, String, etc. It can also occur when splitting the input stream, for example, delimited text, in which case the limit applies to data buffered between delimiters.

      By default this is set to 256K.

      Parameters:
      byteCount - the max number of bytes to buffer, or -1 for unlimited
      Since:
      5.1.11
    • getMaxInMemorySize

      public int getMaxInMemorySize()
      Return the configured byte count limit.
      Since:
      5.1.11
    • decode

      public reactor.core.publisher.Flux<T> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
      Description copied from interface: Decoder
      Decode a DataBuffer input stream into a Flux of T.
      Parameters:
      input - the DataBuffer input stream to decode
      elementType - the expected type of elements in the output stream; this type must have been previously passed to the Decoder.canDecode(ResolvableType, MimeType) method and it must have returned true.
      mimeType - the MIME type associated with the input stream (optional)
      hints - additional information about how to do decode
      Returns:
      the output stream with decoded elements
    • decodeToMono

      public reactor.core.publisher.Mono<T> decodeToMono(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
      Description copied from interface: Decoder
      Decode a DataBuffer input stream into a Mono of T.
      Specified by:
      decodeToMono in interface Decoder<T>
      Overrides:
      decodeToMono in class AbstractDecoder<T>
      Parameters:
      input - the DataBuffer input stream to decode
      elementType - the expected type of elements in the output stream; this type must have been previously passed to the Decoder.canDecode(ResolvableType, MimeType) method and it must have returned true.
      mimeType - the MIME type associated with the input stream (optional)
      hints - additional information about how to do decode
      Returns:
      the output stream with the decoded element
    • decodeDataBuffer

      @Deprecated(since="5.2") protected @Nullable T decodeDataBuffer(DataBuffer buffer, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
      Deprecated.
      How to decode a DataBuffer to the target element type.