Class StringDecoder

All Implemented Interfaces:
Decoder<String>

public final class StringDecoder extends AbstractCharSequenceDecoder<String>
Decode from a data buffer stream to a 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 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:
5.0
Author:
Sebastien Deleuze, Brian Clozel, Arjen Poutsma, Mark Paluch
See Also:
  • 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<String>
      Overrides:
      canDecode in 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 null if not specified)
      Returns:
      true if supported, false otherwise
    • decodeInternal

      protected String 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<String>
    • textPlainOnly

      public static StringDecoder textPlainOnly()
      Create a StringDecoder for "text/plain".
    • textPlainOnly

      public static StringDecoder textPlainOnly(List<String> delimiters, boolean stripDelimiter)
      Create a StringDecoder 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 StringDecoder allMimeTypes()
      Create a StringDecoder that supports all MIME types.
    • allMimeTypes

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