hxb
2022-03-21 0188dee359636723190f0f67a6b674b7b08f7bef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.hdl.sdk.socket.codec;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
 
/**
 * Created by Tong on 2021/9/23.
 */
public class MessagePipeLine implements IMessagePipeLine, IHandleMessage {
 
    public final List<IHandleFlow> queue = new ArrayList<>();
 
    @Override
    public void add(IHandleFlow flow) {
        queue.add(flow);
    }
 
    @Override
    public synchronized void clear() {
        queue.clear();
    }
 
    @Override
    public void read(byte[] data,String ipaddress) throws Exception {
        Object out = data;
        for (int i = 0; i < queue.size(); i++) {
            IHandleFlow flow = queue.get(i);
            Object read = flow.read(out,ipaddress);
            try {
                out = Objects.requireNonNull(read);
            } catch (Exception ignored) {
            }
        }
    }
 
    @Override
    public byte[] write(byte[] data) throws Exception {
        byte[] out = data;
        for (int i = 0; i < queue.size(); i++) {
            IHandleFlow flow = queue.get(i);
            byte[] write = flow.write(out);
            try {
                out = Objects.requireNonNull(write);
            } catch (Exception ignored) {
 
            }
        }
        return new byte[0];
    }
}