public class MultipartHttpMessageWriter extends java.lang.Object implements HttpMessageWriter<MultiValueMap<java.lang.String,?>>
HttpMessageWriter
for "multipart/form-data"
requests.
This writer delegates to other message writers to write the respective
parts. By default basic writers are registered for String
, and
Resources
. These can be overridden through the provided constructors.
Modifier and Type | Class and Description |
---|---|
private static class |
MultipartHttpMessageWriter.MultipartHttpOutputMessage |
Modifier and Type | Field and Description |
---|---|
private DataBufferFactory |
bufferFactory |
private java.nio.charset.Charset |
charset |
static java.nio.charset.Charset |
DEFAULT_CHARSET |
private java.util.List<HttpMessageWriter<?>> |
partWriters |
Constructor and Description |
---|
MultipartHttpMessageWriter() |
MultipartHttpMessageWriter(java.util.List<HttpMessageWriter<?>> partWriters) |
Modifier and Type | Method and Description |
---|---|
boolean |
canWrite(ResolvableType elementType,
MediaType mediaType)
Whether the given object type is supported by this writer.
|
private <T> <any> |
encodePart(byte[] boundary,
java.lang.String name,
T value) |
private <any> |
encodePartValues(byte[] boundary,
java.lang.String name,
java.util.List<?> values) |
private DataBuffer |
generateBoundaryLine(byte[] boundary) |
private DataBuffer |
generateLastLine(byte[] boundary) |
protected byte[] |
generateMultipartBoundary()
Generate a multipart boundary.
|
private DataBuffer |
generateNewLine() |
java.nio.charset.Charset |
getCharset()
Return the configured charset for part headers.
|
java.util.List<MediaType> |
getWritableMediaTypes()
Return the
MediaType 's that this writer supports. |
void |
setCharset(java.nio.charset.Charset charset)
Set the character set to use for part headers such as
"Content-Disposition" (and its filename parameter).
|
<any> |
write(<any> inputStream,
ResolvableType elementType,
MediaType mediaType,
ReactiveHttpOutputMessage outputMessage,
java.util.Map<java.lang.String,java.lang.Object> hints)
Write an given stream of object to the output message.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
write
public static final java.nio.charset.Charset DEFAULT_CHARSET
private final DataBufferFactory bufferFactory
private final java.util.List<HttpMessageWriter<?>> partWriters
private java.nio.charset.Charset charset
public MultipartHttpMessageWriter()
public MultipartHttpMessageWriter(java.util.List<HttpMessageWriter<?>> partWriters)
public void setCharset(java.nio.charset.Charset charset)
By default this is set to "UTF-8".
public java.nio.charset.Charset getCharset()
public java.util.List<MediaType> getWritableMediaTypes()
HttpMessageWriter
MediaType
's that this writer supports.getWritableMediaTypes
in interface HttpMessageWriter<MultiValueMap<java.lang.String,?>>
public boolean canWrite(ResolvableType elementType, @Nullable MediaType mediaType)
HttpMessageWriter
canWrite
in interface HttpMessageWriter<MultiValueMap<java.lang.String,?>>
elementType
- the type of object to checkmediaType
- the media type for the write, possibly null
true
if writable, false
otherwisepublic <any> write(<any> inputStream, ResolvableType elementType, @Nullable MediaType mediaType, ReactiveHttpOutputMessage outputMessage, java.util.Map<java.lang.String,java.lang.Object> hints)
HttpMessageWriter
write
in interface HttpMessageWriter<MultiValueMap<java.lang.String,?>>
inputStream
- the objects to writeelementType
- the type of objects in the stream which must have been
previously checked via HttpMessageWriter.canWrite(ResolvableType, MediaType)
mediaType
- the content type for the write, possibly null
to
indicate that the default content type of the writer must be used.outputMessage
- the message to write tohints
- additional information about how to encode and writeprotected byte[] generateMultipartBoundary()
By default delegates to MimeTypeUtils.generateMultipartBoundary()
.
private <any> encodePartValues(byte[] boundary, java.lang.String name, java.util.List<?> values)
private <T> <any> encodePart(byte[] boundary, java.lang.String name, T value)
private DataBuffer generateBoundaryLine(byte[] boundary)
private DataBuffer generateNewLine()
private DataBuffer generateLastLine(byte[] boundary)