min2.0截报文长度

前些时候将mina1.0升级到mina2.0版本,在windows下测试没问题,可是迁移到AIX下发现报文截长度不对,只能截1024长度,使得所有超过1024的报文都出错.没办法只能查看MINA2.0源码,发现截报文的时候默认取I/O的长度,而且只取一次.如果要取超过超过默认的长度时,有二种方法:1,先告诉它你的报文长度,然后分断,将每次取的内容连接起来.
具体操作:
package com.erayt.utils.mina.codec;


import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;

import java.nio.charset.Charset;

public class FixedStringCodecFactory implements ProtocolCodecFactory {

private final FixedStringEncoder encoder;

private final FixedStringDecoder decoder;

public FixedStringCodecFactory(Charset charset) {
encoder = new FixedStringEncoder(charset);
decoder = new FixedStringDecoder(charset);
}

public FixedStringCodecFactory() {
this(Charset.defaultCharset());
}


public int getEncoderMaxDataLength() {
return encoder.getMaxDataLength();
}


public void setEncoderMaxDataLength(int maxDataLength) {
encoder.setMaxDataLength(maxDataLength);
}


public int getDecoderMaxDataLength() {
return decoder.getMaxDataLength();
}


public void setDecoderMaxDataLength(int maxDataLength) {
decoder.setMaxDataLength(maxDataLength);
}


public void setDecoderPrefixLength(int prefixLength) {
decoder.setPrefixLength(prefixLength);
}


public int getDecoderPrefixLength() {
return decoder.getPrefixLength();
}


public void setEncoderPrefixLength(int prefixLength) {
encoder.setPrefixLength(prefixLength);
}


public int getEncoderPrefixLength() {
return encoder.getPrefixLength();
}

public ProtocolEncoder getEncoder(IoSession session) throws Exception {
return encoder;
}

public ProtocolDecoder getDecoder(IoSession session) throws Exception {
return decoder;
}
}


新增一个编码器:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值