@ChannelPipelineCoverage(value="all") 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 aChannelPipeline
pipeline = ...; // Decoders pipeline.addLast("frameDecoder", newDelimiterBasedFrameDecoder
(Delimiters.lineDelimiter()
)); pipeline.addLast("stringDecoder", newStringDecoder
("UTF-8")); // Encoder pipeline.addLast("stringEncoder", newStringEncoder
("UTF-8"));
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"); }
Constructor and Description |
---|
StringEncoder()
Creates a new instance with the current system character set.
|
StringEncoder(Charset charset) |
StringEncoder(String charsetName) |
Modifier and Type | Method and Description |
---|---|
protected Object |
encode(ChannelHandlerContext ctx,
Channel channel,
Object msg) |
handleDownstream
public StringEncoder()
public StringEncoder(String charsetName)
public StringEncoder(Charset charset)
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
encode
in class OneToOneEncoder
Exception
Copyright © 2008-2013 JBoss, by Red Hat. All Rights Reserved.