Top Description Fields Constructors Methods
org.springframework.http.converter

public Class ByteArrayHttpMessageConverter

extends AbstractHttpMessageConverter<byte[]>
Class Inheritance
Imports
java.io.IOException, org.springframework.http.HttpInputMessage, .HttpOutputMessage, .MediaType, org.springframework.lang.Nullable, org.springframework.util.StreamUtils

Implementation of HttpMessageConverter that can read and write byte arrays.

By default, this converter supports all media types (*/*), and writes with a Content-Type of application/octet-stream. This can be overridden by setting the supportedMediaTypes property.

Authors
Arjen Poutsma, Juergen Hoeller
Since
3.0

Field Summary

Inherited from org.springframework.http.converter.AbstractHttpMessageConverter:
logger

Constructor Summary

AccessConstructor and Description
public
ByteArrayHttpMessageConverter()

Create a new instance of the ByteArrayHttpMessageConverter.

Method Summary

Modifier and TypeMethod and Description
protected Long
getContentLength(byte[]
the type to return the content length for
bytes
,
MediaType contentType)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.getContentLength.

Returns the content length for the given type.
public byte[]
readInternal(Class<? extends byte[]>
the type of object to return
clazz
,
HttpInputMessage
the HTTP input message to read from
message
)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.readInternal.

Abstract template method that reads the actual object.
public boolean
supports(Class<?>
the class to test for support
clazz
)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Indicates whether the given class is supported by this converter.
protected boolean
supportsRepeatableWrites(byte[]
the object t
bytes
)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.
protected void
writeInternal(byte[]
the object to write to the output message
bytes
,
HttpOutputMessage
the HTTP output message to write to
outputMessage
)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.writeInternal.

Abstract template method that writes the actual body.
Inherited from org.springframework.http.converter.AbstractHttpMessageConverter:
addDefaultHeaderscanReadcanReadcanWritecanWritegetDefaultCharsetgetDefaultContentTypegetSupportedMediaTypesreadsetDefaultCharsetsetSupportedMediaTypeswrite

Constructor Detail

ByteArrayHttpMessageConverterback to summary
public ByteArrayHttpMessageConverter()

Create a new instance of the ByteArrayHttpMessageConverter.

Method Detail

getContentLengthback to summary
protected Long getContentLength(byte[] bytes, MediaType contentType)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.getContentLength.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.getContentLength.

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
bytes:byte[]

the type to return the content length for

Returns:Long

the content length, or null if not known

Annotations
@Override
readInternalback to summary
public byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage message) throws IOException

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.readInternal.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.readInternal.

Abstract template method that reads the actual object. Invoked from read.

Parameters
clazz:Class<? extends byte[]>

the type of object to return

message:HttpInputMessage

the HTTP input message to read from

Returns:byte[]

the converted object

Annotations
@Override
Exceptions
IOException:
in case of I/O errors
supportsback to summary
public boolean supports(Class<?> clazz)

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.supports.

Indicates whether the given class is supported by this converter.

Parameters
clazz:Class<?>

the class to test for support

Returns:boolean

true if supported; false otherwise

Annotations
@Override
supportsRepeatableWritesback to summary
protected boolean supportsRepeatableWrites(byte[] bytes)

Overrides org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.supportsRepeatableWrites.

Indicates whether this message converter can write the given object multiple times.

Default implementation returns false.

Parameters
bytes:byte[]

the object t

Returns:boolean

true if t can be written repeatedly; false otherwise

Annotations
@Override
writeInternalback to summary
protected void writeInternal(byte[] bytes, HttpOutputMessage outputMessage) throws IOException

Implements abstract org.springframework.http.converter.AbstractHttpMessageConverter.writeInternal.

Doc from org.springframework.http.converter.AbstractHttpMessageConverter.writeInternal.

Abstract template method that writes the actual body. Invoked from write.

Parameters
bytes:byte[]

the object to write to the output message

outputMessage:HttpOutputMessage

the HTTP output message to write to

Annotations
@Override
Exceptions
IOException:
in case of I/O errors