类 BufferedImageHttpMessageConverter
java.lang.Object
cn.taketoday.http.converter.BufferedImageHttpMessageConverter
- 所有已实现的接口:
HttpMessageConverter<BufferedImage>
public class BufferedImageHttpMessageConverter
extends Object
implements HttpMessageConverter<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.
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.
- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明booleanIndicates whether the given class can be read by this converter.booleanIndicates whether the given class can be written by this converter.private ImageInputStreamprivate ImageOutputStreamprivate MediaTypegetContentType(MediaType contentType) Returns the defaultContent-Typeto be used for writing.Return the list of media types supported by this converter.private booleanisReadable(MediaType mediaType) private booleanisWritable(MediaType mediaType) protected voidprocess(ImageReadParam irp) Template method that allows for manipulating theImageReadParambefore it is used to read an image.protected voidprocess(ImageWriteParam iwp) Template method that allows for manipulating theImageWriteParambefore it is used to write an image.read(Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage) Read an object of the given type from the given input message, and returns it.voidsetCacheDir(File cacheDir) Sets the cache directory.voidsetDefaultContentType(MediaType defaultContentType) Sets the defaultContent-Typeto be used for writing.voidwrite(BufferedImage image, MediaType contentType, HttpOutputMessage outputMessage) Write an given object to the given output message.private voidwriteInternal(BufferedImage image, MediaType contentType, OutputStream body) 从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.http.converter.HttpMessageConverter
getSupportedMediaTypes
-
字段详细资料
-
readableMediaTypes
-
cacheDir
-
defaultContentType
-
-
构造器详细资料
-
BufferedImageHttpMessageConverter
public BufferedImageHttpMessageConverter()
-
-
方法详细资料
-
setDefaultContentType
Sets the defaultContent-Typeto be used for writing.- 抛出:
IllegalArgumentException- if the given content type is not supported by the Java Image I/O API
-
getDefaultContentType
Returns the defaultContent-Typeto be used for writing. Called whenwrite(java.awt.image.BufferedImage, cn.taketoday.http.MediaType, cn.taketoday.http.HttpOutputMessage)is invoked without a specified content type parameter. -
setCacheDir
Sets the cache directory. If this property is set to an existing directory, this converter will cache image data. -
canRead
从接口复制的说明:HttpMessageConverterIndicates 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 benullif not specified); typically the value of aContent-Typeheader.- 返回:
trueif readable;falseotherwise
-
isReadable
-
canWrite
从接口复制的说明:HttpMessageConverterIndicates 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 benullif not specified); typically the value of anAcceptheader.- 返回:
trueif writable;falseotherwise
-
isWritable
-
getSupportedMediaTypes
从接口复制的说明:HttpMessageConverterReturn the list of media types supported by this converter. The list may not apply to every possible target element type and calls to this method should typically be guarded viacanWrite(clazz, null. The list may also exclude MIME types supported only for a specific class. Alternatively, useHttpMessageConverter.getSupportedMediaTypes(Class)for a more precise list.- 指定者:
getSupportedMediaTypes在接口中HttpMessageConverter<BufferedImage>- 返回:
- the list of supported media types
-
read
public BufferedImage read(@Nullable Class<? extends BufferedImage> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException 从接口复制的说明:HttpMessageConverterRead 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 thecanReadmethod 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
-
createImageInputStream
- 抛出:
IOException
-
write
public void write(BufferedImage image, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException 从接口复制的说明:HttpMessageConverterWrite 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 thecanWritemethod of this interface, which must have returnedtrue.contentType- the content type to use when writing. May benullto indicate that the default content type of the converter must be used. If notnull, this media type must have previously been passed to thecanWritemethod 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
-
getContentType
-
writeInternal
private void writeInternal(BufferedImage image, MediaType contentType, OutputStream body) throws IOException, HttpMessageNotWritableException -
createImageOutputStream
- 抛出:
IOException
-
process
Template method that allows for manipulating theImageReadParambefore it is used to read an image.The default implementation is empty.
-
process
Template method that allows for manipulating theImageWriteParambefore it is used to write an image.The default implementation is empty.
-