查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2013 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package io.netty.buffer;
18  
19  public interface ByteBufProcessor {
20  
21      /**
22       * Aborts on a {@code NUL (0x00)}.
23       */
24      ByteBufProcessor FIND_NUL = new ByteBufProcessor() {
25          @Override
26          public boolean process(byte value) throws Exception {
27              return value != 0;
28          }
29      };
30  
31      /**
32       * Aborts on a non-{@code NUL (0x00)}.
33       */
34      ByteBufProcessor FIND_NON_NUL = new ByteBufProcessor() {
35          @Override
36          public boolean process(byte value) throws Exception {
37              return value == 0;
38          }
39      };
40  
41      /**
42       * Aborts on a {@code CR ('\r')}.
43       */
44      ByteBufProcessor FIND_CR = new ByteBufProcessor() {
45          @Override
46          public boolean process(byte value) throws Exception {
47              return value != '\r';
48          }
49      };
50  
51      /**
52       * Aborts on a non-{@code CR ('\r')}.
53       */
54      ByteBufProcessor FIND_NON_CR = new ByteBufProcessor() {
55          @Override
56          public boolean process(byte value) throws Exception {
57              return value == '\r';
58          }
59      };
60  
61      /**
62       * Aborts on a {@code LF ('\n')}.
63       */
64      ByteBufProcessor FIND_LF = new ByteBufProcessor() {
65          @Override
66          public boolean process(byte value) throws Exception {
67              return value != '\n';
68          }
69      };
70  
71      /**
72       * Aborts on a non-{@code LF ('\n')}.
73       */
74      ByteBufProcessor FIND_NON_LF = new ByteBufProcessor() {
75          @Override
76          public boolean process(byte value) throws Exception {
77              return value == '\n';
78          }
79      };
80  
81      /**
82       * Aborts on a {@code CR ('\r')} or a {@code LF ('\n')}.
83       */
84      ByteBufProcessor FIND_CRLF = new ByteBufProcessor() {
85          @Override
86          public boolean process(byte value) throws Exception {
87              return value != '\r' && value != '\n';
88          }
89      };
90  
91      /**
92       * Aborts on a byte which is neither a {@code CR ('\r')} nor a {@code LF ('\n')}.
93       */
94      ByteBufProcessor FIND_NON_CRLF = new ByteBufProcessor() {
95          @Override
96          public boolean process(byte value) throws Exception {
97              return value == '\r' || value == '\n';
98          }
99      };
100 
101     /**
102      * Aborts on a linear whitespace (a ({@code ' '} or a {@code '\t'}).
103      */
104     ByteBufProcessor FIND_LINEAR_WHITESPACE = new ByteBufProcessor() {
105         @Override
106         public boolean process(byte value) throws Exception {
107             return value != ' ' && value != '\t';
108         }
109     };
110 
111     /**
112      * Aborts on a byte which is not a linear whitespace (neither {@code ' '} nor {@code '\t'}).
113      */
114     ByteBufProcessor FIND_NON_LINEAR_WHITESPACE = new ByteBufProcessor() {
115         @Override
116         public boolean process(byte value) throws Exception {
117             return value == ' ' || value == '\t';
118         }
119     };
120 
121     /**
122      * @return {@code true} if the processor wants to continue the loop and handle the next byte in the buffer.
123      *         {@code false} if the processor wants to stop handling bytes and abort the loop.
124      */
125     boolean process(byte value) throws Exception;
126 }