Class StringEncoder

java.lang.Object
org.jboss.netty.handler.codec.oneone.OneToOneEncoder
org.jboss.netty.handler.codec.string.StringEncoder
All Implemented Interfaces:
ChannelDownstreamHandler, ChannelHandler

@Sharable public class StringEncoder extends OneToOneEncoder
Encodes the requested String into a ChannelBuffer. A typical setup for a text-based line protocol in a TCP/IP socket would be:
ChannelPipeline pipeline = ...;

// Decoders
pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(Delimiters.lineDelimiter()));
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 ChannelBuffer as a message:
void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
    String msg = (String) e.getMessage();
    ch.write("Did you say '" + msg + "'?\n");
}