Top Description Constructors Methods
org.springframework.http.converter

public Class ResourceRegionHttpMessageConverter

extends AbstractGenericHttpMessageConverter<Object>
Class Inheritance
Imports
java.io.IOException, .InputStream, .OutputStream, java.lang.reflect.ParameterizedType, .Type, java.nio.charset.StandardCharsets, java.util.Collection, org.springframework.core.io.InputStreamResource, .Resource, org.springframework.core.io.support.ResourceRegion, org.springframework.http.HttpHeaders, .HttpInputMessage, .HttpOutputMessage, .MediaType, .MediaTypeFactory, org.springframework.lang.Nullable, org.springframework.util.Assert, .MimeTypeUtils, .StreamUtils

Implementation of HttpMessageConverter that can write a single ResourceRegion or Collections of ResourceRegions.
Authors
Brian Clozel, Juergen Hoeller, Sam Brannen
Since
4.3

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead(Class<?>
the class to test for readability
clazz
,
MediaType
the media type to read (can be null if not specified); typically the value of a Content-Type header.
mediaType
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.canRead.

Implements org.springframework.http.converter.HttpMessageConverter.canRead.

Indicates whether the given class can be read by this converter.
public boolean
canRead(Type
the (potentially generic) type to test for readability
type
,
Class<?>
a context class for the target type, for example a class in which the target type appears in a method signature (can be null)
contextClass
,
MediaType
the media type to read, can be null if not specified. Typically, the value of a Content-Type header.
mediaType
)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.canRead.

Implements org.springframework.http.converter.GenericHttpMessageConverter.canRead.

Indicates whether the given type can be read by this converter.
public boolean
canWrite(Class<?>
the class to test for writability
clazz
,
MediaType
the media type to write (can be null if not specified); typically the value of an Accept header.
mediaType
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.canWrite.

Implements org.springframework.http.converter.HttpMessageConverter.canWrite.

Indicates whether the given class can be written by this converter.
public boolean
canWrite(Type
the (potentially generic) type to test for writability (can be null if not specified)
type
,
Class<?>
the source object class to test for writability
clazz
,
MediaType
the media type to write (can be null if not specified); typically the value of an Accept header.
mediaType
)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.canWrite.

Implements org.springframework.http.converter.GenericHttpMessageConverter.canWrite.

Indicates whether the given class can be written by this converter.
protected MediaType
getDefaultContentType(Object
the type to return the content type for
object
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.getDefaultContentType.

Returns the default content type for the given type.
private static void
public Object
read(Type
the (potentially generic) type of object to return. This type must have previously been passed to the canRead method of this interface, which must have returned true.
type
,
Class<?>
a context class for the target type, for example a class in which the target type appears in a method signature (can be null)
contextClass
,
HttpInputMessage
the HTTP input message to read from
inputMessage
)

Implements org.springframework.http.converter.GenericHttpMessageConverter.read.

Read an object of the given type form the given input message, and returns it.
protected ResourceRegion
readInternal(Class<?>
the type of object to return
clazz
,
HttpInputMessage
the HTTP input message to read from
inputMessage
)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.readInternal.

Abstract template method that reads the actual object.
protected boolean
supportsRepeatableWrites(Object
the object t
object
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.
private boolean
supportsRepeatableWrites(ResourceRegion
the object t
region
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.
protected void
writeInternal(Object
the object to write to the output message
object
,
Type
the type of object to write (may be null)
type
,
HttpOutputMessage
the HTTP output message to write to
outputMessage
)

Implements abstract org.springframework.http.converter.AbstractGenericHttpMessageConverter.writeInternal.

Abstract template method that writes the actual body.
protected void
private void
Inherited from org.springframework.http.converter.AbstractGenericHttpMessageConverter:
supportswritewriteInternal

Constructor Detail

ResourceRegionHttpMessageConverterback to summary
public ResourceRegionHttpMessageConverter()

Method Detail

canReadback to summary
public boolean canRead(Class<?> clazz, MediaType mediaType)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.canRead.

Implements org.springframework.http.converter.HttpMessageConverter.canRead.

Doc from org.springframework.http.converter.HttpMessageConverter.canRead.

Indicates whether the given class can be read by this converter.

Parameters
clazz:Class<?>

the class to test for readability

mediaType:MediaType

the media type to read (can be null if not specified); typically the value of a Content-Type header.

Returns:boolean

true if readable; false otherwise

Annotations
@Override
canReadback to summary
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.canRead.

Implements org.springframework.http.converter.GenericHttpMessageConverter.canRead.

Doc from org.springframework.http.converter.GenericHttpMessageConverter.canRead.

Indicates whether the given type can be read by this converter. This method should perform the same checks as HttpMessageConverter#canRead(Class, MediaType) with additional ones related to the generic type.

Parameters
type:Type

the (potentially generic) type to test for readability

contextClass:Class<?>

a context class for the target type, for example a class in which the target type appears in a method signature (can be null)

mediaType:MediaType

the media type to read, can be null if not specified. Typically, the value of a Content-Type header.

Returns:boolean

true if readable; false otherwise

Annotations
@Override
canWriteback to summary
public boolean canWrite(Class<?> clazz, MediaType mediaType)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.canWrite.

Implements org.springframework.http.converter.HttpMessageConverter.canWrite.

Doc from org.springframework.http.converter.HttpMessageConverter.canWrite.

Indicates whether the given class can be written by this converter.

Parameters
clazz:Class<?>

the class to test for writability

mediaType:MediaType

the media type to write (can be null if not specified); typically the value of an Accept header.

Returns:boolean

true if writable; false otherwise

Annotations
@Override
canWriteback to summary
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType)

Overrides org.springframework.http.converter.AbstractGenericHttpMessageConverter.canWrite.

Implements org.springframework.http.converter.GenericHttpMessageConverter.canWrite.

Doc from org.springframework.http.converter.GenericHttpMessageConverter.canWrite.

Indicates whether the given class can be written by this converter.

This method should perform the same checks as HttpMessageConverter#canWrite(Class, MediaType) with additional ones related to the generic type.

Parameters
type:Type

the (potentially generic) type to test for writability (can be null if not specified)

clazz:Class<?>

the source object class to test for writability

mediaType:MediaType

the media type to write (can be null if not specified); typically the value of an Accept header.

Returns:boolean

true if writable; false otherwise

Annotations
@Override
getDefaultContentTypeback to summary
protected MediaType getDefaultContentType(Object object)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.getDefaultContentType.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.getDefaultContentType.

Returns the default content type for the given type. Called when write is invoked without a specified content type parameter.

By default, this returns the first element of the supportedMediaTypes property, if any. Can be overridden in subclasses.

Parameters
object:Object

the type to return the content type for

Returns:MediaType

the content type, or null if not known

Annotations
@Override
@SuppressWarnings:unchecked
printlnback to summary
private static void println(OutputStream os) throws IOException
readback to summary
public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException

Implements org.springframework.http.converter.GenericHttpMessageConverter.read.

Doc from org.springframework.http.converter.GenericHttpMessageConverter.read.

Read an object of the given type form the given input message, and returns it.

Parameters
type:Type

the (potentially generic) type of object to return. This type must have previously been passed to the canRead method of this interface, which must have returned true.

contextClass:Class<?>

a context class for the target type, for example a class in which the target type appears in a method signature (can be null)

inputMessage:HttpInputMessage

the HTTP input message to read from

Returns:Object

the converted object

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
HttpMessageNotReadableException:
in case of conversion errors
readInternalback to summary
protected ResourceRegion readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.readInternal.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.readInternal.

Abstract template method that reads the actual object. Invoked from read.

Parameters
clazz:Class<?>

the type of object to return

inputMessage:HttpInputMessage

the HTTP input message to read from

Returns:ResourceRegion

the converted object

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
HttpMessageNotReadableException:
in case of conversion errors
supportsRepeatableWritesback to summary
protected boolean supportsRepeatableWrites(Object object)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.

Default implementation returns false.

Parameters
object:Object

the object t

Returns:boolean

true if t can be written repeatedly; false otherwise

Annotations
@Override
@SuppressWarnings:unchecked
supportsRepeatableWritesback to summary
private boolean supportsRepeatableWrites(ResourceRegion region)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.

Default implementation returns false.

Parameters
region:ResourceRegion

the object t

Returns:boolean

true if t can be written repeatedly; false otherwise

writeInternalback to summary
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException

Implements abstract org.springframework.http.converter.AbstractGenericHttpMessageConverter.writeInternal.

Doc from org.springframework.http.converter.AbstractGenericHttpMessageConverter.writeInternal.

Abstract template method that writes the actual body. Invoked from write.

Parameters
object:Object

the object to write to the output message

type:Type

the type of object to write (may be null)

outputMessage:HttpOutputMessage

the HTTP output message to write to

Annotations
@Override
@SuppressWarnings:unchecked
Exceptions
IOException:
in case of I/O errors
HttpMessageNotWritableException:
in case of conversion errors
writeResourceRegionback to summary
protected void writeResourceRegion(ResourceRegion region, HttpOutputMessage outputMessage) throws IOException
writeResourceRegionCollectionback to summary
private void writeResourceRegionCollection(Collection<ResourceRegion> resourceRegions, HttpOutputMessage outputMessage) throws IOException