@ChannelHandler.Sharable
public class MonitoredStringDecoder
extends io.netty.handler.codec.MessageToMessageDecoder<io.netty.buffer.ByteBuf>
ByteBuf into a String. Please
note that this decoder must be used with a proper ByteToMessageDecoder
such as DelimiterBasedFrameDecoder or LineBasedFrameDecoder
if you are using a stream-based transport such as TCP/IP. A typical setup for a
text-based line protocol in a TCP/IP socket would be:
and then you can use aChannelPipelinepipeline = ...; // Decoders pipeline.addLast("frameDecoder", newLineBasedFrameDecoder(80)); pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8)); // Encoder pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));
String instead of a ByteBuf
as a message:
void channelRead(ChannelHandlerContextctx,Stringmsg) { ch.write("Did you say '" + msg + "'?\n"); }
| Constructor and Description |
|---|
MonitoredStringDecoder(Charset charset)
Creates a new instance with the specified character set.
|
MonitoredStringDecoder(com.codahale.metrics.Counter counter)
Creates a new instance with the current system character set.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf msg,
List<Object> out) |
acceptInboundMessage, channelReadchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerAdded, handlerRemoved, isSharablepublic MonitoredStringDecoder(com.codahale.metrics.Counter counter)
counter - public MonitoredStringDecoder(Charset charset)
charset - the charset to useCopyright © 2023. All rights reserved.