public class LineBasedFrameDecoder extends FrameDecoder
ChannelBuffers on line endings.
Both "\n" and "\r\n" are handled.
For a more general delimiter-based decoder, see DelimiterBasedFrameDecoder.
ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private int |
discardedBytes |
private boolean |
discarding
True if we're discarding input because we're already over maxLength.
|
private boolean |
failFast
Whether or not to throw an exception as soon as we exceed maxLength.
|
private int |
maxLength
Maximum length of a frame we're willing to decode.
|
private boolean |
stripDelimiter |
cumulation, DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS| Constructor and Description |
|---|
LineBasedFrameDecoder(int maxLength)
Creates a new decoder.
|
LineBasedFrameDecoder(int maxLength,
boolean stripDelimiter,
boolean failFast)
Creates a new decoder.
|
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Object |
decode(ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buffer)
Decodes the received packets so far into a frame.
|
private void |
fail(ChannelHandlerContext ctx,
int length) |
private void |
fail(ChannelHandlerContext ctx,
java.lang.String length) |
private static int |
findEndOfLine(ChannelBuffer buffer)
Returns the index in the buffer of the end of line found.
|
actualReadableBytes, afterAdd, afterRemove, appendToCumulation, beforeAdd, beforeRemove, channelClosed, channelDisconnected, cleanup, decodeLast, exceptionCaught, extractFrame, getMaxCumulationBufferCapacity, getMaxCumulationBufferComponents, internalBuffer, isUnfold, messageReceived, newCumulationBuffer, replace, setMaxCumulationBufferCapacity, setMaxCumulationBufferComponents, setUnfold, unfoldAndFireMessageReceived, updateCumulationchannelBound, channelConnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, handleUpstream, writeCompleteprivate final int maxLength
private final boolean failFast
private final boolean stripDelimiter
private boolean discarding
private int discardedBytes
public LineBasedFrameDecoder(int maxLength)
maxLength - the maximum length of the decoded frame.
A TooLongFrameException is thrown if
the length of the frame exceeds this value.public LineBasedFrameDecoder(int maxLength,
boolean stripDelimiter,
boolean failFast)
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 notfailFast - 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.protected java.lang.Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws java.lang.Exception
FrameDecoderFrameDecoder.extractFrame(ChannelBuffer, int, int) method,
to make optimizations easier later.decode in class FrameDecoderctx - the context of this handlerchannel - the current channelbuffer - the cumulative buffer of received packets so far.
Note that the buffer might be empty, which means you
should not make an assumption that the buffer contains
at least one byte in your decoder implementation.null if there's not enough data in the buffer to decode a frame.java.lang.Exceptionprivate void fail(ChannelHandlerContext ctx, int length)
private void fail(ChannelHandlerContext ctx, java.lang.String length)
private static int findEndOfLine(ChannelBuffer buffer)