@ChannelHandler.Sharable public class StringEncoder extends OneToOneEncoder
String into a ChannelBuffer.
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", newDelimiterBasedFrameDecoder(Delimiters.lineDelimiter())); pipeline.addLast("stringDecoder", newStringDecoder(CharsetUtil.UTF_8)); // Encoder pipeline.addLast("stringEncoder", newStringEncoder(CharsetUtil.UTF_8));
String instead of a ChannelBuffer
as a message:
void messageReceived(ChannelHandlerContextctx,MessageEvente) { String msg = (String) e.getMessage(); ch.write("Did you say '" + msg + "'?\n"); }
ChannelHandler.Sharable| Constructor and Description |
|---|
StringEncoder()
Creates a new instance with the current system character set.
|
StringEncoder(Charset charset)
Creates a new instance with the specified character set.
|
StringEncoder(String charsetName)
Deprecated.
Use
StringEncoder(Charset) instead. |
| Modifier and Type | Method and Description |
|---|---|
protected Object |
encode(ChannelHandlerContext ctx,
Channel channel,
Object msg)
Transforms the specified message into another message and return the
transformed message.
|
doEncode, handleDownstreampublic StringEncoder()
public StringEncoder(Charset charset)
@Deprecated public StringEncoder(String charsetName)
StringEncoder(Charset) instead.protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
OneToOneEncodernull, unlike
you can in OneToOneDecoder.decode(ChannelHandlerContext, Channel, Object);
you must return something, at least ChannelBuffers.EMPTY_BUFFER.encode in class OneToOneEncoderExceptionCopyright © 2008-2015 The Netty Project. All Rights Reserved.