diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java index b55b3598b91..9016da269df 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java +++ b/org.springframework.web/src/main/java/org/springframework/http/converter/AbstractHttpMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,8 +88,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv /** - * {@inheritDoc} - *

This implementation checks if the given class is {@linkplain #supports(Class) supported}, + * This implementation checks if the given class is {@linkplain #supports(Class) supported}, * and if the {@linkplain #getSupportedMediaTypes() supported media types} * {@linkplain MediaType#includes(MediaType) include} the given media type. */ @@ -100,9 +99,10 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv /** * Returns true if any of the {@linkplain #setSupportedMediaTypes(List) supported media types} * include the given media type. - * @param mediaType the media type to read, can be {@code null} if not specified. Typically the value of a - * {@code Content-Type} header. - * @return true if the supported media types include the media type, or if the media type is {@code null} + * @param mediaType the media type to read, can be {@code null} if not specified. + * Typically the value of a {@code Content-Type} header. + * @return {@code true} if the supported media types include the media type, + * or if the media type is {@code null} */ protected boolean canRead(MediaType mediaType) { if (mediaType == null) { @@ -117,8 +117,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv } /** - * {@inheritDoc} - *

This implementation checks if the given class is {@linkplain #supports(Class) supported}, + * This implementation checks if the given class is {@linkplain #supports(Class) supported}, * and if the {@linkplain #getSupportedMediaTypes() supported media types} * {@linkplain MediaType#includes(MediaType) include} the given media type. */ @@ -127,11 +126,12 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv } /** - * Returns true if the given media type includes any of the + * Returns {@code true} if the given media type includes any of the * {@linkplain #setSupportedMediaTypes(List) supported media types}. - * @param mediaType the media type to write, can be {@code null} if not specified. Typically the value of an - * {@code Accept} header. - * @return true if the supported media types are compatible with the media type, or if the media type is {@code null} + * @param mediaType the media type to write, can be {@code null} if not specified. + * Typically the value of an {@code Accept} header. + * @return {@code true} if the supported media types are compatible with the media type, + * or if the media type is {@code null} */ protected boolean canWrite(MediaType mediaType) { if (mediaType == null || MediaType.ALL.equals(mediaType)) { @@ -146,8 +146,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv } /** - * {@inheritDoc} - *

This implementation simple delegates to {@link #readInternal(Class, HttpInputMessage)}. + * This implementation simple delegates to {@link #readInternal(Class, HttpInputMessage)}. * Future implementations might add some default behavior, however. */ public final T read(Class clazz, HttpInputMessage inputMessage) throws IOException { @@ -155,8 +154,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv } /** - * {@inheritDoc} - *

This implementation delegates to {@link #getDefaultContentType(Object)} if a content + * This implementation delegates to {@link #getDefaultContentType(Object)} if a content * type was not provided, calls {@link #getContentLength}, and sets the corresponding headers * on the output message. It then calls {@link #writeInternal}. */ @@ -191,7 +189,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv * @param t the type to return the content type for * @return the content type, or null if not known */ - protected MediaType getDefaultContentType(T t) { + protected MediaType getDefaultContentType(T t) throws IOException { List mediaTypes = getSupportedMediaTypes(); return (!mediaTypes.isEmpty() ? mediaTypes.get(0) : null); } @@ -203,7 +201,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv * @param t the type to return the content length for * @return the content length, or {@code null} if not known */ - protected Long getContentLength(T t, MediaType contentType) { + protected Long getContentLength(T t, MediaType contentType) throws IOException { return null; } diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java index 978b9f32e9d..9991fbcc804 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java +++ b/org.springframework.web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java @@ -34,9 +34,9 @@ import org.springframework.util.StringUtils; /** * Implementation of {@link HttpMessageConverter} that can read and write {@link Resource Resources}. * - *

By default, this converter can read all media types. The Java Activation Framework (JAF) - if available - is used - * to determine the {@code Content-Type} of written resources. If JAF is not available, {@code application/octet-stream} - * is used. + *

By default, this converter can read all media types. The Java Activation Framework (JAF) - + * if available - is used to determine the {@code Content-Type} of written resources. + * If JAF is not available, {@code application/octet-stream} is used. * * @author Arjen Poutsma * @since 3.0.2 @@ -46,9 +46,12 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter clazz) { return Resource.class.isAssignableFrom(clazz); @@ -57,6 +60,7 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { + byte[] body = FileCopyUtils.copyToByteArray(inputMessage.getBody()); return new ByteArrayResource(body); } @@ -72,22 +76,19 @@ public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter