org.springframework.core.codec

## Class ResourceEncoder

- java.lang.Object
- - org.springframework.core.codec.AbstractEncoder<T>
  - - org.springframework.core.codec.AbstractSingleValueEncoder<Resource>
    - - org.springframework.core.codec.ResourceEncoder

- All Implemented Interfaces:
    Encoder<Resource>

      public class ResourceEncoder
      extends AbstractSingleValueEncoder<Resource>

  Encoder for `Resources`.
  Since:
    5.0
  Author:
    Arjen Poutsma

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_BUFFER_SIZE` The default buffer size used by the encoder.

    - ### Fields inherited from class org.springframework.core.codec.AbstractEncoder

      `logger`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceEncoder()`
    `ResourceEncoder(int bufferSize)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canEncode(ResolvableType elementType, MimeType mimeType)` Whether the encoder supports the given source element type and the MIME type for the output stream.
    `protected reactor.core.publisher.Flux<DataBuffer>` | `encode(Resource resource, DataBufferFactory bufferFactory, ResolvableType type, MimeType mimeType, Map<String,Object> hints)` Encode `T` to an output `DataBuffer` stream.

    - ### Methods inherited from class org.springframework.core.codec.AbstractSingleValueEncoder

      `encode`

    - ### Methods inherited from class org.springframework.core.codec.AbstractEncoder

      `getEncodableMimeTypes, getLogger, setLogger`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.springframework.core.codec.Encoder

      `encodeValue, getEncodableMimeTypes`

- - ### Field Detail

    - #### DEFAULT_BUFFER_SIZE

          public static final int DEFAULT_BUFFER_SIZE

      The default buffer size used by the encoder.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ResourceEncoder

          public ResourceEncoder()

    - #### ResourceEncoder

          public ResourceEncoder(int bufferSize)

  - ### Method Detail

    - #### canEncode

          public boolean canEncode(ResolvableType elementType,
                                   @Nullable
                                   MimeType mimeType)

      Description copied from interface: `Encoder`
      Whether the encoder supports the given source element type and the MIME type for the output stream.
      Specified by:
        `canEncode` in interface `Encoder<Resource>`
      Overrides:
        `canEncode` in class `AbstractEncoder<Resource>`
      Parameters:
        `elementType` - the type of elements in the source stream
        `mimeType` - the MIME type for the output stream (can be `null` if not specified)
      Returns:
        `true` if supported, `false` otherwise

    - #### encode

          protected reactor.core.publisher.Flux<DataBuffer> encode(Resource resource,
                                                                   DataBufferFactory bufferFactory,
                                                                   ResolvableType type,
                                                                   @Nullable
                                                                   MimeType mimeType,
                                                                   @Nullable
                                                                   Map<String,Object> hints)

      Description copied from class: `AbstractSingleValueEncoder`
      Encode `T` to an output `DataBuffer` stream.
      Specified by:
        `encode` in class `AbstractSingleValueEncoder<Resource>`
      Parameters:
        `resource` - the value to process
        `bufferFactory` - a buffer factory used to create the output
        `type` - the stream element type to process
        `mimeType` - the mime type to process
        `hints` - additional information about how to do decode, optional
      Returns:
        the output stream