类 BufferedImageHttpMessageConverter
- java.lang.Object
- org.springframework.http.converter.BufferedImageHttpMessageConverter
- 所有已实现的接口:
HttpMessageConverter<BufferedImage>
public class BufferedImageHttpMessageConverter extends Object implements HttpMessageConverter<BufferedImage>
Implementation ofHttpMessageConverter
that can read and writeBufferedImages
.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)
andprocess(ImageWriteParam)
template methods allow subclasses to override Image I/O parameters.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma
构造器概要
构造器 构造器 说明 BufferedImageHttpMessageConverter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 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 defaultContent-Type
to be used for writing.List<MediaType>
getSupportedMediaTypes()
Return the list ofMediaType
objects supported by this converter.protected void
process(ImageReadParam irp)
Template method that allows for manipulating theImageReadParam
before it is used to read an image.protected void
process(ImageWriteParam iwp)
Template method that allows for manipulating theImageWriteParam
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 defaultContent-Type
to be used for writing.void
write(BufferedImage image, MediaType contentType, HttpOutputMessage outputMessage)
Write an given object to the given output message.
构造器详细资料
BufferedImageHttpMessageConverter
public BufferedImageHttpMessageConverter()
方法详细资料
setDefaultContentType
public void setDefaultContentType(MediaType defaultContentType)
Sets the defaultContent-Type
to be used for writing.- 抛出:
IllegalArgumentException
- if the given content type is not supported by the Java Image I/O API
getDefaultContentType
public MediaType getDefaultContentType()
Returns the defaultContent-Type
to be used for writing. Called whenwrite(java.awt.image.BufferedImage, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
is invoked without a specified content type parameter.
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.
canRead
public boolean canRead(Class<?> clazz, MediaType mediaType)
从接口复制的说明:HttpMessageConverter
Indicates whether the given class can be read by this converter.- 指定者:
canRead
在接口中HttpMessageConverter<BufferedImage>
- 参数:
clazz
- the class to test for readabilitymediaType
- the media type to read (can benull
if not specified); typically the value of aContent-Type
header.- 返回:
true
if readable;false
otherwise
canWrite
public boolean canWrite(Class<?> clazz, MediaType mediaType)
从接口复制的说明:HttpMessageConverter
Indicates whether the given class can be written by this converter.- 指定者:
canWrite
在接口中HttpMessageConverter<BufferedImage>
- 参数:
clazz
- the class to test for writabilitymediaType
- the media type to write (can benull
if not specified); typically the value of anAccept
header.- 返回:
true
if writable;false
otherwise
getSupportedMediaTypes
public List<MediaType> getSupportedMediaTypes()
从接口复制的说明:HttpMessageConverter
Return the list ofMediaType
objects supported by this converter.- 指定者:
getSupportedMediaTypes
在接口中HttpMessageConverter<BufferedImage>
- 返回:
- the list of supported media types, potentially an immutable copy
read
public BufferedImage read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
从接口复制的说明:HttpMessageConverter
Read an object of the given type from the given input message, and returns it.- 指定者:
read
在接口中HttpMessageConverter<BufferedImage>
- 参数:
clazz
- the type of object to return. This type must have previously been passed to thecanRead
method of this interface, which must have returnedtrue
.inputMessage
- the HTTP input message to read from- 返回:
- the converted object
- 抛出:
IOException
- in case of I/O errorsHttpMessageNotReadableException
- in case of conversion errors
write
public void write(BufferedImage image, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException
从接口复制的说明:HttpMessageConverter
Write an given object to the given output message.- 指定者:
write
在接口中HttpMessageConverter<BufferedImage>
- 参数:
image
- the object to write to the output message. The type of this object must have previously been passed to thecanWrite
method of this interface, which must have returnedtrue
.contentType
- the content type to use when writing. May benull
to indicate that the default content type of the converter must be used. If notnull
, this media type must have previously been passed to thecanWrite
method of this interface, which must have returnedtrue
.outputMessage
- the message to write to- 抛出:
IOException
- in case of I/O errorsHttpMessageNotWritableException
- in case of conversion errors
process
protected void process(ImageReadParam irp)
Template method that allows for manipulating theImageReadParam
before it is used to read an image.The default implementation is empty.
process
protected void process(ImageWriteParam iwp)
Template method that allows for manipulating theImageWriteParam
before it is used to write an image.The default implementation is empty.