package co.dc.aptiv.mina;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

public class DataDecoderEx extends CumulativeProtocolDecoder {

    @Override
    protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
        byte[] bytes = new byte[in.remaining()];
        in.get(bytes, 0, in.remaining());
        String str = new String(bytes, "UTF-8");
        if (null != str && str.length() > 0) {
            // 别看这里的处理，这里是我的数据包解密算法~你可以直接拿str当数据
            String strOut = str;
            out.write(strOut);
        }
        // 处理成功，让父类进行接收下个包
        return true;
    }
}