public class DelimiterBasedFrameDecoder extends ByteToMessageDecoder
ByteBuf的解码器。
对于以NUL或newline characters等分隔符结尾的帧进行解码特别有用。
为了方便起见, Delimiters定义了常用的分隔符。
DelimiterBasedFrameDecoder允许您指定多个分隔符。 如果在缓冲区中找到多个分隔符,它会选择产生最短帧的分隔符。 例如,如果您在缓冲区中有以下数据:
+--------------+
| ABC\nDEF\r\n |
+--------------+
一个DelimiterBasedFrameDecoder ( Delimiters.lineDelimiter() )会选择'\n'作为第一个分隔符并产生两个帧:
+-----+-----+
| ABC | DEF |
+-----+-----+
而不是错误地选择'\r\n'作为第一个分隔符:
+----------+
| ABC\nDEF |
+----------+
ByteToMessageDecoder.CumulatorChannelHandler.SharableCOMPOSITE_CUMULATOR, MERGE_CUMULATOR| Constructor and Description |
|---|
DelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, boolean failFast, ByteBuf... delimiters)
创建一个新的实例。
|
DelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, boolean failFast, ByteBuf delimiter)
创建一个新的实例。
|
DelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, ByteBuf... delimiters)
创建一个新的实例。
|
DelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, ByteBuf delimiter)
创建一个新的实例。
|
DelimiterBasedFrameDecoder(int maxFrameLength, ByteBuf... delimiters)
创建一个新的实例。
|
DelimiterBasedFrameDecoder(int maxFrameLength, ByteBuf delimiter)
创建一个新的实例。
|
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.Object |
decode(ChannelHandlerContext ctx, ByteBuf buffer)
从 ByteBuf中创建一个框架并将其返回。
|
protected void |
decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out)
解码从一个 ByteBuf到另一个。
|
actualReadableBytes, callDecode, channelInactive, channelRead, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, isSingleDecode, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggeredchannelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaughtensureNotSharable, handlerAdded, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerAddedpublic DelimiterBasedFrameDecoder(int maxFrameLength,
ByteBuf delimiter)
maxFrameLength - 解码帧的最大长度。
如果帧的长度超过此值,则会引发TooLongFrameException 。
delimiter - 分隔符
public DelimiterBasedFrameDecoder(int maxFrameLength,
boolean stripDelimiter,
ByteBuf delimiter)
maxFrameLength - 解码帧的最大长度。
如果帧的长度超过此值,则会引发TooLongFrameException 。
stripDelimiter - 解码帧是否应该删除分隔符
delimiter - 分隔符
public DelimiterBasedFrameDecoder(int maxFrameLength,
boolean stripDelimiter,
boolean failFast,
ByteBuf delimiter)
maxFrameLength - 解码帧的最大长度。
如果帧的长度超过此值,则会引发TooLongFrameException 。
stripDelimiter - 解码后的帧是否应该删除分隔符
failFast -如果true,一个TooLongFrameException被只要解码器注意到该帧的长度将超过maxFrameLength不管整个帧是否已被读出抛出。
如果false,一个TooLongFrameException超过maxFrameLength整个框架已经被读取之后被抛出。
delimiter - 分隔符
public DelimiterBasedFrameDecoder(int maxFrameLength,
ByteBuf... delimiters)
maxFrameLength - 解码帧的最大长度。
如果帧的长度超过此值,则会引发TooLongFrameException 。
delimiters - 分隔符
public DelimiterBasedFrameDecoder(int maxFrameLength,
boolean stripDelimiter,
ByteBuf... delimiters)
maxFrameLength - 解码帧的最大长度。
如果帧的长度超过此值,则会引发TooLongFrameException 。
stripDelimiter - 解码后的帧是否应该删除分隔符
delimiters - 分隔符
public DelimiterBasedFrameDecoder(int maxFrameLength,
boolean stripDelimiter,
boolean failFast,
ByteBuf... delimiters)
maxFrameLength - 解码帧的最大长度。
如果帧的长度超过此值,则会引发TooLongFrameException 。
stripDelimiter - 解码的帧是否应该删除分隔符
failFast -如果true,一个TooLongFrameException被只要解码器注意到该帧的长度将超过maxFrameLength不管整个帧是否已被读出抛出。
如果false,一个TooLongFrameException超过maxFrameLength整个框架已经被读取之后被抛出。
delimiters - 分隔符
protected final void decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
ByteToMessageDecoder
decode在课堂
ByteToMessageDecoder
ctx - 这ByteToMessageDecoder属于的ChannelHandlerContext
in - 从中读取数据的ByteBuf
out - 应该添加解码消息的
List
java.lang.Exception - 如果发生错误则抛出
protected java.lang.Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws java.lang.Exception
ByteBuf中创建一个框架并将其返回。
ctx - 这ByteToMessageDecoder所属的ChannelHandlerContext
buffer - 从中读取数据的ByteBuf
ByteBuf或null 。
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.