Class StringEncoder

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
All Implemented Interfaces:
ChannelHandler, ChannelOutboundHandler

@Sharable public class StringEncoder extends MessageToMessageEncoder<CharSequence>
Encodes the requested String into a ByteBuf. A typical setup for a text-based line protocol in a TCP/IP socket would be:
ChannelPipeline pipeline = ...;
// Decoders
pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(80));
pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));
// Encoder
pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));
and then you can use a String instead of a ByteBuf as a message:
void channelRead(ChannelHandlerContext ctx, String msg) {
 ch.write("Did you say '" + msg + "'?\n");
}