类 ServerSentEventHttpMessageReader

java.lang.Object
cn.taketoday.http.codec.ServerSentEventHttpMessageReader
所有已实现的接口:
HttpMessageReader<Object>

public class ServerSentEventHttpMessageReader extends Object implements HttpMessageReader<Object>
Reader that supports a stream of ServerSentEvents and also plain Objects which is the same as an ServerSentEvent with data only.
从以下版本开始:
4.0
作者:
Sebastien Deleuze, Rossen Stoyanchev
  • 字段详细资料

    • STRING_TYPE

      private static final cn.taketoday.core.ResolvableType STRING_TYPE
    • decoder

      @Nullable private final cn.taketoday.core.codec.Decoder<?> decoder
    • lineDecoder

      private final cn.taketoday.core.codec.StringDecoder lineDecoder
  • 构造器详细资料

    • ServerSentEventHttpMessageReader

      public ServerSentEventHttpMessageReader()
      Constructor without a Decoder. In this mode only String is supported as the data of an event.
    • ServerSentEventHttpMessageReader

      public ServerSentEventHttpMessageReader(@Nullable cn.taketoday.core.codec.Decoder<?> decoder)
      Constructor with JSON Decoder for decoding to Objects. Support for decoding to String event data is built-in.
  • 方法详细资料

    • getDecoder

      @Nullable public cn.taketoday.core.codec.Decoder<?> getDecoder()
      Return the configured Decoder.
    • setMaxInMemorySize

      public void setMaxInMemorySize(int byteCount)
      Configure a limit on the maximum number of bytes per SSE event which are buffered before the event is parsed.

      Note that the data decoder, if provided, must also be customized accordingly to raise the limit if necessary in order to be able to parse the data portion of the event.

      By default this is set to 256K.

      参数:
      byteCount - the max number of bytes to buffer, or -1 for unlimited
    • getMaxInMemorySize

      public int getMaxInMemorySize()
      Return the configured byte count limit.
    • getReadableMediaTypes

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

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

      private boolean isServerSentEvent(cn.taketoday.core.ResolvableType elementType)
    • read

      public reactor.core.publisher.Flux<Object> read(cn.taketoday.core.ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
      从接口复制的说明: HttpMessageReader
      Read from the input message and decode to a stream of objects.
      指定者:
      read 在接口中 HttpMessageReader<Object>
      参数:
      elementType - the type of objects in the stream which must have been previously checked via HttpMessageReader.canRead(ResolvableType, MediaType)
      message - the message to read from
      hints - additional information about how to read and decode the input
      返回:
      the decoded stream of elements
    • buildEvent

      @Nullable private Object buildEvent(List<String> lines, cn.taketoday.core.ResolvableType valueType, boolean shouldWrap, Map<String,Object> hints)
    • decodeData

      @Nullable private Object decodeData(StringBuilder data, cn.taketoday.core.ResolvableType dataType, Map<String,Object> hints)
    • readMono

      public reactor.core.publisher.Mono<Object> readMono(cn.taketoday.core.ResolvableType elementType, ReactiveHttpInputMessage message, Map<String,Object> hints)
      从接口复制的说明: HttpMessageReader
      Read from the input message and decode to a single object.
      指定者:
      readMono 在接口中 HttpMessageReader<Object>
      参数:
      elementType - the type of objects in the stream which must have been previously checked via HttpMessageReader.canRead(ResolvableType, MediaType)
      message - the message to read from
      hints - additional information about how to read and decode the input
      返回:
      the decoded object