Top Description Fields Constructors Methods
org.springframework.core.codec

public Class ResourceRegionEncoder

extends AbstractEncoder<ResourceRegion>
Class Inheritance
Imports
java.io.IOException, java.nio.charset.StandardCharsets, java.util.Map, .OptionalLong, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.core.ResolvableType, org.springframework.core.io.InputStreamResource, .Resource, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DataBufferUtils, org.springframework.core.io.support.ResourceRegion, org.springframework.lang.Nullable, org.springframework.util.Assert, .MimeType, .MimeTypeUtils, .StreamUtils

Encoder for ResourceRegions.
Author
Brian Clozel
Since
5.0

Field Summary

Modifier and TypeField and Description
public static final String
BOUNDARY_STRING_HINT

The hint key that contains the boundary string.

private final int
public static final int
DEFAULT_BUFFER_SIZE

The default buffer size used by the encoder.

Inherited from org.springframework.core.codec.AbstractEncoder:
logger

Constructor Summary

AccessConstructor and Description
public
public
ResourceRegionEncoder(int bufferSize)

Method Summary

Modifier and TypeMethod and Description
public boolean
canEncode(ResolvableType
the type of elements in the source stream
elementType
,
MimeType
the MIME type for the output stream (can be null if not specified)
mimeType
)

Overrides org.springframework.core.codec.AbstractEncoder.canEncode.

Implements org.springframework.core.codec.Encoder.canEncode.

Whether the encoder supports the given source element type and the MIME type for the output stream.
private OptionalLong

Returns:

the contentLength of the resource
contentLength
(Resource
the resource instance
resource
)

Determine, if possible, the contentLength of the given resource without reading it.

public Flux<DataBuffer>
encode(Publisher<? extends ResourceRegion>
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.
input
,
DataBufferFactory
for creating output stream DataBuffer's
bufferFactory
,
ResolvableType
the expected type of elements in the input stream; this type must have been previously passed to the canEncode method and it must have returned true.
elementType
,
MimeType
the MIME type for the output content (optional)
mimeType
,
Map<String, Object>
additional information about how to encode
hints
)

Implements org.springframework.core.codec.Encoder.encode.

Encode a stream of Objects of type T into a DataBuffer output stream.
private byte[]
private DataBuffer
getRegionSuffix(DataBufferFactory bufferFactory, String boundaryString)

private byte[]
private Flux<DataBuffer>
Inherited from org.springframework.core.codec.AbstractEncoder:
getEncodableMimeTypesgetLoggersetLogger

Field Detail

BOUNDARY_STRING_HINTback to summary
public static final String BOUNDARY_STRING_HINT

The hint key that contains the boundary string.

bufferSizeback to summary
private final int bufferSize
DEFAULT_BUFFER_SIZEback to summary
public static final int DEFAULT_BUFFER_SIZE

The default buffer size used by the encoder.

Constructor Detail

ResourceRegionEncoderback to summary
public ResourceRegionEncoder()
ResourceRegionEncoderback to summary
public ResourceRegionEncoder(int bufferSize)

Method Detail

canEncodeback to summary
public boolean canEncode(ResolvableType elementType, MimeType mimeType)

Overrides org.springframework.core.codec.AbstractEncoder.canEncode.

Implements org.springframework.core.codec.Encoder.canEncode.

Doc from org.springframework.core.codec.Encoder.canEncode.

Whether the encoder supports the given source element type and the MIME type for the output stream.

Parameters
elementType:ResolvableType

the type of elements in the source stream

mimeType:MimeType

the MIME type for the output stream (can be null if not specified)

Returns:boolean

true if supported, false otherwise

Annotations
@Override
contentLengthback to summary
private OptionalLong contentLength(Resource resource)

Determine, if possible, the contentLength of the given resource without reading it.

Parameters
resource:Resource

the resource instance

Returns:OptionalLong

the contentLength of the resource

encodeback to summary
public Flux<DataBuffer> encode(Publisher<? extends ResourceRegion> input, DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType, Map<String, Object> hints)

Implements org.springframework.core.codec.Encoder.encode.

Doc from org.springframework.core.codec.Encoder.encode.

Encode a stream of Objects of type T into a DataBuffer output stream.

Parameters
input:Publisher<? extends ResourceRegion>

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:DataBufferFactory

for creating output stream DataBuffer's

elementType:ResolvableType

the expected type of elements in the input stream; this type must have been previously passed to the canEncode method and it must have returned true.

mimeType:MimeType

the MIME type for the output content (optional)

hints:Map<String, Object>

additional information about how to encode

Returns:Flux<DataBuffer>

the output stream

Annotations
@Override
getContentRangeHeaderback to summary
private byte[] getContentRangeHeader(ResourceRegion region)
getRegionSuffixback to summary
private DataBuffer getRegionSuffix(DataBufferFactory bufferFactory, String boundaryString)
toAsciiBytesback to summary
private byte[] toAsciiBytes(String in)
writeResourceRegionback to summary
private Flux<DataBuffer> writeResourceRegion(ResourceRegion region, DataBufferFactory bufferFactory, Map<String, Object> hints)