Class LineBasedFrameDecoder

All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
Direct Known Subclasses:
SmtpResponseDecoder

public class LineBasedFrameDecoder extends ByteToMessageDecoder
A decoder that splits the received ByteBufs on line endings.

Both "\n" and "\r\n" are handled.

The byte stream is expected to be in UTF-8 character encoding or ASCII. The current implementation uses direct byte to char cast and then compares that char to a few low range ASCII characters like '\n' or '\r'. UTF-8 is not using low range [0..0x7F] byte values for multibyte codepoint representations therefore fully supported by this implementation.

For a more general delimiter-based decoder, see DelimiterBasedFrameDecoder.

Users should be aware that used as is, the lenient approach on lone '\n might result on a parser diffenrencial on line based protocols requiring the use of "\r\n" delimiters like SMTP and can result in attacks similar to SMTP smuggling. Validating afterward the end of line pattern can be a possible mitigation.

  • Field Details

    • maxLength

      private final int maxLength
      Maximum length of a frame we're willing to decode.
    • failFast

      private final boolean failFast
      Whether or not to throw an exception as soon as we exceed maxLength.
    • stripDelimiter

      private final boolean stripDelimiter
    • discarding

      private boolean discarding
      True if we're discarding input because we're already over maxLength.
    • discardedBytes

      private int discardedBytes
    • offset

      private int offset
      Last scan position.
  • Constructor Details

    • LineBasedFrameDecoder

      public LineBasedFrameDecoder(int maxLength)
      Creates a new decoder.
      Parameters:
      maxLength - the maximum length of the decoded frame. A TooLongFrameException is thrown if the length of the frame exceeds this value.
    • LineBasedFrameDecoder

      public LineBasedFrameDecoder(int maxLength, boolean stripDelimiter, boolean failFast)
      Creates a new decoder.
      Parameters:
      maxLength - the maximum length of the decoded frame. A TooLongFrameException is thrown if the length of the frame exceeds this value.
      stripDelimiter - whether the decoded frame should strip out the delimiter or not
      failFast - If true, a TooLongFrameException is thrown as soon as the decoder notices the length of the frame will exceed maxFrameLength regardless of whether the entire frame has been read. If false, a TooLongFrameException is thrown after the entire frame that exceeds maxFrameLength has been read.
  • Method Details