org.springframework.core.codec

## 接口 Encoder<T>

- 类型参数:
    `T` - the type of elements in the input stream
  所有已知实现类:
    AbstractEncoder, AbstractSingleValueEncoder, ByteArrayEncoder, ByteBufferEncoder, CharSequenceEncoder, DataBufferEncoder, ResourceEncoder, ResourceRegionEncoder

      public interface Encoder<T>

  Strategy to encode a stream of Objects of type `<T>` into an output stream of bytes.
  从以下版本开始:
    5.0
  作者:
    Sebastien Deleuze, Rossen Stoyanchev

- - ### 方法概要

    所有方法 实例方法 抽象方法 默认方法 已过时的方法
    限定符和类型 | 方法和说明
    --- | ---
    `boolean` | `canEncode(ResolvableType elementType, MimeType mimeType)` Whether the encoder supports the given source element type and the MIME type for the output stream.
    `reactor.core.publisher.Flux<DataBuffer>` | `encode(org.reactivestreams.Publisher<? extends T> inputStream, DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType, Map<String,Object> hints)` Encode a stream of Objects of type `T` into a `DataBuffer` output stream.
    `default Long` | `getContentLength(T t, MimeType mimeType)` 已过时。 this method was added so `EncoderHttpMessageWriter` can set the content-length header. However after further improvements as of 5.0.7, it is no longer needed, and not used.
    `List<MimeType>` | `getEncodableMimeTypes()` Return the list of mime types this encoder supports.

- - ### 方法详细资料

    - #### canEncode

          boolean canEncode(ResolvableType elementType,
                            @Nullable
                            MimeType mimeType)

      Whether the encoder supports the given source element type and the MIME type for the output stream.
      参数:
        `elementType` - the type of elements in the source stream
        `mimeType` - the MIME type for the output stream (can be `null` if not specified)
      返回:
        `true` if supported, `false` otherwise

    - #### encode

          reactor.core.publisher.Flux<DataBuffer> encode(org.reactivestreams.Publisher<? extends T> inputStream,
                                                         DataBufferFactory bufferFactory,
                                                         ResolvableType elementType,
                                                         @Nullable
                                                         MimeType mimeType,
                                                         @Nullable
                                                         Map<String,Object> hints)

      Encode a stream of Objects of type `T` into a `DataBuffer` output stream.
      参数:
        `inputStream` - the input stream of Objects to encode. If the input should be encoded as a single value rather than as a stream of elements, an instance of `Mono` should be used.
        `bufferFactory` - for creating output stream `DataBuffer`'s
        `elementType` - the expected type of elements in the input stream; this type must have been previously passed to the `canEncode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)` method and it must have returned `true`.
        `mimeType` - the MIME type for the output stream (optional)
        `hints` - additional information about how to do encode
      返回:
        the output stream

    - #### getContentLength

          @Nullable
           @Deprecated
          default Long getContentLength(T t,
                                                                 @Nullable
                                                                 MimeType mimeType)

      已过时。 this method was added so `EncoderHttpMessageWriter` can set the content-length header. However after further improvements as of 5.0.7, it is no longer needed, and not used.
      Return the length for the given item, if known.
      参数:
        `t` - the item to check
      返回:
        the length in bytes, or `null` if not known.
      从以下版本开始:
        5.0.5

    - #### getEncodableMimeTypes

          List<MimeType> getEncodableMimeTypes()

      Return the list of mime types this encoder supports.