public class

ResourceHttpMessageConverter

extends AbstractHttpMessageConverter<T>
java.lang.Object
   ↳ org.springframework.http.converter.AbstractHttpMessageConverter<T>
     ↳ org.springframework.http.converter.ResourceHttpMessageConverter

Class Overview

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.

Summary

[Expand]
Inherited Fields
From class org.springframework.http.converter.AbstractHttpMessageConverter
Public Constructors
ResourceHttpMessageConverter()
Protected Methods
Long getContentLength(Resource resource, MediaType contentType)
Returns the content length for the given type.
MediaType getDefaultContentType(Resource resource)
Returns the default content type for the given type.
Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
Abstract template method that reads the actualy object.
boolean supports(Class<?> clazz)
Indicates whether the given class is supported by this converter.
void writeInternal(Resource resource, HttpOutputMessage outputMessage)
Abstract template method that writes the actual body.
[Expand]
Inherited Methods
From class org.springframework.http.converter.AbstractHttpMessageConverter
From class java.lang.Object
From interface org.springframework.http.converter.HttpMessageConverter

Public Constructors

public ResourceHttpMessageConverter ()

Protected Methods

protected Long getContentLength (Resource resource, MediaType contentType)

Returns the content length for the given type.

By default, this returns null, meaning that the content length is unknown. Can be overridden in subclasses.

Parameters
resource the type to return the content length for
Returns
  • the content length, or null if not known

protected MediaType getDefaultContentType (Resource resource)

Returns the default content type for the given type. Called when write(T, MediaType, 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.

Parameters
resource the type to return the content type for
Returns
  • the content type, or null if not known

protected Resource readInternal (Class<? extends Resource> clazz, HttpInputMessage inputMessage)

Abstract template method that reads the actualy object. Invoked from read(Class, HttpInputMessage).

Parameters
clazz the type of object to return
inputMessage the HTTP input message to read from
Returns
  • the converted object

protected boolean supports (Class<?> clazz)

Indicates whether the given class is supported by this converter.

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

protected void writeInternal (Resource resource, HttpOutputMessage outputMessage)

Abstract template method that writes the actual body. Invoked from write(T, MediaType, HttpOutputMessage).

Parameters
resource the object to write to the output message
outputMessage the message to write to