public class TextLineDecoder extends java.lang.Object implements ProtocolDecoder
ProtocolDecoder which decodes a text line into a string.| Modifier and Type | Class and Description |
|---|---|
private class |
TextLineDecoder.Context
A Context used during the decoding of a lin.
|
| Modifier and Type | Field and Description |
|---|---|
private int |
bufferLength
The default maximum buffer length.
|
private java.nio.charset.Charset |
charset |
private AttributeKey |
CONTEXT |
private IoBuffer |
delimBuf
An IoBuffer containing the delimiter
|
private LineDelimiter |
delimiter
The delimiter used to determinate when a line has been fully decoded
|
private int |
maxLineLength
The default maximum Line length.
|
| Constructor and Description |
|---|
TextLineDecoder()
Creates a new instance with the current default
Charset
and LineDelimiter.AUTO delimiter. |
TextLineDecoder(java.nio.charset.Charset charset)
Creates a new instance with the spcified charset
and
LineDelimiter.AUTO delimiter. |
TextLineDecoder(java.nio.charset.Charset charset,
LineDelimiter delimiter)
Creates a new instance with the specified charset
and the specified delimiter.
|
TextLineDecoder(java.nio.charset.Charset charset,
java.lang.String delimiter)
Creates a new instance with the spcified charset
and the specified delimiter.
|
TextLineDecoder(LineDelimiter delimiter)
Creates a new instance with the current default
Charset
and the specified delimiter. |
TextLineDecoder(java.lang.String delimiter)
Creates a new instance with the current default
Charset
and the specified delimiter. |
| Modifier and Type | Method and Description |
|---|---|
void |
decode(IoSession session,
IoBuffer in,
ProtocolDecoderOutput out)
Decodes binary or protocol-specific content into higher-level message objects.
|
private void |
decodeAuto(TextLineDecoder.Context ctx,
IoSession session,
IoBuffer in,
ProtocolDecoderOutput out)
Decode a line using the default delimiter on the current system
|
private void |
decodeNormal(TextLineDecoder.Context ctx,
IoSession session,
IoBuffer in,
ProtocolDecoderOutput out)
Decode a line using the delimiter defined by the caller
|
void |
dispose(IoSession session)
Releases all resources related with this decoder.
|
void |
finishDecode(IoSession session,
ProtocolDecoderOutput out)
Invoked when the specified session is closed.
|
int |
getBufferLength()
Returns the allowed buffer size used to store the decoded line
in the Context instance.
|
private TextLineDecoder.Context |
getContext(IoSession session)
Return the context for this session
|
int |
getMaxLineLength()
Returns the allowed maximum size of the line to be decoded.
|
void |
setBufferLength(int bufferLength)
Sets the default buffer size.
|
void |
setMaxLineLength(int maxLineLength)
Sets the allowed maximum size of the line to be decoded.
|
protected void |
writeText(IoSession session,
java.lang.String text,
ProtocolDecoderOutput out)
By default, this method propagates the decoded line of text to
ProtocolDecoderOutput#write(Object). |
private final AttributeKey CONTEXT
private final java.nio.charset.Charset charset
private final LineDelimiter delimiter
private IoBuffer delimBuf
private int maxLineLength
private int bufferLength
public TextLineDecoder()
Charset
and LineDelimiter.AUTO delimiter.public TextLineDecoder(java.lang.String delimiter)
Charset
and the specified delimiter.public TextLineDecoder(LineDelimiter delimiter)
Charset
and the specified delimiter.public TextLineDecoder(java.nio.charset.Charset charset)
LineDelimiter.AUTO delimiter.public TextLineDecoder(java.nio.charset.Charset charset,
java.lang.String delimiter)
public TextLineDecoder(java.nio.charset.Charset charset,
LineDelimiter delimiter)
public int getMaxLineLength()
BufferDataException. The default
value is 1024 (1KB).public void setMaxLineLength(int maxLineLength)
BufferDataException. The default
value is 1024 (1KB).public void setBufferLength(int bufferLength)
bufferLength - The default bufer sizepublic int getBufferLength()
public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws java.lang.Exception
ProtocolDecoder.decode(IoSession, IoBuffer, ProtocolDecoderOutput)
method with read data, and then the decoder implementation puts decoded
messages into ProtocolDecoderOutput.decode in interface ProtocolDecoderjava.lang.Exception - if the read data violated protocol specificationprivate TextLineDecoder.Context getContext(IoSession session)
public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws java.lang.Exception
ProtocolDecoder.decode(IoSession, IoBuffer, ProtocolDecoderOutput)
method didn't process completely.finishDecode in interface ProtocolDecoderjava.lang.Exception - if the read data violated protocol specificationpublic void dispose(IoSession session) throws java.lang.Exception
dispose in interface ProtocolDecoderjava.lang.Exception - if failed to dispose all resourcesprivate void decodeAuto(TextLineDecoder.Context ctx, IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws java.nio.charset.CharacterCodingException, ProtocolDecoderException
java.nio.charset.CharacterCodingExceptionProtocolDecoderExceptionprivate void decodeNormal(TextLineDecoder.Context ctx, IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws java.nio.charset.CharacterCodingException, ProtocolDecoderException
java.nio.charset.CharacterCodingExceptionProtocolDecoderExceptionprotected void writeText(IoSession session, java.lang.String text, ProtocolDecoderOutput out)
ProtocolDecoderOutput#write(Object). You may override this method to modify
the default behavior.session - the IoSession the received data.text - the decoded textout - the upstream ProtocolDecoderOutput.