1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package io.netty.util;
16
17 import static io.netty.util.ByteProcessorUtils.CARRIAGE_RETURN;
18 import static io.netty.util.ByteProcessorUtils.HTAB;
19 import static io.netty.util.ByteProcessorUtils.LINE_FEED;
20 import static io.netty.util.ByteProcessorUtils.SPACE;
21
22
23
24
25 public interface ByteProcessor {
26
27
28
29 class IndexOfProcessor implements ByteProcessor {
30 private final byte byteToFind;
31
32 public IndexOfProcessor(byte byteToFind) {
33 this.byteToFind = byteToFind;
34 }
35
36 @Override
37 public boolean process(byte value) {
38 return value != byteToFind;
39 }
40 }
41
42
43
44
45 class IndexNotOfProcessor implements ByteProcessor {
46 private final byte byteToNotFind;
47
48 public IndexNotOfProcessor(byte byteToNotFind) {
49 this.byteToNotFind = byteToNotFind;
50 }
51
52 @Override
53 public boolean process(byte value) {
54 return value == byteToNotFind;
55 }
56 }
57
58
59
60
61 ByteProcessor FIND_NUL = new IndexOfProcessor((byte) 0);
62
63
64
65
66 ByteProcessor FIND_NON_NUL = new IndexNotOfProcessor((byte) 0);
67
68
69
70
71 ByteProcessor FIND_CR = new IndexOfProcessor(CARRIAGE_RETURN);
72
73
74
75
76 ByteProcessor FIND_NON_CR = new IndexNotOfProcessor(CARRIAGE_RETURN);
77
78
79
80
81 ByteProcessor FIND_LF = new IndexOfProcessor(LINE_FEED);
82
83
84
85
86 ByteProcessor FIND_NON_LF = new IndexNotOfProcessor(LINE_FEED);
87
88
89
90
91 ByteProcessor FIND_SEMI_COLON = new IndexOfProcessor((byte) ';');
92
93
94
95
96 ByteProcessor FIND_COMMA = new IndexOfProcessor((byte) ',');
97
98
99
100
101 ByteProcessor FIND_ASCII_SPACE = new IndexOfProcessor(SPACE);
102
103
104
105
106 ByteProcessor FIND_CRLF = new ByteProcessor() {
107 @Override
108 public boolean process(byte value) {
109 return value != CARRIAGE_RETURN && value != LINE_FEED;
110 }
111 };
112
113
114
115
116 ByteProcessor FIND_NON_CRLF = new ByteProcessor() {
117 @Override
118 public boolean process(byte value) {
119 return value == CARRIAGE_RETURN || value == LINE_FEED;
120 }
121 };
122
123
124
125
126 ByteProcessor FIND_LINEAR_WHITESPACE = new ByteProcessor() {
127 @Override
128 public boolean process(byte value) {
129 return value != SPACE && value != HTAB;
130 }
131 };
132
133
134
135
136 ByteProcessor FIND_NON_LINEAR_WHITESPACE = new ByteProcessor() {
137 @Override
138 public boolean process(byte value) {
139 return value == SPACE || value == HTAB;
140 }
141 };
142
143
144
145
146
147 boolean process(byte value) throws Exception;
148 }