public class StringDecoder extends AbstractDecoder<java.lang.String>
String
stream.
By default, this decoder will split the received DataBuffer
s
along newline characters (\r\n
), but this can be changed by
passing false
as a constructor argument.
CharSequenceEncoder
Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
DEFAULT_CHARSET |
private static java.util.function.IntPredicate |
NEWLINE_DELIMITER |
private boolean |
splitOnNewline |
Constructor and Description |
---|
StringDecoder()
Create a
StringDecoder that decodes a bytes stream to a String stream |
StringDecoder(boolean splitOnNewline)
Create a
StringDecoder that decodes a bytes stream to a String stream |
Modifier and Type | Method and Description |
---|---|
boolean |
canDecode(ResolvableType elementType,
MimeType mimeType)
Whether the decoder supports the given target element type and the MIME
type of the source stream.
|
<any> |
decode(<any> inputStream,
ResolvableType elementType,
MimeType mimeType,
java.util.Map<java.lang.String,java.lang.Object> hints)
Decode a
DataBuffer input stream into a Flux of T . |
private java.lang.String |
decodeDataBuffer(DataBuffer dataBuffer,
MimeType mimeType) |
<any> |
decodeToMono(<any> inputStream,
ResolvableType elementType,
MimeType mimeType,
java.util.Map<java.lang.String,java.lang.Object> hints)
Decode a
DataBuffer input stream into a Mono of T . |
private java.nio.charset.Charset |
getCharset(MimeType mimeType) |
private static <any> |
splitOnNewline(DataBuffer dataBuffer) |
getDecodableMimeTypes
public static final java.nio.charset.Charset DEFAULT_CHARSET
private static final java.util.function.IntPredicate NEWLINE_DELIMITER
private final boolean splitOnNewline
public StringDecoder()
StringDecoder
that decodes a bytes stream to a String stream
By default, this decoder will split along new lines.
public StringDecoder(boolean splitOnNewline)
StringDecoder
that decodes a bytes stream to a String streamsplitOnNewline
- whether this decoder should split the received data buffers
along newline characterspublic boolean canDecode(ResolvableType elementType, MimeType mimeType)
Decoder
canDecode
in interface Decoder<java.lang.String>
canDecode
in class AbstractDecoder<java.lang.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 <any> decode(<any> inputStream, ResolvableType elementType, MimeType mimeType, java.util.Map<java.lang.String,java.lang.Object> hints)
Decoder
DataBuffer
input stream into a Flux of T
.inputStream
- 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, optionalhints
- additional information about how to do encodepublic <any> decodeToMono(<any> inputStream, ResolvableType elementType, MimeType mimeType, java.util.Map<java.lang.String,java.lang.Object> hints)
Decoder
DataBuffer
input stream into a Mono of T
.decodeToMono
in interface Decoder<java.lang.String>
decodeToMono
in class AbstractDecoder<java.lang.String>
inputStream
- 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, optionalhints
- additional information about how to do encodeprivate static <any> splitOnNewline(DataBuffer dataBuffer)
private java.lang.String decodeDataBuffer(DataBuffer dataBuffer, MimeType mimeType)
private java.nio.charset.Charset getCharset(MimeType mimeType)