类 ResourceHttpMessageWriter

java.lang.Object
cn.taketoday.http.codec.ResourceHttpMessageWriter
所有已实现的接口:
HttpMessageWriter<cn.taketoday.core.io.Resource>

public class ResourceHttpMessageWriter extends Object implements HttpMessageWriter<cn.taketoday.core.io.Resource>
HttpMessageWriter that can write a Resource.

Also an implementation of HttpMessageWriter with support for writing one or more ResourceRegion's based on the HTTP ranges specified in the request.

For reading to a Resource, use ResourceDecoder wrapped with DecoderHttpMessageReader.

从以下版本开始:
4.0
作者:
Arjen Poutsma, Brian Clozel, Rossen Stoyanchev, Harry Yang
另请参阅:
  • ResourceEncoder
  • ResourceRegionEncoder
  • HttpRange
  • 字段详细资料

    • logger

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

      private static final cn.taketoday.core.ResolvableType REGION_TYPE
    • encoder

      private final cn.taketoday.core.codec.ResourceEncoder encoder
    • mediaTypes

      private final List<MediaType> mediaTypes
    • regionEncoder

      private final cn.taketoday.core.codec.ResourceRegionEncoder regionEncoder
  • 构造器详细资料

    • ResourceHttpMessageWriter

      public ResourceHttpMessageWriter()
    • ResourceHttpMessageWriter

      public ResourceHttpMessageWriter(int bufferSize)
  • 方法详细资料

    • 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<cn.taketoday.core.io.Resource>
      参数:
      elementType - the type of object to check
      mediaType - the media type for the write (possibly null)
      返回:
      true if writable, false otherwise
    • 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<cn.taketoday.core.io.Resource>
      返回:
      the general list of supported media types
    • write

      public reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends cn.taketoday.core.io.Resource> 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<cn.taketoday.core.io.Resource>
      参数:
      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
    • writeResource

      private reactor.core.publisher.Mono<Void> writeResource(cn.taketoday.core.io.Resource resource, cn.taketoday.core.ResolvableType type, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)
    • addDefaultHeaders

      public reactor.core.publisher.Mono<Void> addDefaultHeaders(ReactiveHttpOutputMessage message, cn.taketoday.core.io.Resource resource, @Nullable MediaType contentType, Map<String,Object> hints)
      Adds the default headers for the given resource to the given message.
    • getResourceMediaType

      private static MediaType getResourceMediaType(@Nullable MediaType mediaType, cn.taketoday.core.io.Resource resource, Map<String,Object> hints)
    • lengthOf

      private static reactor.core.publisher.Mono<Long> lengthOf(cn.taketoday.core.io.Resource resource)
    • zeroCopy

      @Nullable private static reactor.core.publisher.Mono<Void> zeroCopy(cn.taketoday.core.io.Resource resource, @Nullable cn.taketoday.core.io.ResourceRegion region, ReactiveHttpOutputMessage message, Map<String,Object> hints)
    • write

      public reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends cn.taketoday.core.io.Resource> inputStream, @Nullable 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<cn.taketoday.core.io.Resource>
      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
    • writeSingleRegion

      private reactor.core.publisher.Mono<Void> writeSingleRegion(cn.taketoday.core.io.ResourceRegion region, ReactiveHttpOutputMessage message, Map<String,Object> hints)
    • encodeAndWriteRegions

      private reactor.core.publisher.Mono<Void> encodeAndWriteRegions(org.reactivestreams.Publisher<? extends cn.taketoday.core.io.ResourceRegion> publisher, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)