Package org.springframework.core.codec

# Class CharBufferDecoder

java.lang.Object
org.springframework.core.codec.AbstractDecoder<T>
org.springframework.core.codec.AbstractDataBufferDecoder<T>
org.springframework.core.codec.AbstractCharSequenceDecoder<CharBuffer>
org.springframework.core.codec.CharBufferDecoder

All Implemented Interfaces:
  `Decoder<CharBuffer>`

public final class CharBufferDecoder extends AbstractCharSequenceDecoder<CharBuffer>
Decode from a data buffer stream to a `CharBuffer` stream, either splitting or aggregating incoming data chunks to realign along newlines delimiters and produce a stream of char buffers. This is useful for streaming but is also necessary to ensure that multi-byte 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.

Since:
  6.1
Author:
  Markus Heiden, Arjen Poutsma
See Also:
  - `CharSequenceEncoder`

## Field Summary

### Fields inherited from class org.springframework.core.codec.AbstractCharSequenceDecoder

`DEFAULT_CHARSET, DEFAULT_DELIMITERS`

### Fields inherited from class org.springframework.core.codec.AbstractDecoder

`logger`

## Constructor Summary

Constructors
Constructor
Description
`CharBufferDecoder(List<String> delimiters, boolean stripDelimiter, MimeType... mimeTypes)`

## Method Summary

Modifier and Type
Method
Description
`static CharBufferDecoder`
`allMimeTypes()`
Create a `CharBufferDecoder` that supports all MIME types.
`static CharBufferDecoder`
`allMimeTypes(List<String> delimiters, boolean stripDelimiter)`
Create a `CharBufferDecoder` 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.
`protected CharBuffer`
`decodeInternal(DataBuffer dataBuffer, Charset charset)`
Template method that decodes the given data buffer into `T`, given the charset.
`static CharBufferDecoder`
`textPlainOnly()`
Create a `CharBufferDecoder` for `"text/plain"`.
`static CharBufferDecoder`
`textPlainOnly(List<String> delimiters, boolean stripDelimiter)`
Create a `CharBufferDecoder` for `"text/plain"`.

### Methods inherited from class org.springframework.core.codec.AbstractCharSequenceDecoder

`decode, decode, getDefaultCharset, setDefaultCharset`

### 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`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.springframework.core.codec.Decoder

`getDecodableMimeTypes`

## Constructor Details

### CharBufferDecoder

public CharBufferDecoder(List<String> delimiters, boolean stripDelimiter, MimeType... mimeTypes)

## Method Details

### canDecode

public boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType)
Description copied from interface: `Decoder`
Whether the decoder supports the given target element type and the MIME type of the source stream.

Specified by:
  `canDecode` in interface `Decoder<CharBuffer>`
Overrides:
  `canDecode` in class `AbstractDecoder<CharBuffer>`
Parameters:
  `elementType` - the target element type for the output stream
  `mimeType` - the mime type associated with the stream to decode (can be `null` if not specified)
Returns:
  `true` if supported, `false` otherwise

### decodeInternal

protected CharBuffer decodeInternal(DataBuffer dataBuffer, Charset charset)
Description copied from class: `AbstractCharSequenceDecoder`
Template method that decodes the given data buffer into `T`, given the charset.

Specified by:
  `decodeInternal` in class `AbstractCharSequenceDecoder<CharBuffer>`

### textPlainOnly

public static CharBufferDecoder textPlainOnly()
Create a `CharBufferDecoder` for `"text/plain"`.

### textPlainOnly

public static CharBufferDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter)
Create a `CharBufferDecoder` for `"text/plain"`.

Parameters:
  `delimiters` - delimiter strings to use to split the input stream
  `stripDelimiter` - whether to remove delimiters from the resulting input strings

### allMimeTypes

public static CharBufferDecoder allMimeTypes()
Create a `CharBufferDecoder` that supports all MIME types.

### allMimeTypes

public static CharBufferDecoder allMimeTypes(List<String> delimiters, boolean stripDelimiter)
Create a `CharBufferDecoder` that 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