public class BufferedImageHttpMessageConverter extends Object implements HttpMessageConverter<BufferedImage>
HttpMessageConverter
that can read and write
BufferedImages
.
By default, this converter can read all media types that are supported
by the registered image readers,
and writes using the media type of the first available
registered image writer.
The latter can be overridden by setting the
defaultContentType
property.
If the cacheDir
property is set, this converter
will cache image data.
The process(ImageReadParam)
and process(ImageWriteParam)
template methods allow subclasses to override Image I/O parameters.
Constructor and Description |
---|
BufferedImageHttpMessageConverter() |
Modifier and Type | Method and Description |
---|---|
boolean |
canRead(Class<?> clazz,
MediaType mediaType)
Indicates whether the given class can be read by this converter.
|
boolean |
canWrite(Class<?> clazz,
MediaType mediaType)
Indicates whether the given class can be written by this converter.
|
MediaType |
getDefaultContentType()
Returns the default
Content-Type to be used for writing. |
List<MediaType> |
getSupportedMediaTypes()
Return the list of media types supported by this converter.
|
protected void |
process(ImageReadParam irp)
Template method that allows for manipulating the
ImageReadParam
before it is used to read an image. |
protected void |
process(ImageWriteParam iwp)
Template method that allows for manipulating the
ImageWriteParam
before it is used to write an image. |
BufferedImage |
read(Class<? extends BufferedImage> clazz,
HttpInputMessage inputMessage)
Read an object of the given type from the given input message, and returns it.
|
void |
setCacheDir(File cacheDir)
Sets the cache directory.
|
void |
setDefaultContentType(MediaType defaultContentType)
Sets the default
Content-Type to be used for writing. |
void |
write(BufferedImage image,
MediaType contentType,
HttpOutputMessage outputMessage)
Write an given object to the given output message.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getSupportedMediaTypes
public void setDefaultContentType(@Nullable MediaType defaultContentType)
Content-Type
to be used for writing.IllegalArgumentException
- if the given content type is not supported by the Java Image I/O API@Nullable public MediaType getDefaultContentType()
Content-Type
to be used for writing.
Called when write(java.awt.image.BufferedImage, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
is invoked without a specified content type parameter.public void setCacheDir(File cacheDir)
public boolean canRead(Class<?> clazz, @Nullable MediaType mediaType)
HttpMessageConverter
canRead
in interface HttpMessageConverter<BufferedImage>
clazz
- the class to test for readabilitymediaType
- the media type to read (can be null
if not specified);
typically the value of a Content-Type
header.true
if readable; false
otherwisepublic boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType)
HttpMessageConverter
canWrite
in interface HttpMessageConverter<BufferedImage>
clazz
- the class to test for writabilitymediaType
- the media type to write (can be null
if not specified);
typically the value of an Accept
header.true
if writable; false
otherwisepublic List<MediaType> getSupportedMediaTypes()
HttpMessageConverter
canWrite(clazz, null
. The list may also exclude MIME types supported
only for a specific class. Alternatively, use
HttpMessageConverter.getSupportedMediaTypes(Class)
for a more precise list.getSupportedMediaTypes
in interface HttpMessageConverter<BufferedImage>
public BufferedImage read(@Nullable Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
HttpMessageConverter
read
in interface HttpMessageConverter<BufferedImage>
clazz
- the type of object to return. This type must have previously been passed to the
canRead
method of this interface, which must have returned true
.inputMessage
- the HTTP input message to read fromIOException
- in case of I/O errorsHttpMessageNotReadableException
- in case of conversion errorspublic void write(BufferedImage image, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
HttpMessageConverter
write
in interface HttpMessageConverter<BufferedImage>
image
- the object to write to the output message. The type of this object must have previously been
passed to the canWrite
method of this interface, which must have returned true
.contentType
- the content type to use when writing. May be null
to indicate that the
default content type of the converter must be used. If not null
, this media type must have
previously been passed to the canWrite
method of this interface, which must have
returned true
.outputMessage
- the message to write toIOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errorsprotected void process(ImageReadParam irp)
ImageReadParam
before it is used to read an image.
The default implementation is empty.
protected void process(ImageWriteParam iwp)
ImageWriteParam
before it is used to write an image.
The default implementation is empty.