org.springframework.http.converter
Class BufferedImageHttpMessageConverter

java.lang.Object
  extended by org.springframework.http.converter.AbstractHttpMessageConverter<BufferedImage>
      extended by org.springframework.http.converter.BufferedImageHttpMessageConverter
All Implemented Interfaces:
HttpMessageConverter<BufferedImage>

public class BufferedImageHttpMessageConverter
extends AbstractHttpMessageConverter<BufferedImage>

Implementation of 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. This behavior can be overriden by setting the supportedMediaTypes and contentType properties respectively.

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.

Since:
3.0
Author:
Arjen Poutsma

Field Summary
 
Fields inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
logger
 
Constructor Summary
BufferedImageHttpMessageConverter()
           
 
Method Summary
protected  MediaType getContentType(BufferedImage image)
          Returns the content type for the given type.
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 readInternal(Class<BufferedImage> clazz, HttpInputMessage inputMessage)
          Abstract template method that reads the actualy object.
 void setCacheDir(File cacheDir)
          Sets the cache directory.
 void setContentType(MediaType contentType)
          Sets the Content-Type to be used for writing.
 void setSupportedMediaTypes(List<MediaType> supportedMediaTypes)
          Sets the MediaTypes supported for reading.
 boolean supports(Class<? extends BufferedImage> clazz)
          Indicate whether the given class is supported by this converter.
protected  void writeInternal(BufferedImage image, HttpOutputMessage outputMessage)
          Abstract template method that writes the actual body.
 
Methods inherited from class org.springframework.http.converter.AbstractHttpMessageConverter
getContentLength, getSupportedMediaTypes, read, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedImageHttpMessageConverter

public BufferedImageHttpMessageConverter()
Method Detail

setSupportedMediaTypes

public void setSupportedMediaTypes(List<MediaType> supportedMediaTypes)
Sets the MediaTypes supported for reading.

Overrides:
setSupportedMediaTypes in class AbstractHttpMessageConverter<BufferedImage>
Throws:
IllegalArgumentException - if the given media type is not supported by the Java Image I/O API

setContentType

public void setContentType(MediaType contentType)
Sets the Content-Type to be used for writing.

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

setCacheDir

public void setCacheDir(File cacheDir)
Sets the cache directory. If this property is set to an existing directory, this converter will cache image data.


supports

public boolean supports(Class<? extends BufferedImage> clazz)
Description copied from interface: HttpMessageConverter
Indicate whether the given class is supported by this converter.

Parameters:
clazz - the class to test for support
Returns:
true if supported; false otherwise

readInternal

public BufferedImage readInternal(Class<BufferedImage> clazz,
                                  HttpInputMessage inputMessage)
                           throws IOException
Description copied from class: AbstractHttpMessageConverter
Abstract template method that reads the actualy object. Invoked from AbstractHttpMessageConverter.read(Class, HttpInputMessage).

Specified by:
readInternal in class AbstractHttpMessageConverter<BufferedImage>
Parameters:
clazz - the type of object to return
inputMessage - the HTTP input message to read from
Returns:
the converted object
Throws:
IOException - in case of I/O errors

getContentType

protected MediaType getContentType(BufferedImage image)
Description copied from class: AbstractHttpMessageConverter
Returns the content type for the given type.

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

Overrides:
getContentType in class AbstractHttpMessageConverter<BufferedImage>
Parameters:
image - the type to return the content type for
Returns:
the content type, or null if not known

writeInternal

protected void writeInternal(BufferedImage image,
                             HttpOutputMessage outputMessage)
                      throws IOException
Description copied from class: AbstractHttpMessageConverter
Abstract template method that writes the actual body. Invoked from AbstractHttpMessageConverter.write(Object, HttpOutputMessage).

Specified by:
writeInternal in class AbstractHttpMessageConverter<BufferedImage>
Parameters:
image - the object to write to the output message
outputMessage - the message to write to
Throws:
IOException - in case of I/O errors

process

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.


process

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.