Class TextLineDecoder
- java.lang.Object
-
- org.apache.mina.filter.codec.textline.TextLineDecoder
-
- All Implemented Interfaces:
ProtocolDecoder
public class TextLineDecoder extends Object implements ProtocolDecoder
AProtocolDecoder
which decodes a text line into a string.- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Constructor Description TextLineDecoder()
Creates a new instance with the current defaultCharset
andLineDelimiter.AUTO
delimiter.TextLineDecoder(String delimiter)
Creates a new instance with the current defaultCharset
and the specified delimiter.TextLineDecoder(Charset charset)
Creates a new instance with the spcified charset andLineDelimiter.AUTO
delimiter.TextLineDecoder(Charset charset, String delimiter)
Creates a new instance with the spcified charset and the specified delimiter.TextLineDecoder(Charset charset, LineDelimiter delimiter)
Creates a new instance with the specified charset and the specified delimiter.TextLineDecoder(LineDelimiter delimiter)
Creates a new instance with the current defaultCharset
and the specified delimiter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out)
Decodes binary or protocol-specific content into higher-level message objects.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()
int
getMaxLineLength()
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, String text, ProtocolDecoderOutput out)
By default, this method propagates the decoded line of text toProtocolDecoderOutput#write(Object)
.
-
-
-
Constructor Detail
-
TextLineDecoder
public TextLineDecoder()
Creates a new instance with the current defaultCharset
andLineDelimiter.AUTO
delimiter.
-
TextLineDecoder
public TextLineDecoder(String delimiter)
Creates a new instance with the current defaultCharset
and the specified delimiter.- Parameters:
delimiter
- The line delimiter to use
-
TextLineDecoder
public TextLineDecoder(LineDelimiter delimiter)
Creates a new instance with the current defaultCharset
and the specified delimiter.- Parameters:
delimiter
- The line delimiter to use
-
TextLineDecoder
public TextLineDecoder(Charset charset)
Creates a new instance with the spcified charset andLineDelimiter.AUTO
delimiter.- Parameters:
charset
- TheCharset
to use
-
TextLineDecoder
public TextLineDecoder(Charset charset, String delimiter)
Creates a new instance with the spcified charset and the specified delimiter.- Parameters:
charset
- TheCharset
to usedelimiter
- The line delimiter to use
-
TextLineDecoder
public TextLineDecoder(Charset charset, LineDelimiter delimiter)
Creates a new instance with the specified charset and the specified delimiter.- Parameters:
charset
- TheCharset
to usedelimiter
- The line delimiter to use
-
-
Method Detail
-
getMaxLineLength
public int getMaxLineLength()
- Returns:
- the allowed maximum size of the line to be decoded.
If the size of the line to be decoded exceeds this value, the
decoder will throw a
BufferDataException
. The default value is 1024 (1KB).
-
setMaxLineLength
public void setMaxLineLength(int maxLineLength)
Sets the allowed maximum size of the line to be decoded. If the size of the line to be decoded exceeds this value, the decoder will throw aBufferDataException
. The default value is 1024 (1KB).- Parameters:
maxLineLength
- The maximum line length
-
setBufferLength
public void setBufferLength(int bufferLength)
Sets the default buffer size. This buffer is used in the Context to store the decoded line.- Parameters:
bufferLength
- The default bufer size
-
getBufferLength
public int getBufferLength()
- Returns:
- the allowed buffer size used to store the decoded line in the Context instance.
-
decode
public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception
Decodes binary or protocol-specific content into higher-level message objects. MINA invokesProtocolDecoder.decode(IoSession, IoBuffer, ProtocolDecoderOutput)
method with read data, and then the decoder implementation puts decoded messages intoProtocolDecoderOutput
.- Specified by:
decode
in interfaceProtocolDecoder
- Parameters:
session
- The current Sessionin
- the buffer to decodeout
- TheProtocolDecoderOutput
that will receive the decoded message- Throws:
Exception
- if the read data violated protocol specification
-
finishDecode
public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception
Invoked when the specified session is closed. This method is useful when you deal with the protocol which doesn't specify the length of a message such as HTTP response without content-length header. Implement this method to process the remaining data thatProtocolDecoder.decode(IoSession, IoBuffer, ProtocolDecoderOutput)
method didn't process completely.- Specified by:
finishDecode
in interfaceProtocolDecoder
- Parameters:
session
- The current Sessionout
- TheProtocolDecoderOutput
that contains the decoded message- Throws:
Exception
- if the read data violated protocol specification
-
dispose
public void dispose(IoSession session) throws Exception
Releases all resources related with this decoder.- Specified by:
dispose
in interfaceProtocolDecoder
- Parameters:
session
- The current Session- Throws:
Exception
- if failed to dispose all resources
-
writeText
protected void writeText(IoSession session, String text, ProtocolDecoderOutput out)
By default, this method propagates the decoded line of text toProtocolDecoderOutput#write(Object)
. You may override this method to modify the default behavior.- Parameters:
session
- theIoSession
the received data.text
- the decoded textout
- the upstreamProtocolDecoderOutput
.
-
-