|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.mina.filter.codec.ProtocolDecoderAdapter
org.apache.mina.filter.codec.CumulativeProtocolDecoder
public abstract class CumulativeProtocolDecoder
A ProtocolDecoder
that cumulates the content of received
buffers to a cumulative buffer to help users implement decoders.
If the received ByteBuffer
is only a part of a message.
decoders should cumulate received buffers to make a message complete or
to postpone decoding until more buffers arrive.
Here is an example decoder that decodes a list of integers:
public class IntegerDecoder extends CumulativeProtocolDecoder { public IntegerDecoder() { super(4); } protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws ProtocolViolationException { if (in.remaining() < 4) { return false; // Cumulate remainder to decode later. } out.write(new Integer(in.getInt())); // Decoded one integer; CumulativeProtocolDecoder will call me again, // so I can decode as many integers as possible. return true; } }
Constructor Summary | |
---|---|
protected |
CumulativeProtocolDecoder()
Creates a new instance with the 16 bytes initial capacity of cumulative buffer. |
protected |
CumulativeProtocolDecoder(int initialCapacity)
Creates a new instance with the specified initial capacity of cumulative buffer. |
Method Summary | |
---|---|
void |
decode(IoSession session,
ByteBuffer in,
ProtocolDecoderOutput out)
Cumulates content of in into internal buffer and forwards decoding request to doDecode(IoSession, ByteBuffer, ProtocolDecoderOutput) . |
void |
dispose(IoSession session)
Releases the cumulative buffer used by the specified session. |
protected abstract boolean |
doDecode(IoSession session,
ByteBuffer in,
ProtocolDecoderOutput out)
Implement this method to consume the specified cumulative buffer and decode its content into message(s). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected CumulativeProtocolDecoder()
protected CumulativeProtocolDecoder(int initialCapacity)
Method Detail |
---|
public void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception
doDecode(IoSession, ByteBuffer, ProtocolDecoderOutput)
.
doDecode() is invoked repeatedly until it returns false
and the cumulative buffer is compacted after decoding ends.
IllegalStateException
- if your doDecode() returned
true not consuming the cumulative buffer.
Exception
- if the read data violated protocol specificationprotected abstract boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception
in
- the cumulative buffer
Exception
- if cannot decode in.public void dispose(IoSession session) throws Exception
dispose
in interface ProtocolDecoder
dispose
in class ProtocolDecoderAdapter
Exception
- if failed to dispose all resources
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |