public class

BufferedImageHttpMessageConverter

extends Object
implements HttpMessageConverter<T>
java.lang.Object
   ↳ org.springframework.http.converter.BufferedImageHttpMessageConverter

Class Overview

Implementation of HttpMessageConverter that can read and write BufferedImage 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. This behavior can be overriden by setting the #setContentType(org.springframework.http.MediaType) contentType} properties.

If the cacheDir property is set to an existing directory, this converter will cache image data.

The process(ImageReadParam) and process(ImageWriteParam) template methods allow subclasses to override Image I/O parameters.

Summary

Public Constructors
BufferedImageHttpMessageConverter()
Public Methods
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 MediaType objects supported by this converter.
BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)
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)
Protected Methods
void process(ImageWriteParam iwp)
Template method that allows for manipulating the ImageWriteParam before it is used to write an image.
void process(ImageReadParam irp)
Template method that allows for manipulating the ImageReadParam before it is used to read an image.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.http.converter.HttpMessageConverter

Public Constructors

public BufferedImageHttpMessageConverter ()

Public Methods

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

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

Parameters
clazz the class to test for readability
mediaType the media type to read, can be null if not specified. Typically the value of a Content-Type header.
Returns
  • true if readable; false otherwise

public boolean canWrite (Class<?> clazz, MediaType mediaType)

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

Parameters
clazz the class to test for writability
mediaType the media type to write, can be null if not specified. Typically the value of an Accept header.
Returns
  • true if writable; false otherwise

public MediaType getDefaultContentType ()

Returns the default Content-Type to be used for writing. Called when write(T, MediaType, HttpOutputMessage) is invoked without a specified content type parameter.

public List<MediaType> getSupportedMediaTypes ()

Return the list of MediaType objects supported by this converter.

Returns
  • the list of supported media types

public BufferedImage read (Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage)

public void setCacheDir (File cacheDir)

Sets the cache directory. If this property is set to an existing directory, this converter will cache image data.

public void setDefaultContentType (MediaType defaultContentType)

Sets the default Content-Type to be used for writing.

Throws
IllegalArgumentException if the given content type is not supported by the Java Image I/O API

public void write (BufferedImage image, MediaType contentType, HttpOutputMessage outputMessage)

Protected Methods

protected void process (ImageWriteParam iwp)

Template method that allows for manipulating the ImageWriteParam before it is used to write an image.

Default implementation is empty.

protected void process (ImageReadParam irp)

Template method that allows for manipulating the ImageReadParam before it is used to read an image.

Default implementation is empty.