Commit f36d2615520148308b2b62b97a228f2e1c2074ad
1 parent
1fe72425
Exists in
develop
fix: 删除公用coder
Showing
4 changed files
with
1 additions
and
104 deletions
Show diff stats
src/main/java/com/example/mina/client/box/aeroflex/AeroflexClient.java
1 | 1 | package com.example.mina.client.box.aeroflex; |
2 | 2 | |
3 | 3 | import com.example.mina.client.base.AbstractClient; |
4 | -import com.example.mina.client.coder.ByteFactory; | |
5 | 4 | import com.example.mina.client.entity.AbstractClientMessage; |
6 | 5 | import com.example.mina.server.entity.AeroflexDataBuffer; |
7 | 6 | |
... | ... | @@ -13,7 +12,7 @@ public class AeroflexClient extends AbstractClient { |
13 | 12 | |
14 | 13 | @Override |
15 | 14 | protected void init(AbstractClientMessage abstractClientMessage) { |
16 | - protocolCodecFactory = new ByteFactory(); | |
15 | + protocolCodecFactory = new AeroflexByteFactory(); | |
17 | 16 | abstractVirtualBoxClientHandler = new AeroflexClientHandler(abstractClientMessage, hardwareDataBuffer); |
18 | 17 | } |
19 | 18 | ... | ... |
src/main/java/com/example/mina/client/coder/ByteDecoder.java
... | ... | @@ -1,29 +0,0 @@ |
1 | -package com.example.mina.client.coder; | |
2 | - | |
3 | -import org.apache.mina.core.buffer.IoBuffer; | |
4 | -import org.apache.mina.core.session.IoSession; | |
5 | -import org.apache.mina.filter.codec.ProtocolDecoder; | |
6 | -import org.apache.mina.filter.codec.ProtocolDecoderAdapter; | |
7 | -import org.apache.mina.filter.codec.ProtocolDecoderOutput; | |
8 | -import org.slf4j.Logger; | |
9 | -import org.slf4j.LoggerFactory; | |
10 | - | |
11 | -/** | |
12 | - * @author dy | |
13 | - * @date 2021/3/3 | |
14 | - */ | |
15 | -public class ByteDecoder extends ProtocolDecoderAdapter { | |
16 | - //打印日志信息 | |
17 | - private final static Logger log = LoggerFactory | |
18 | - .getLogger(ProtocolDecoder.class); | |
19 | - | |
20 | - @Override | |
21 | - public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { | |
22 | - int limit = in.limit(); | |
23 | - byte[] bytes = new byte[limit]; | |
24 | - | |
25 | - in.get(bytes); | |
26 | - | |
27 | - out.write(bytes); | |
28 | - } | |
29 | -} |
src/main/java/com/example/mina/client/coder/ByteEnCoder.java
... | ... | @@ -1,39 +0,0 @@ |
1 | -package com.example.mina.client.coder; | |
2 | - | |
3 | -import org.apache.mina.core.buffer.IoBuffer; | |
4 | -import org.apache.mina.core.session.IoSession; | |
5 | -import org.apache.mina.filter.codec.ProtocolEncoder; | |
6 | -import org.apache.mina.filter.codec.ProtocolEncoderAdapter; | |
7 | -import org.apache.mina.filter.codec.ProtocolEncoderOutput; | |
8 | -import org.slf4j.Logger; | |
9 | -import org.slf4j.LoggerFactory; | |
10 | - | |
11 | -/** | |
12 | - * @author dy | |
13 | - * @date 2021/3/3 | |
14 | - */ | |
15 | -public class ByteEnCoder extends ProtocolEncoderAdapter { | |
16 | - //用于打印日志信息 | |
17 | - private final static Logger log = LoggerFactory | |
18 | - .getLogger(ProtocolEncoder.class); | |
19 | - | |
20 | - //编码 将数据包转成字节数组 | |
21 | - @Override | |
22 | - public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { | |
23 | - byte[] bytes = (byte[]) message; | |
24 | - | |
25 | - IoBuffer buffer = IoBuffer.allocate(bytes.length); | |
26 | - buffer.setAutoExpand(true); | |
27 | - | |
28 | - // 将数据放入缓冲IoBuffer | |
29 | - buffer.put(bytes); | |
30 | - // 写状态切换到读状态 | |
31 | - buffer.flip(); | |
32 | - | |
33 | - out.write(buffer); | |
34 | -// out.flush(); | |
35 | -// | |
36 | -// buffer.free(); | |
37 | - } | |
38 | - | |
39 | -} |
src/main/java/com/example/mina/client/coder/ByteFactory.java
... | ... | @@ -1,34 +0,0 @@ |
1 | -package com.example.mina.client.coder; | |
2 | - | |
3 | -import org.apache.mina.core.session.IoSession; | |
4 | -import org.apache.mina.filter.codec.ProtocolCodecFactory; | |
5 | -import org.apache.mina.filter.codec.ProtocolDecoder; | |
6 | -import org.apache.mina.filter.codec.ProtocolEncoder; | |
7 | - | |
8 | -/** | |
9 | - * @author dy | |
10 | - * @date 2021/3/3 | |
11 | - */ | |
12 | -public class ByteFactory implements ProtocolCodecFactory { | |
13 | - private final ByteDecoder decoder; | |
14 | - private final ByteEnCoder encoder; | |
15 | - | |
16 | - //构造 | |
17 | - public ByteFactory() { | |
18 | - encoder = new ByteEnCoder(); | |
19 | - decoder = new ByteDecoder(); | |
20 | - } | |
21 | - | |
22 | - @Override | |
23 | - public ProtocolDecoder getDecoder(IoSession arg0) throws Exception { | |
24 | - // TODO Auto-generated method stub | |
25 | - return decoder; | |
26 | - } | |
27 | - | |
28 | - @Override | |
29 | - public ProtocolEncoder getEncoder(IoSession arg0) throws Exception { | |
30 | - // TODO Auto-generated method stub | |
31 | - return encoder; | |
32 | - } | |
33 | - | |
34 | -} |