public final class StringDecoder extends AbstractDataBufferDecoder<String>
String stream, either splitting
or aggregating incoming data chunks to realign along newlines delimiters
and produce a stream of strings. This is useful for streaming but is also
necessary to ensure that that multibyte characters can be decoded correctly,
avoiding split-character issues. The default delimiters used by default are
\n and \r\n but that can be customized.CharSequenceEncoder| Modifier and Type | Field and Description |
|---|---|
static Charset |
DEFAULT_CHARSET
The default charset to use, i.e.
|
static List<String> |
DEFAULT_DELIMITERS
The default delimiter strings to use, i.e.
|
logger| Modifier and Type | Method and Description |
|---|---|
static StringDecoder |
allMimeTypes()
Create a
StringDecoder that supports all MIME types. |
static StringDecoder |
allMimeTypes(boolean stripDelimiter)
Deprecated.
as of Spring 5.0.4, in favor of
allMimeTypes() or
allMimeTypes(List, boolean) |
static StringDecoder |
allMimeTypes(List<String> delimiters,
boolean stripDelimiter)
Create a
StringDecoder that supports all MIME types. |
boolean |
canDecode(ResolvableType elementType,
MimeType mimeType)
Whether the decoder supports the given target element type and the MIME
type of the source stream.
|
String |
decode(DataBuffer dataBuffer,
ResolvableType elementType,
MimeType mimeType,
Map<String,Object> hints)
Decode a data buffer to an Object of type T.
|
reactor.core.publisher.Flux<String> |
decode(Publisher<DataBuffer> input,
ResolvableType elementType,
MimeType mimeType,
Map<String,Object> hints)
Decode a
DataBuffer input stream into a Flux of T. |
Charset |
getDefaultCharset()
Return the configured
defaultCharset. |
void |
setDefaultCharset(Charset defaultCharset)
Set the default character set to fall back on if the MimeType does not specify any.
|
static StringDecoder |
textPlainOnly()
Create a
StringDecoder for "text/plain". |
static StringDecoder |
textPlainOnly(boolean stripDelimiter)
Deprecated.
as of Spring 5.0.4, in favor of
textPlainOnly() or
textPlainOnly(List, boolean) |
static StringDecoder |
textPlainOnly(List<String> delimiters,
boolean stripDelimiter)
Create a
StringDecoder for "text/plain". |
decodeDataBuffer, decodeToMono, getMaxInMemorySize, setMaxInMemorySizegetDecodableMimeTypes, getLogger, setLoggerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetDecodableMimeTypespublic static final Charset DEFAULT_CHARSET
public void setDefaultCharset(Charset defaultCharset)
By default this is UTF-8.
defaultCharset - the charset to fall back onpublic Charset getDefaultCharset()
defaultCharset.public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType)
DecodercanDecode in interface Decoder<String>canDecode in class AbstractDecoder<String>elementType - the target element type for the output streammimeType - the mime type associated with the stream to decode
(can be null if not specified)true if supported, false otherwisepublic reactor.core.publisher.Flux<String> decode(Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
DecoderDataBuffer input stream into a Flux of T.decode in interface Decoder<String>decode in class AbstractDataBufferDecoder<String>input - the DataBuffer input stream to decodeelementType - the expected type of elements in the output stream;
this type must have been previously passed to the Decoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)
method and it must have returned true.mimeType - the MIME type associated with the input stream (optional)hints - additional information about how to do decodepublic String decode(DataBuffer dataBuffer, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
DecoderdataBuffer - the DataBuffer to decodeelementType - the expected output typemimeType - the MIME type associated with the datahints - additional information about how to do decodenull@Deprecated public static StringDecoder textPlainOnly(boolean stripDelimiter)
textPlainOnly() or
textPlainOnly(List, boolean)StringDecoder for "text/plain".stripDelimiter - this flag is ignoredpublic static StringDecoder textPlainOnly()
StringDecoder for "text/plain".public static StringDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter)
StringDecoder for "text/plain".delimiters - delimiter strings to use to split the input streamstripDelimiter - whether to remove delimiters from the resulting
input strings@Deprecated public static StringDecoder allMimeTypes(boolean stripDelimiter)
allMimeTypes() or
allMimeTypes(List, boolean)StringDecoder that supports all MIME types.stripDelimiter - this flag is ignoredpublic static StringDecoder allMimeTypes()
StringDecoder that supports all MIME types.public static StringDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter)
StringDecoder that supports all MIME types.delimiters - delimiter strings to use to split the input streamstripDelimiter - whether to remove delimiters from the resulting
input strings