Package org.springframework.core.codec
Class StringDecoder
- java.lang.Object
- org.springframework.core.codec.AbstractDecoder<T>
- org.springframework.core.codec.AbstractDataBufferDecoder<String>
- org.springframework.core.codec.StringDecoder
 
 
 
- public final class StringDecoder extends AbstractDataBufferDecoder<String> Decode from a data buffer stream to a- Stringstream, 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- \nand- \r\nbut that can be customized.- Since:
- 5.0
- Author:
- Sebastien Deleuze, Brian Clozel, Arjen Poutsma, Mark Paluch
- See Also:
- CharSequenceEncoder
 
- Field Summary- Fields - Modifier and Type - Field - Description - static Charset- DEFAULT_CHARSETThe default charset to use, i.e.- static List<String>- DEFAULT_DELIMITERSThe default delimiter strings to use, i.e.- Fields inherited from class org.springframework.core.codec.AbstractDecoder- logger
 
 - Method Summary- All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods - Modifier and Type - Method - Description - static StringDecoder- allMimeTypes()Create a- StringDecoderthat 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- StringDecoderthat 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.- reactor.core.publisher.Flux<String>- decode(org.reactivestreams.Publisher<DataBuffer> input, ResolvableType elementType, MimeType mimeType, Map<String,Object> hints)Decode a- DataBufferinput stream into a Flux of- T.- String- decode(DataBuffer dataBuffer, ResolvableType elementType, MimeType mimeType, Map<String,Object> hints)Decode a data buffer to an Object of type 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- StringDecoderfor- "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- StringDecoderfor- "text/plain".- Methods inherited from class org.springframework.core.codec.AbstractDataBufferDecoder- decodeDataBuffer, decodeToMono, getMaxInMemorySize, setMaxInMemorySize
 - Methods inherited from class org.springframework.core.codec.AbstractDecoder- getDecodableMimeTypes, getLogger, setLogger
 
 
- Field Detail- DEFAULT_CHARSET- public static final Charset DEFAULT_CHARSET The default charset to use, i.e. "UTF-8".
 - DEFAULT_DELIMITERS- public static final List<String> DEFAULT_DELIMITERS The default delimiter strings to use, i.e.- \r\nand- \n.
 
 - Method Detail- setDefaultCharset- public void setDefaultCharset(Charset defaultCharset) Set the default character set to fall back on if the MimeType does not specify any.- By default this is - UTF-8.- Parameters:
- defaultCharset- the charset to fall back on
- Since:
- 5.2.9
 
 - getDefaultCharset- public Charset getDefaultCharset() Return the configured- defaultCharset.- Since:
- 5.2.9
 
 - canDecode- public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType) Description copied from interface:- DecoderWhether the decoder supports the given target element type and the MIME type of the source stream.- Specified by:
- canDecodein interface- Decoder<String>
- Overrides:
- canDecodein class- AbstractDecoder<String>
- Parameters:
- elementType- the target element type for the output stream
- mimeType- the mime type associated with the stream to decode (can be- nullif not specified)
- Returns:
- trueif supported,- falseotherwise
 
 - decode- public reactor.core.publisher.Flux<String> decode(org.reactivestreams.Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints) Description copied from interface:- DecoderDecode a- DataBufferinput stream into a Flux of- T.- Specified by:
- decodein interface- Decoder<String>
- Overrides:
- decodein class- AbstractDataBufferDecoder<String>
- Parameters:
- input- the- DataBufferinput stream to decode
- elementType- 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 encode
- Returns:
- the output stream with decoded elements
 
 - decode- public String decode(DataBuffer dataBuffer, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints) Description copied from interface:- DecoderDecode a data buffer to an Object of type T. This is useful for scenarios, that distinct messages (or events) are decoded and handled individually, in fully aggregated form.- Parameters:
- dataBuffer- the- DataBufferto decode
- elementType- the expected output type
- mimeType- the MIME type associated with the data
- hints- additional information about how to do encode
- Returns:
- the decoded value, possibly null
 
 - textPlainOnly- @Deprecated public static StringDecoder textPlainOnly(boolean stripDelimiter) Deprecated.as of Spring 5.0.4, in favor of- textPlainOnly()or- textPlainOnly(List, boolean)Create a- StringDecoderfor- "text/plain".- Parameters:
- stripDelimiter- this flag is ignored
 
 - textPlainOnly- public static StringDecoder textPlainOnly() Create a- StringDecoderfor- "text/plain".
 - textPlainOnly- public static StringDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter) Create a- StringDecoderfor- "text/plain".- Parameters:
- delimiters- delimiter strings to use to split the input stream
- stripDelimiter- whether to remove delimiters from the resulting input strings
 
 - allMimeTypes- @Deprecated public static StringDecoder allMimeTypes(boolean stripDelimiter) Deprecated.as of Spring 5.0.4, in favor of- allMimeTypes()or- allMimeTypes(List, boolean)Create a- StringDecoderthat supports all MIME types.- Parameters:
- stripDelimiter- this flag is ignored
 
 - allMimeTypes- public static StringDecoder allMimeTypes() Create a- StringDecoderthat supports all MIME types.
 - allMimeTypes- public static StringDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter) Create a- StringDecoderthat supports all MIME types.- Parameters:
- delimiters- delimiter strings to use to split the input stream
- stripDelimiter- whether to remove delimiters from the resulting input strings