public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<org.springframework.core.io.Resource>
HttpMessageConverter that can read and write Resources.
By default, this converter can read all media types. The Java Activation Framework (JAF) -
if available - is used to determine the Content-Type of written resources.
If JAF is not available, application/octet-stream is used.
logger| Constructor and Description |
|---|
ResourceHttpMessageConverter() |
| Modifier and Type | Method and Description |
|---|---|
protected Long |
getContentLength(org.springframework.core.io.Resource resource,
MediaType contentType)
Returns the content length for the given type.
|
protected MediaType |
getDefaultContentType(org.springframework.core.io.Resource resource)
Returns the default content type for the given type.
|
protected org.springframework.core.io.Resource |
readInternal(Class<? extends org.springframework.core.io.Resource> clazz,
HttpInputMessage inputMessage)
Abstract template method that reads the actual object.
|
protected boolean |
supports(Class<?> clazz)
Indicates whether the given class is supported by this converter.
|
protected void |
writeInternal(org.springframework.core.io.Resource resource,
HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.
|
canRead, canRead, canWrite, canWrite, getSupportedMediaTypes, read, setSupportedMediaTypes, writeprotected boolean supports(Class<?> clazz)
AbstractHttpMessageConvertersupports in class AbstractHttpMessageConverter<org.springframework.core.io.Resource>clazz - the class to test for supporttrue if supported; false otherwiseprotected org.springframework.core.io.Resource readInternal(Class<? extends org.springframework.core.io.Resource> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException
AbstractHttpMessageConverterAbstractHttpMessageConverter.read(java.lang.Class<? extends T>, org.springframework.http.HttpInputMessage).readInternal in class AbstractHttpMessageConverter<org.springframework.core.io.Resource>clazz - the type of object to returninputMessage - the HTTP input message to read fromIOException - in case of I/O errorsHttpMessageNotReadableException - in case of conversion errorsprotected MediaType getDefaultContentType(org.springframework.core.io.Resource resource)
AbstractHttpMessageConverterAbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage)
is invoked without a specified content type parameter.
By default, this returns the first element of the
supportedMediaTypes property, if any.
Can be overridden in subclasses.
getDefaultContentType in class AbstractHttpMessageConverter<org.springframework.core.io.Resource>resource - the type to return the content type fornull if not knownprotected Long getContentLength(org.springframework.core.io.Resource resource, MediaType contentType) throws IOException
AbstractHttpMessageConverterBy default, this returns null, meaning that the content length is unknown.
Can be overridden in subclasses.
getContentLength in class AbstractHttpMessageConverter<org.springframework.core.io.Resource>resource - the type to return the content length fornull if not knownIOExceptionprotected void writeInternal(org.springframework.core.io.Resource resource,
HttpOutputMessage outputMessage)
throws IOException,
HttpMessageNotWritableException
AbstractHttpMessageConverterAbstractHttpMessageConverter.write(T, org.springframework.http.MediaType, org.springframework.http.HttpOutputMessage).writeInternal in class AbstractHttpMessageConverter<org.springframework.core.io.Resource>resource - the object to write to the output messageoutputMessage - the message to write toIOException - in case of I/O errorsHttpMessageNotWritableException - in case of conversion errors