Package org.springframework.http.codec
Class ResourceHttpMessageWriter
- java.lang.Object
- org.springframework.http.codec.ResourceHttpMessageWriter
- All Implemented Interfaces:
HttpMessageWriter<Resource>
public class ResourceHttpMessageWriter extends Object implements HttpMessageWriter<Resource>
HttpMessageWriter
that can write aResource
.Also an implementation of
HttpMessageWriter
with support for writing one or moreResourceRegion
's based on the HTTP ranges specified in the request.For reading to a Resource, use
ResourceDecoder
wrapped withDecoderHttpMessageReader
.- Since:
- 5.0
- Author:
- Arjen Poutsma, Brian Clozel, Rossen Stoyanchev
- See Also:
ResourceEncoder
,ResourceRegionEncoder
,HttpRange
Constructor Summary
Constructors Constructor Description ResourceHttpMessageWriter()
ResourceHttpMessageWriter(int bufferSize)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canWrite(ResolvableType elementType, MediaType mediaType)
Whether the given object type is supported by this writer.List<MediaType>
getWritableMediaTypes()
Return theMediaType
's that this writer supports.reactor.core.publisher.Mono<Void>
write(org.reactivestreams.Publisher<? extends Resource> inputStream, ResolvableType actualType, ResolvableType elementType, MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> hints)
Server-side only alternative toHttpMessageWriter.write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)
with additional context available.reactor.core.publisher.Mono<Void>
write(org.reactivestreams.Publisher<? extends Resource> inputStream, ResolvableType elementType, MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)
Write an given stream of object to the output message.
Constructor Detail
ResourceHttpMessageWriter
public ResourceHttpMessageWriter()
ResourceHttpMessageWriter
public ResourceHttpMessageWriter(int bufferSize)
Method Detail
canWrite
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
Description copied from interface:HttpMessageWriter
Whether the given object type is supported by this writer.- Specified by:
canWrite
in interfaceHttpMessageWriter<Resource>
- Parameters:
elementType
- the type of object to checkmediaType
- the media type for the write (possiblynull
)- Returns:
true
if writable,false
otherwise
getWritableMediaTypes
public List<MediaType> getWritableMediaTypes()
Description copied from interface:HttpMessageWriter
Return theMediaType
's that this writer supports.- Specified by:
getWritableMediaTypes
in interfaceHttpMessageWriter<Resource>
write
public reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends Resource> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage message, Map<String,Object> hints)
Description copied from interface:HttpMessageWriter
Write an given stream of object to the output message.- Specified by:
write
in interfaceHttpMessageWriter<Resource>
- Parameters:
inputStream
- the objects to writeelementType
- the type of objects in the stream which must have been previously checked viaHttpMessageWriter.canWrite(ResolvableType, MediaType)
mediaType
- the content type for the write (possiblynull
to indicate that the default content type of the writer must be used)message
- the message to write tohints
- additional information about how to encode and write- Returns:
- indicates completion or error
write
public reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<? extends Resource> inputStream, @Nullable ResolvableType actualType, ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response, Map<String,Object> hints)
Description copied from interface:HttpMessageWriter
Server-side only alternative toHttpMessageWriter.write(Publisher, ResolvableType, MediaType, ReactiveHttpOutputMessage, Map)
with additional context available.- Specified by:
write
in interfaceHttpMessageWriter<Resource>
actualType
- the actual return type of the method that returned the value; for annotated controllers, theMethodParameter
can be accessed viaResolvableType.getSource()
.elementType
- the type of Objects in the input streammediaType
- the content type to use (possiblynull
indicating the default content type of the writer should be used)request
- the current requestresponse
- the current response- Returns:
- a
Mono
that indicates completion of writing or error