Class StringEncoder
java.lang.Object
org.jboss.netty.handler.codec.oneone.OneToOneEncoder
org.jboss.netty.handler.codec.string.StringEncoder
- All Implemented Interfaces:
ChannelDownstreamHandler
,ChannelHandler
Encodes the requested
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
(CharsetUtil.UTF_8)); // Encoder pipeline.addLast("stringEncoder", newStringEncoder
(CharsetUtil.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"); }
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with the current system character set.StringEncoder
(Charset charset) Creates a new instance with the specified character set. -
Method Summary
Modifier and TypeMethodDescriptionprotected Object
encode
(ChannelHandlerContext ctx, Channel channel, Object msg) Transforms the specified message into another message and return the transformed message.Methods inherited from class org.jboss.netty.handler.codec.oneone.OneToOneEncoder
doEncode, handleDownstream
-
Field Details
-
charset
-
-
Constructor Details
-
StringEncoder
public StringEncoder()Creates a new instance with the current system character set. -
StringEncoder
Creates a new instance with the specified character set.
-
-
Method Details
-
encode
Description copied from class:OneToOneEncoder
Transforms the specified message into another message and return the transformed message. Note that you can not returnnull
, unlike you can inOneToOneDecoder.decode(ChannelHandlerContext, Channel, Object)
; you must return something, at leastChannelBuffers.EMPTY_BUFFER
.- Specified by:
encode
in classOneToOneEncoder
- Throws:
Exception
-