类 EncoderHttpMessageWriter<T>

java.lang.Object
cn.taketoday.http.codec.EncoderHttpMessageWriter<T>
类型参数:
T - the type of objects in the input stream
所有已实现的接口:
HttpMessageWriter<T>
直接已知子类:
ProtobufHttpMessageWriter

public class EncoderHttpMessageWriter<T> extends Object implements HttpMessageWriter<T>
HttpMessageWriter that wraps and delegates to an Encoder.

Also a HttpMessageWriter that pre-resolves encoding hints from the extra information available on the server side such as the request or controller method annotations.

从以下版本开始:
4.0
作者:
Arjen Poutsma, Sebastien Deleuze, Rossen Stoyanchev, Brian Clozel, Sam Brannen
  • 字段详细资料

    • logger

      private static final cn.taketoday.logging.Logger logger
    • encoder

      private final cn.taketoday.core.codec.Encoder<T> encoder
    • mediaTypes

      private final List<MediaType> mediaTypes
    • defaultMediaType

      @Nullable private final MediaType defaultMediaType
  • 构造器详细资料

    • EncoderHttpMessageWriter

      public EncoderHttpMessageWriter(cn.taketoday.core.codec.Encoder<T> encoder)
      Create an instance wrapping the given Encoder.
  • 方法详细资料

    • initLogger

      private static void initLogger(cn.taketoday.core.codec.Encoder<?> encoder)
    • initDefaultMediaType

      @Nullable private static MediaType initDefaultMediaType(List<MediaType> mediaTypes)
    • getEncoder

      public cn.taketoday.core.codec.Encoder<T> getEncoder()
      Return the Encoder of this writer.
    • getWritableMediaTypes

      public List<MediaType> getWritableMediaTypes()
      从接口复制的说明: HttpMessageWriter
      Return the list of media types supported by this Writer. 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 HttpMessageWriter.getWritableMediaTypes(ResolvableType) for a more precise list.
      指定者:
      getWritableMediaTypes 在接口中 HttpMessageWriter<T>
      返回:
      the general list of supported media types
    • getWritableMediaTypes

      public List<MediaType> getWritableMediaTypes(cn.taketoday.core.ResolvableType elementType)
      从接口复制的说明: HttpMessageWriter
      Return the list of media types supported by this Writer for the given type of element. This list may differ from HttpMessageWriter.getWritableMediaTypes() if the Writer doesn't support the element type, or if it supports it only for a subset of media types.
      指定者:
      getWritableMediaTypes 在接口中 HttpMessageWriter<T>
      参数:
      elementType - the type of element to encode
      返回:
      the list of media types supported for the given class
    • canWrite

      public boolean canWrite(cn.taketoday.core.ResolvableType elementType, @Nullable MediaType mediaType)
      从接口复制的说明: HttpMessageWriter
      Whether the given object type is supported by this writer.
      指定者:
      canWrite 在接口中 HttpMessageWriter<T>
      参数:
      elementType - the type of object to check
      mediaType - the media type for the write (possibly null)
      返回:
      true if writable, false otherwise
    • write

      public reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends T> inputStream, cn.taketoday.core.ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)
      从接口复制的说明: HttpMessageWriter
      Write an given stream of object to the output message.
      指定者:
      write 在接口中 HttpMessageWriter<T>
      参数:
      inputStream - the objects to write
      elementType - the type of objects in the stream which must have been previously checked via HttpMessageWriter.canWrite(ResolvableType, MediaType)
      mediaType - the content type for the write (possibly null to indicate that the default content type of the writer must be used)
      message - the message to write to
      hints - additional information about how to encode and write
      返回:
      indicates completion or error
    • updateContentType

      @Nullable private MediaType updateContentType(ReactiveHttpOutputMessage message, @Nullable MediaType mediaType)
    • useFallback

      private static boolean useFallback(@Nullable MediaType main, @Nullable MediaType fallback)
    • addDefaultCharset

      private static MediaType addDefaultCharset(MediaType main, @Nullable MediaType defaultType)
    • isStreamingMediaType

      private boolean isStreamingMediaType(@Nullable MediaType mediaType)
    • matchParameters

      private boolean matchParameters(MediaType streamingMediaType, MediaType mediaType)
    • write

      public reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends T> inputStream, cn.taketoday.core.ResolvableType actualType, cn.taketoday.core.ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> hints)
      从接口复制的说明: HttpMessageWriter
      Server-side only alternative to HttpMessageWriter.write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map) with additional context available.
      指定者:
      write 在接口中 HttpMessageWriter<T>
      actualType - the actual return type of the method that returned the value; for annotated controllers, the Parameter can be accessed via ResolvableType.getSource().
      elementType - the type of Objects in the input stream
      mediaType - the content type to use (possibly null indicating the default content type of the writer should be used)
      request - the current request
      response - the current response
      返回:
      a Mono that indicates completion of writing or error
    • getWriteHints

      protected Map<String,Object> getWriteHints(cn.taketoday.core.ResolvableType streamType, cn.taketoday.core.ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response)
      Get additional hints for encoding for example based on the server request or annotations from controller method parameters. By default, delegate to the encoder if it is an instance of HttpMessageEncoder.