org.springframework.http.converter
Class ResourceHttpMessageConverter

java.lang.Object
  extended by org.springframework.http.converter.ResourceHttpMessageConverter
All Implemented Interfaces:
HttpMessageConverter<Resource>

public class ResourceHttpMessageConverter
extends java.lang.Object
implements HttpMessageConverter<Resource>

Implementation of 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.

Since:
3.0.2

Constructor Summary
ResourceHttpMessageConverter()
           
 
Method Summary
 boolean canRead(java.lang.Class<?> clazz, MediaType mediaType)
           
 boolean canWrite(java.lang.Class<?> clazz, MediaType mediaType)
           
protected  java.lang.Long getContentLength(Resource resource, MediaType contentType)
           
 java.util.List<MediaType> getSupportedMediaTypes()
           
 Resource read(java.lang.Class<? extends Resource> clazz, HttpInputMessage inputMessage)
           
 void write(Resource resource, MediaType contentType, HttpOutputMessage outputMessage)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceHttpMessageConverter

public ResourceHttpMessageConverter()
Method Detail

canRead

public boolean canRead(java.lang.Class<?> clazz,
                       MediaType mediaType)
Specified by:
canRead in interface HttpMessageConverter<Resource>

canWrite

public boolean canWrite(java.lang.Class<?> clazz,
                        MediaType mediaType)
Specified by:
canWrite in interface HttpMessageConverter<Resource>

getSupportedMediaTypes

public java.util.List<MediaType> getSupportedMediaTypes()
Specified by:
getSupportedMediaTypes in interface HttpMessageConverter<Resource>

read

public Resource read(java.lang.Class<? extends Resource> clazz,
                     HttpInputMessage inputMessage)
              throws java.io.IOException,
                     HttpMessageNotReadableException
Specified by:
read in interface HttpMessageConverter<Resource>
Throws:
java.io.IOException
HttpMessageNotReadableException

write

public void write(Resource resource,
                  MediaType contentType,
                  HttpOutputMessage outputMessage)
           throws java.io.IOException,
                  HttpMessageNotWritableException
Specified by:
write in interface HttpMessageConverter<Resource>
Throws:
java.io.IOException
HttpMessageNotWritableException

getContentLength

protected java.lang.Long getContentLength(Resource resource,
                                          MediaType contentType)
                                   throws java.io.IOException
Throws:
java.io.IOException