Top Description Fields Constructors Methods
io.netty5.handler.codec.string

public Class StringDecoder

extends MessageToMessageDecoder<Buffer>
Class Inheritance
Imports
io.netty5.buffer.Buffer, io.netty5.channel.ChannelHandlerContext, .ChannelPipeline, io.netty5.handler.codec.DelimiterBasedFrameDecoder, .LineBasedFrameDecoder, .MessageToMessageDecoder, java.nio.charset.Charset

Decodes a received Buffer into a String. Please note that this decoder must be used with a proper ByteToMessageDecoder such as DelimiterBasedFrameDecoder or LineBasedFrameDecoder if you are using a stream-based transport such as TCP/IP. 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 Buffer as a message:
void channelRead(ChannelHandlerContext ctx, String msg) {
    ch.write("Did you say '" + msg + "'?\n");
}

Field Summary

Modifier and TypeField and Description
private final Charset

Constructor Summary

AccessConstructor and Description
public
StringDecoder()

Creates a new instance with the current system character set.

public
StringDecoder(Charset charset)

Creates a new instance with the specified character set.

Method Summary

Modifier and TypeMethod and Description
protected void
decode(ChannelHandlerContext ctx, Buffer
the message to decode to another one
msg
)

Overrides io.netty5.handler.codec.MessageToMessageDecoder.decode.

Decode from one message to another.
public boolean
isSharable()

Overrides default io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline.
Inherited from io.netty5.handler.codec.MessageToMessageDecoder:
acceptInboundMessagechannelReaddecodeAndClose

Field Detail

charsetback to summary
private final Charset charset

Constructor Detail

StringDecoderback to summary
public StringDecoder()

Creates a new instance with the current system character set.

StringDecoderback to summary
public StringDecoder(Charset charset)

Creates a new instance with the specified character set.

Method Detail

decodeback to summary
protected void decode(ChannelHandlerContext ctx, Buffer msg) throws Exception

Overrides io.netty5.handler.codec.MessageToMessageDecoder.decode.

Doc from io.netty5.handler.codec.MessageToMessageDecoder.decode.

Decode from one message to another. This method will be called for each written message that can be handled by this decoder.

The message will be disposed of after this call.

Subclasses that wish to sometimes pass messages through, should instead override the decodeAndClose(ChannelHandlerContext, Object) method.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageDecoder belongs to

msg:Buffer

the message to decode to another one

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
isSharableback to summary
public boolean isSharable()

Overrides default io.netty5.channel.ChannelHandler.isSharable.

Doc from io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline. By default, this method returns false. If this method returns false, you have to create a new handler instance every time you add it to a pipeline because it has unshared state such as member variables.

Annotations
@Override