类 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 aString
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.- 从以下版本开始:
- 5.0
- 作者:
- Sebastien Deleuze, Brian Clozel, Arjen Poutsma, Mark Paluch
- 另请参阅:
CharSequenceEncoder
字段概要
字段 修饰符和类型 字段 说明 static Charset
DEFAULT_CHARSET
The default charset to use, i.e.static List<String>
DEFAULT_DELIMITERS
The default delimiter strings to use, i.e.从类继承的字段 org.springframework.core.codec.AbstractDecoder
logger
方法概要
所有方法 静态方法 实例方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static StringDecoder
allMimeTypes()
Create aStringDecoder
that supports all MIME types.static StringDecoder
allMimeTypes(boolean stripDelimiter)
已过时。as of Spring 5.0.4, in favor ofallMimeTypes()
orallMimeTypes(List, boolean)
static StringDecoder
allMimeTypes(List<String> delimiters, boolean stripDelimiter)
Create aStringDecoder
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.reactor.core.publisher.Flux<String>
decode(org.reactivestreams.Publisher<DataBuffer> input, ResolvableType elementType, MimeType mimeType, Map<String,Object> hints)
Decode aDataBuffer
input stream into a Flux ofT
.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 configureddefaultCharset
.void
setDefaultCharset(Charset defaultCharset)
Set the default character set to fall back on if the MimeType does not specify any.static StringDecoder
textPlainOnly()
Create aStringDecoder
for"text/plain"
.static StringDecoder
textPlainOnly(boolean stripDelimiter)
已过时。as of Spring 5.0.4, in favor oftextPlainOnly()
ortextPlainOnly(List, boolean)
static StringDecoder
textPlainOnly(List<String> delimiters, boolean stripDelimiter)
Create aStringDecoder
for"text/plain"
.从类继承的方法 org.springframework.core.codec.AbstractDataBufferDecoder
decodeDataBuffer, decodeToMono, getMaxInMemorySize, setMaxInMemorySize
从类继承的方法 org.springframework.core.codec.AbstractDecoder
getDecodableMimeTypes, getLogger, setLogger
字段详细资料
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\n
and\n
.
方法详细资料
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
.- 参数:
defaultCharset
- the charset to fall back on- 从以下版本开始:
- 5.2.9
getDefaultCharset
public Charset getDefaultCharset()
Return the configureddefaultCharset
.- 从以下版本开始:
- 5.2.9
canDecode
public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType)
从接口复制的说明:Decoder
Whether the decoder supports the given target element type and the MIME type of the source stream.
decode
public reactor.core.publisher.Flux<String> decode(org.reactivestreams.Publisher<DataBuffer> input, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
从接口复制的说明:Decoder
Decode aDataBuffer
input stream into a Flux ofT
.- 指定者:
decode
在接口中Decoder<String>
- 覆盖:
decode
在类中AbstractDataBufferDecoder<String>
- 参数:
input
- theDataBuffer
input stream to decodeelementType
- the expected type of elements in the output stream; this type must have been previously passed to theDecoder.canDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)
method and it must have returnedtrue
.mimeType
- the MIME type associated with the input stream (optional)hints
- additional information about how to do encode- 返回:
- the output stream with decoded elements
decode
public String decode(DataBuffer dataBuffer, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
从接口复制的说明:Decoder
Decode 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.- 参数:
dataBuffer
- theDataBuffer
to decodeelementType
- the expected output typemimeType
- the MIME type associated with the datahints
- additional information about how to do encode- 返回:
- the decoded value, possibly
null
textPlainOnly
@Deprecated public static StringDecoder textPlainOnly(boolean stripDelimiter)
已过时。as of Spring 5.0.4, in favor oftextPlainOnly()
ortextPlainOnly(List, boolean)
Create aStringDecoder
for"text/plain"
.- 参数:
stripDelimiter
- this flag is ignored
textPlainOnly
public static StringDecoder textPlainOnly()
Create aStringDecoder
for"text/plain"
.
textPlainOnly
public static StringDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter)
Create aStringDecoder
for"text/plain"
.- 参数:
delimiters
- delimiter strings to use to split the input streamstripDelimiter
- whether to remove delimiters from the resulting input strings
allMimeTypes
@Deprecated public static StringDecoder allMimeTypes(boolean stripDelimiter)
已过时。as of Spring 5.0.4, in favor ofallMimeTypes()
orallMimeTypes(List, boolean)
Create aStringDecoder
that supports all MIME types.- 参数:
stripDelimiter
- this flag is ignored
allMimeTypes
public static StringDecoder allMimeTypes()
Create aStringDecoder
that supports all MIME types.
allMimeTypes
public static StringDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter)
Create aStringDecoder
that supports all MIME types.- 参数:
delimiters
- delimiter strings to use to split the input streamstripDelimiter
- whether to remove delimiters from the resulting input strings