org.apache.mina.filter.codec.demux

Interface MessageDecoder

Known Implementing Classes:
MessageDecoderAdapter

public interface MessageDecoder

Decodes specific messages.
See Also:
DemuxingProtocolCodecFactory, MessageDecoderFactory

Field Summary

static MessageDecoderResult
NEED_DATA
Represents a result from decodable(IoSession,ByteBuffer) and decode(IoSession,ByteBuffer,ProtocolDecoderOutput).
static MessageDecoderResult
NOT_OK
Represents a result from decodable(IoSession,ByteBuffer) and decode(IoSession,ByteBuffer,ProtocolDecoderOutput).
static MessageDecoderResult
OK
Represents a result from decodable(IoSession,ByteBuffer) and decode(IoSession,ByteBuffer,ProtocolDecoderOutput).

Method Summary

MessageDecoderResult
decodable(IoSession session, ByteBuffer in)
Checks the specified buffer is decodable by this decoder.
MessageDecoderResult
decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out)
Decodes binary or protocol-specific content into higher-level message objects.
void
finishDecode(IoSession session, ProtocolDecoderOutput out)
Invoked when the specified session is closed while this decoder was parsing the data.

Field Details

NEED_DATA

public static final MessageDecoderResult NEED_DATA
Represents a result from decodable(IoSession,ByteBuffer) and decode(IoSession,ByteBuffer,ProtocolDecoderOutput). Please refer to each method's documentation for detailed explanation.

NOT_OK

public static final MessageDecoderResult NOT_OK
Represents a result from decodable(IoSession,ByteBuffer) and decode(IoSession,ByteBuffer,ProtocolDecoderOutput). Please refer to each method's documentation for detailed explanation.

OK

public static final MessageDecoderResult OK
Represents a result from decodable(IoSession,ByteBuffer) and decode(IoSession,ByteBuffer,ProtocolDecoderOutput). Please refer to each method's documentation for detailed explanation.

Method Details

decodable

public MessageDecoderResult decodable(IoSession session,
                                      ByteBuffer in)
Checks the specified buffer is decodable by this decoder.
Returns:
OK if this decoder can decode the specified buffer. NOT_OK if this decoder cannot decode the specified buffer. NEED_DATA if more data is required to determine if the specified buffer is decodable (OK) or not decodable NOT_OK.

decode

public MessageDecoderResult decode(IoSession session,
                                   ByteBuffer in,
                                   ProtocolDecoderOutput out)
            throws Exception
Decodes binary or protocol-specific content into higher-level message objects. MINA invokes decode(IoSession,ByteBuffer,ProtocolDecoderOutput) method with read data, and then the decoder implementation puts decoded messages into ProtocolDecoderOutput.
Returns:
OK if you finished decoding messages successfully. NEED_DATA if you need more data to finish decoding current message. NOT_OK if you cannot decode current message due to protocol specification violation.

finishDecode

public void finishDecode(IoSession session,
                         ProtocolDecoderOutput out)
            throws Exception
Invoked when the specified session is closed while this decoder was parsing the data. 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 that decode(IoSession,ByteBuffer,ProtocolDecoderOutput) method didn't process completely.