Mercurial Hosting > luan
annotate src/org/eclipse/jetty/io/Buffer.java @ 1029:4e5e9e3c25b3
remove Buffer.equalsIgnoreCase()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Nov 2016 00:55:20 -0600 |
parents | 6d17a257b03f |
children | 80cad9086593 |
rev | line source |
---|---|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 // ------------------------------------------------------------------------ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 // All rights reserved. This program and the accompanying materials |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 // are made available under the terms of the Eclipse Public License v1.0 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 // and Apache License v2.0 which accompanies this distribution. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 // The Eclipse Public License is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 // http://www.eclipse.org/legal/epl-v10.html |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 // The Apache License v2.0 is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 // http://www.opensource.org/licenses/apache2.0.php |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 // You may elect to redistribute this code under either of these licenses. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 package org.eclipse.jetty.io; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 import java.io.IOException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import java.io.InputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.io.OutputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.nio.charset.Charset; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 * Byte Buffer interface. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 * This is a byte buffer that is designed to work like a FIFO for bytes. Puts and Gets operate on different |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 * pointers into the buffer and the valid _content of the buffer is always between the getIndex and the putIndex. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 * This buffer interface is designed to be similar, but not dependent on the java.nio buffers, which may |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 * be used to back an implementation of this Buffer. The main difference is that NIO buffer after a put have |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 * their valid _content before the position and a flip is required to access that data. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 * For this buffer it is always true that: |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 * markValue <= getIndex <= putIndex <= capacity |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 * @version 1.0 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 public interface Buffer extends Cloneable |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 { |
1010 | 45 public final static int |
46 IMMUTABLE=0, // neither indexes or contexts can be changed | |
47 READONLY=1, // indexes may be changed, but not content | |
48 READWRITE=2; // anything can be changed | |
49 public final boolean VOLATILE=true; // The buffer may change outside of current scope. | |
50 public final boolean NON_VOLATILE=false; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 |
1010 | 52 /** |
53 * Get the underlying array, if one exists. | |
54 * @return a <code>byte[]</code> backing this buffer or null if none exists. | |
55 */ | |
56 byte[] array(); | |
57 | |
58 /** | |
59 * | |
60 * @return a <code>byte[]</code> value of the bytes from the getIndex to the putIndex. | |
61 */ | |
62 byte[] asArray(); | |
63 | |
64 /** | |
65 * Get the underlying buffer. If this buffer wraps a backing buffer. | |
66 * @return The root backing buffer or this if there is no backing buffer; | |
67 */ | |
68 Buffer buffer(); | |
69 | |
70 /** | |
71 * | |
72 * @return a readonly version of this <code>Buffer</code>. | |
73 */ | |
74 Buffer asReadOnlyBuffer(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
75 |
1010 | 76 /** |
77 * | |
78 * The capacity of the buffer. This is the maximum putIndex that may be set. | |
79 * @return an <code>int</code> value | |
80 */ | |
81 int capacity(); | |
82 | |
83 /** | |
84 * the space remaining in the buffer. | |
85 * @return capacity - putIndex | |
86 */ | |
87 int space(); | |
88 | |
89 /** | |
90 * Clear the buffer. getIndex=0, putIndex=0. | |
91 */ | |
92 void clear(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
93 |
1010 | 94 /** |
95 * Compact the buffer by discarding bytes before the postion (or mark if set). | |
96 * Bytes from the getIndex (or mark) to the putIndex are moved to the beginning of | |
97 * the buffer and the values adjusted accordingly. | |
98 */ | |
99 void compact(); | |
100 | |
101 /** | |
102 * Get the byte at the current getIndex and increment it. | |
103 * @return The <code>byte</code> value from the current getIndex. | |
104 */ | |
105 byte get(); | |
106 | |
107 /** | |
108 * Get bytes from the current postion and put them into the passed byte array. | |
109 * The getIndex is incremented by the number of bytes copied into the array. | |
110 * @param b The byte array to fill. | |
111 * @param offset Offset in the array. | |
112 * @param length The max number of bytes to read. | |
113 * @return The number of bytes actually read. | |
114 */ | |
115 int get(byte[] b, int offset, int length); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
116 |
1010 | 117 /** |
118 * | |
119 * @param length an <code>int</code> value | |
120 * @return a <code>Buffer</code> value | |
121 */ | |
122 Buffer get(int length); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
123 |
1010 | 124 /** |
125 * The index within the buffer that will next be read or written. | |
126 * @return an <code>int</code> value >=0 <= putIndex() | |
127 */ | |
128 int getIndex(); | |
129 | |
130 /** | |
131 * @return true of putIndex > getIndex | |
132 */ | |
133 boolean hasContent(); | |
134 | |
135 /** | |
136 * | |
137 * @return a <code>boolean</code> value true if the buffer is immutable and that neither | |
138 * the buffer contents nor the indexes may be changed. | |
139 */ | |
140 boolean isImmutable(); | |
141 | |
142 /** | |
143 * | |
144 * @return a <code>boolean</code> value true if the buffer is readonly. The buffer indexes may | |
145 * be modified, but the buffer contents may not. For example a View onto an immutable Buffer will be | |
146 * read only. | |
147 */ | |
148 boolean isReadOnly(); | |
149 | |
150 /** | |
151 * | |
152 * @return a <code>boolean</code> value true if the buffer contents may change | |
153 * via alternate paths than this buffer. If the contents of this buffer are to be used outside of the | |
154 * current context, then a copy must be made. | |
155 */ | |
156 boolean isVolatile(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
157 |
1010 | 158 /** |
159 * The number of bytes from the getIndex to the putIndex | |
160 * @return an <code>int</code> == putIndex()-getIndex() | |
161 */ | |
162 int length(); | |
163 | |
164 /** | |
165 * Set the mark to the current getIndex. | |
166 */ | |
167 void mark(); | |
168 | |
169 /** | |
170 * Set the mark relative to the current getIndex | |
171 * @param offset an <code>int</code> value to add to the current getIndex to obtain the mark value. | |
172 */ | |
173 void mark(int offset); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
174 |
1010 | 175 /** |
176 * The current index of the mark. | |
177 * @return an <code>int</code> index in the buffer or -1 if the mark is not set. | |
178 */ | |
179 int markIndex(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
180 |
1010 | 181 /** |
182 * Get the byte at the current getIndex without incrementing the getIndex. | |
183 * @return The <code>byte</code> value from the current getIndex. | |
184 */ | |
185 byte peek(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
186 |
1010 | 187 /** |
188 * Get the byte at a specific index in the buffer. | |
189 * @param index an <code>int</code> value | |
190 * @return a <code>byte</code> value | |
191 */ | |
192 byte peek(int index); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
193 |
1010 | 194 /** |
195 * | |
196 * @param index an <code>int</code> value | |
197 * @param length an <code>int</code> value | |
198 * @return The <code>Buffer</code> value from the requested getIndex. | |
199 */ | |
200 Buffer peek(int index, int length); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
201 |
1010 | 202 /** |
203 * | |
204 * @param index an <code>int</code> value | |
205 * @param b The byte array to peek into | |
206 * @param offset The offset into the array to start peeking | |
207 * @param length an <code>int</code> value | |
208 * @return The number of bytes actually peeked | |
209 */ | |
210 int peek(int index, byte[] b, int offset, int length); | |
211 | |
212 /** | |
213 * Put the contents of the buffer at the specific index. | |
214 * @param index an <code>int</code> value | |
215 * @param src a <code>Buffer</code>. If the source buffer is not modified | |
216 | |
217 * @return The number of bytes actually poked | |
218 */ | |
219 int poke(int index, Buffer src); | |
220 | |
221 /** | |
222 * Put a specific byte to a specific getIndex. | |
223 * @param index an <code>int</code> value | |
224 * @param b a <code>byte</code> value | |
225 */ | |
226 void poke(int index, byte b); | |
227 | |
228 /** | |
229 * Put a specific byte to a specific getIndex. | |
230 * @param index an <code>int</code> value | |
231 * @param b a <code>byte array</code> value | |
232 * @return The number of bytes actually poked | |
233 */ | |
234 int poke(int index, byte b[], int offset, int length); | |
235 | |
236 /** | |
237 * Write the bytes from the source buffer to the current getIndex. | |
238 * @param src The source <code>Buffer</code> it is not modified. | |
239 * @return The number of bytes actually poked | |
240 */ | |
241 int put(Buffer src); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
242 |
1010 | 243 /** |
244 * Put a byte to the current getIndex and increment the getIndex. | |
245 * @param b a <code>byte</code> value | |
246 */ | |
247 void put(byte b); | |
248 | |
249 /** | |
250 * Put a byte to the current getIndex and increment the getIndex. | |
251 * @param b a <code>byte</code> value | |
252 * @return The number of bytes actually poked | |
253 */ | |
254 int put(byte[] b,int offset, int length); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
255 |
1010 | 256 /** |
257 * Put a byte to the current getIndex and increment the getIndex. | |
258 * @param b a <code>byte</code> value | |
259 * @return The number of bytes actually poked | |
260 */ | |
261 int put(byte[] b); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
262 |
1010 | 263 /** |
264 * The index of the first element that should not be read. | |
265 * @return an <code>int</code> value >= getIndex() | |
266 */ | |
267 int putIndex(); | |
268 | |
269 /** | |
270 * Reset the current getIndex to the mark | |
271 */ | |
272 void reset(); | |
273 | |
274 /** | |
275 * Set the buffers start getIndex. | |
276 * @param newStart an <code>int</code> value | |
277 */ | |
278 void setGetIndex(int newStart); | |
279 | |
280 /** | |
281 * Set a specific value for the mark. | |
282 * @param newMark an <code>int</code> value | |
283 */ | |
284 void setMarkIndex(int newMark); | |
285 | |
286 /** | |
287 * | |
288 * @param newLimit an <code>int</code> value | |
289 */ | |
290 void setPutIndex(int newLimit); | |
291 | |
292 /** | |
293 * Skip _content. The getIndex is updated by min(remaining(), n) | |
294 * @param n The number of bytes to skip | |
295 * @return the number of bytes skipped. | |
296 */ | |
297 int skip(int n); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
298 |
1010 | 299 /** |
300 * | |
301 * @return a volitile <code>Buffer</code> from the postion to the putIndex. | |
302 */ | |
303 Buffer slice(); | |
304 | |
305 /** | |
306 * | |
307 * | |
308 * @return a volitile <code>Buffer</code> value from the mark to the putIndex | |
309 */ | |
310 Buffer sliceFromMark(); | |
311 | |
312 /** | |
313 * | |
314 * | |
315 * @param length an <code>int</code> value | |
316 * @return a valitile <code>Buffer</code> value from the mark of the length requested. | |
317 */ | |
318 Buffer sliceFromMark(int length); | |
319 | |
320 /** | |
321 * | |
322 * @return a <code>String</code> value describing the state and contents of the buffer. | |
323 */ | |
324 String toDetailString(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
325 |
1010 | 326 /* ------------------------------------------------------------ */ |
327 /** Read the buffer's contents from the input stream | |
328 * @param in input stream | |
329 * @param max maximum number of bytes that may be read | |
330 * @return actual number of bytes read or -1 for EOF | |
331 */ | |
332 int readFrom(InputStream in, int max) throws IOException; | |
333 | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
334 |
1010 | 335 String toString(String charset); |
336 | |
337 String toString(Charset charset); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
338 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
339 } |